Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project : QYVORA7// File : App/Sources/Wallet/WalletRoutes.swift8// Module : Wallet9// Repository : https://git.spboucher.ai/qyvora10// Project Website : Not specified11// Created : 2026-12-0412// Last Modified : 2026-12-0413//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 QyvoraWallet43import QyvoraUI4445/// Screens pushed on the Wallet and Activity navigation stacks. Everything is addressed by chain identifier.46enum WalletRoute: Hashable, Sendable {47 /// One active chain: balance, tokens, family panel, recent activity.48 case chain(ChainID)49 /// One token of a chain, by contract or mint address.50 case token(chain: ChainID, address: String)51 /// Unspent outputs of a UTXO chain (coin control).52 case coins(ChainID)53 /// Discovered addresses of a UTXO chain, with their labels.54 case addresses(ChainID)55 /// One line of history; `id` is `ActivityEntry.id`.56 case transaction(chain: ChainID, id: String)57 /// The whole history of one chain.58 case activity(ChainID)59}6061/// What a send starts from: nothing (the asset picker opens), a chain or a token (from their screens), or a scanned62/// address or payment request.63struct SendPrefill: Hashable, Sendable {64 var chain: ChainID?65 /// Contract or mint address of the token to send; nil for the coin of the chain.66 var tokenAddress: String?67 var recipient: String?68 /// Decimal amount of the asset, as scanned ("0.01").69 var amount: String?70 var memo: String?7172 init(chain: ChainID? = nil, tokenAddress: String? = nil, recipient: String? = nil, amount: String? = nil, memo: String? = nil) {73 self.chain = chain74 self.tokenAddress = tokenAddress75 self.recipient = recipient76 self.amount = amount77 self.memo = memo78 }79}8081/// Flows presented as sheets from the dashboard, the chain and asset screens.82enum WalletSheet: Identifiable, Hashable {83 case send(SendPrefill)84 /// Receive on a chain; nil opens the chain picker.85 case receive(ChainID?)86 case scan87 /// Enable or disable chains.88 case networks89 /// The "More" menu of the dashboard.90 case more91 /// Broadcast a transaction signed on a cold device.92 case importSigned9394 var id: String {95 switch self {96 case .send(let prefill): return "send-\(prefill.hashValue)"97 case .receive(let chain): return "receive-\(chain?.rawValue ?? "pick")"98 case .scan: return "scan"99 case .networks: return "networks"100 case .more: return "more"101 case .importSigned: return "import-signed"102 }103 }104}105106extension View {107 /// Registers the wallet screens on the enclosing navigation stack. `namespace` carries the row → detail zoom of108 /// the list that pushes them (nil: the standard transition).109 func walletDestinations(namespace: Namespace.ID? = nil) -> some View {110 navigationDestination(for: WalletRoute.self) { route in111 Group {112 switch route {113 case .chain(let id): ChainDetailScreen(chainID: id)114 case .token(let chain, let address): WalletTokenDetailScreen(chainID: chain, address: address)115 case .coins(let id): ChainCoinsScreen(chainID: id)116 case .addresses(let id): ChainAddressesScreen(chainID: id)117 case .transaction(let chain, let id): TransactionDetailView(chain: chain, id: id)118 case .activity(let id): ActivityView(fixedChain: id)119 }120 }121 .qMatchedDestination(id: route, in: namespace)122 }123 }124125 /// Presents the wallet flows. A flow can hand over to another one (scan → send): the sheet is replaced.126 func walletSheet(_ sheet: Binding<WalletSheet?>) -> some View {127 self.sheet(item: sheet) { item in128 WalletSheetContent(item: item) { next in129 sheet.wrappedValue = nil130 guard let next else { return }131 Task { @MainActor in132 // the dismissal of the first sheet must finish before the next one is presented133 try? await Task.sleep(for: .milliseconds(450))134 sheet.wrappedValue = next135 }136 }137 }138 }139}140141/// The content of a wallet sheet, with its detents. `handOver(nil)` closes; `handOver(next)` replaces the sheet.142private struct WalletSheetContent: View {143 let item: WalletSheet144 let handOver: (WalletSheet?) -> Void145146 var body: some View {147 Group {148 switch item {149 case .send(let prefill): SendFlow(prefill: prefill)150 case .receive(let chain): ReceiveFlow(initialChain: chain)151 case .scan: WalletScanFlow(open: handOver)152 case .networks: WalletNetworksSheet().qSheetChrome(detents: QDetents.full)153 case .more: WalletMoreSheet(open: handOver).qSheetChrome(detents: QDetents.half)154 case .importSigned: SendSignedImportFlow()155 }156 }157 .presentedPrivacyCover()158 }159}160