SPB Git

Repository Public

TransactionDetailView.swift 10.8 KB 210 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project          : QYVORA7// File             : App/Sources/Activity/TransactionDetailView.swift8// Module           : Activity9// Repository       : https://git.spboucher.ai/qyvora10// Project Website  : Not specified11// Created          : 2026-12-0412// Last Modified    : 2026-12-0513//14// Author           : Simon-Pierre Boucher15// Position         : Professor of Finance16// Institution      : Université du Québec en Outaouais (UQO)17// Organization     : SP Boucher18// Website          : https://spboucher.ai19// Git              : https://git.spboucher.ai20//21// Preferred Contact: contact@spboucher.ai22// Development      : dev@spboucher.ai23// Support          : support@spboucher.ai24// Security/Admin   : admin@spboucher.ai25//26// Copyright (c) 202627// Simon-Pierre Boucher28// All rights reserved where applicable. This file is governed by the29// applicable project license, copyright notices and relevant law.30// Existing third-party rights and notices remain unaffected.31//32// License          : None specified (no license file in this repository)33//34// Do not embed credentials, private keys, access tokens,35// certificates or confidential personal information.36//37// =============================================================================38// END OF SP BOUCHER SOURCE HEADER39// =============================================================================4041import SwiftUI42import QyvoraCore43import QyvoraWallet44import QyvoraUI4546/// One line of history in full: status in the chain's own terms, amounts, fee, addresses, identifier, block and a47/// link to a public explorer. Everything comes from the entry the service read; what the source did not report is48/// named as not reported.49struct TransactionDetailView: View {50    let chain: ChainID51    /// `ActivityEntry.id` (a transaction with several token movements has several entries).52    let id: String5354    @Environment(WalletStore.self) private var wallet55    @Environment(\.walletHooks) private var hooks56    @HideAmounts private var hideAmounts5758    var snapshotChain: ChainSnapshot? { wallet.snapshot?.activeChain(chain) }59    var item: ActivityItem? {60        guard let snapshotChain else { return nil }61        return ActivityItem.of(snapshotChain).first { $0.entry.id == id }62    }6364    var body: some View {65        ScrollView {66            VStack(alignment: .leading, spacing: QSpace.xl) {67                if let item, let snapshot = wallet.snapshot {68                    header(item)69                    if snapshotChain?.data.value?.notes.contains(where: { $0.hasPrefix(WalletService.singleIndexerNotePrefix) }) == true {70                        WarningBanner(.warning, title: "Reported by one source",71                                      message: "This entry, its amount and its confirmations are the word of one indexer; no second source confirmed them. A source that lies can show a payment that does not exist. Do not hand over goods on this screen alone: add a second indexer in the network settings, or check the transaction on an explorer you trust.")72                    }73                    statusSection(item)74                    amountSection(item, snapshot)75                    addressSection(item)76                    identifierSection(item)77                    if let url = item.entry.explorerURL { WalletExplorerLink(title: "View on a block explorer", url: url) }78                    if item.entry.direction == .sent || item.entry.direction == .selfTransfer, let open = hooks.openShield {79                        QListSection(footnote: "A transaction sent by an account publishes the public key that signed it.") {80                            WalletActionRow(title: "Key exposure in the Shield", subtitle: "What this transaction revealed", systemImage: "shield.lefthalf.filled", external: true) {81                                open(ShieldSection(item.chain))82                            }83                        }84                    }85                } else {86                    UnavailableDataView(reason: "This transaction is not in the history that was last read. Synchronize the network and open it again.",87                                        title: "Transaction not found") { Task { await wallet.synchronize(chains: [chain]) } }88                        .padding(.top, QSpace.xxl)89                }90            }91            .padding(.horizontal, QMetric.screenPadding)92            .padding(.vertical, QSpace.l)93            .frame(maxWidth: 640)94            .frame(maxWidth: .infinity)95        }96        .qScreen()97        .navigationTitle("Transaction")98        .navigationBarTitleDisplayMode(.inline)99        .refreshable { await wallet.synchronize(chains: [chain]) }100    }101102    func header(_ item: ActivityItem) -> some View {103        VStack(alignment: .leading, spacing: QSpace.m) {104            HStack(spacing: QSpace.m) {105                if case .token(_, let symbol, _, _) = item.entry.kind, let symbol {106                    TokenGlyph(symbol: symbol, network: item.network, size: .large)107                } else {108                    ChainGlyph(item.network, size: .large)109                }110                VStack(alignment: .leading, spacing: QSpace.xs) {111                    Text(item.title).font(QFont.title).foregroundStyle(QColor.textPrimary).fixedSize(horizontal: false, vertical: true)112                    NetworkBadge(item.network, style: .plain)113                }114            }115            if item.showsAmount {116                AmountText(units: item.entry.amount, decimals: item.entry.decimals ?? 0, symbol: item.amountIsScaled ? item.symbol : "base units",117                           style: .balance, sign: item.sign, hidden: hideAmounts)118                    .privacySensitive()119            }120            QBadge(item.statusText, systemImage: item.statusImage, tone: item.statusTone)121        }122        .frame(maxWidth: .infinity, alignment: .leading)123        .accessibilityElement(children: .combine)124    }125126    func statusSection(_ item: ActivityItem) -> some View {127        ReviewSection("Status", footnote: item.statusExplanation) {128            ReviewRow("Status", value: item.statusText)129            ReviewRow("Time", value: item.entry.time.map(WalletFormat.timestamp) ?? (item.isPending ? "Not in a block yet" : "Not reported by the source"))130            if let height = item.entry.blockHeight {131                ReviewRow(item.chain.heightNoun, value: height.formatted(.number.grouping(.never)))132            }133        }134    }135136    @ViewBuilder137    func amountSection(_ item: ActivityItem, _ snapshot: WalletSnapshot) -> some View {138        let nativeQuote = snapshot.quote(of: item.chain)139        ReviewSection("Amounts", footnote: amountFootnote(item)) {140            if item.showsAmount {141                ReviewRow("Amount", value: hideAmounts ? "••••" : amountText(item), secondary: hideAmounts ? nil : amountFiat(item, snapshot), emphasis: .strong)142            }143            if let fee = item.entry.fee {144                ReviewRow("Network fee", value: hideAmounts ? "••••" : WalletChainFormat.native(fee, item.chain),145                          secondary: hideAmounts ? nil : WalletChainFormat.fiat(units: fee, decimals: item.chain.nativeDecimals, quote: nativeQuote, isTest: item.chain.isTest))146            } else {147                ReviewRow("Network fee", value: item.entry.direction == .received ? "Paid by the sender" : "Not reported by the source")148            }149        }150        .privacySensitive()151    }152153    func amountText(_ item: ActivityItem) -> String {154        guard let decimals = item.entry.decimals else { return "\(item.entry.amount.description) base units" }155        return WalletChainFormat.amount(item.entry.amount, decimals: decimals, symbol: item.symbol)156    }157158    func amountFiat(_ item: ActivityItem, _ snapshot: WalletSnapshot) -> String? {159        guard case .native = item.entry.kind, let decimals = item.entry.decimals else { return nil }160        return WalletChainFormat.fiat(units: item.entry.amount, decimals: decimals, quote: snapshot.quote(of: item.chain), isTest: item.chain.isTest)161            .map { "\($0) at today's price" }162    }163164    func amountFootnote(_ item: ActivityItem) -> String? {165        switch item.entry.kind {166        case .token(_, _, let decimals, let verified):167            if decimals == nil { return "The decimals of this token are not known: the amount is shown in its base units." }168            return verified ? nil : "Symbol and decimals of this token are the indexer's word; they were not verified on chain."169        case .approval: return "An approval lets a contract spend a token of this account. Open approvals are listed in the Shield."170        case .contract: return "A call to a contract or a program that is not a plain transfer. QYVORA shows what it could attribute to this account."171        case .unknown: return "QYVORA does not decode this transaction. Nothing about it is guessed."172        case .native: return nil173        }174    }175176    @ViewBuilder177    func addressSection(_ item: ActivityItem) -> some View {178        let token: String? = {179            switch item.entry.kind {180            case .token(let address, _, _, _): return address181            case .approval(let token): return token182            default: return nil183            }184        }()185        if item.entry.counterparty != nil || token != nil {186            ReviewSection("Addresses", footnote: item.chain.family == .utxo && item.entry.direction == .received187                          ? "On \(item.chain.nativeName) the payer of a transaction cannot be told reliably, so none is shown." : nil) {188                if let counterparty = item.entry.counterparty {189                    ReviewRow(item.entry.direction == .received ? "From" : (item.entry.direction == .sent ? "To" : "Counterparty"), value: counterparty,190                              emphasis: .address, copyValue: counterparty)191                }192                if let token {193                    ReviewRow(item.chain.family == .solana ? "Token mint" : "Token contract", value: token, emphasis: .address, copyValue: token)194                }195            }196            .privacySensitive()197        } else if item.chain.family == .utxo, item.entry.direction == .received {198            WalletNoteLine(text: "On \(item.chain.nativeName) the payer of a transaction cannot be told reliably, so none is shown.")199        }200    }201202    func identifierSection(_ item: ActivityItem) -> some View {203        ReviewSection("Identifier") {204            ReviewRow(item.chain.family == .solana ? "Signature" : (item.chain.family == .evm ? "Transaction hash" : "Transaction ID"), value: item.entry.hash,205                      emphasis: .mono, copyValue: item.entry.hash)206        }207        .privacySensitive()208    }209}210
Files main
Menu

Theme