SPB Git

Repository Public

MainShell.swift 8.6 KB 203 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project          : QYVORA7// File             : App/Sources/MainShell.swift8// Module           : Sources9// 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 QyvoraUI43import QyvoraWallet4445enum MainTab: String, Hashable, CaseIterable, Sendable {46    case wallet, shield, activity, settings47}4849/// Destinations that exist without a wallet and can be pushed from several places.50enum EngineRoute: Hashable, Sendable {51    case cryptography52    case algorithm(String)53    case benchmarks54    case migration55}5657extension View {58    /// Registers the engine screens on the enclosing navigation stack.59    func engineDestinations() -> some View {60        navigationDestination(for: EngineRoute.self) { route in61            switch route {62            case .cryptography: CryptoInfoView()63            case .algorithm(let name): AlgorithmDetailView(name: name)64            case .benchmarks: BenchmarksView()65            case .migration:66                #if DEBUG67                MigrationView(chain: DebugLaunch.migrationChain)68                #else69                MigrationView()70                #endif71            }72        }73    }74}7576extension View {77    /// DEBUG builds: scrolls the enclosed list or scroll view to the `-QYScrollTo` identifier (screenshots).78    /// Release builds: returns the view unchanged.79    @ViewBuilder func debugScroll() -> some View {80        #if DEBUG81        DebugScroll { self }82        #else83        self84        #endif85    }86}8788/// Main shell: four tabs, each with its own navigation stack.89struct MainShell: View {90    @Environment(AppModel.self) private var model91    @Environment(WalletStore.self) private var wallet92    @State private var tab: MainTab93    @State private var walletPath: NavigationPath94    @State private var activityPath = NavigationPath()95    @State private var settingsPath: NavigationPath96    /// A plan handed over by the security screens (sweep of exposed coins, revocation of an approval) on any chain,97    /// as the uniform review the send flow opens on.98    @State private var handedReview: SendReview?99    /// Security screens opened from the dashboard banners (recovery-phrase verification, cold mode).100    @State private var securitySheet: SecuritySheet?101    /// Section of the Shield tab asked for by a wallet or activity screen; the tab scrolls to it and clears it.102    @State private var shieldFocus: ShieldSection?103104    enum SecuritySheet: String, Identifiable {105        case verifyPhrase, coldMode106        var id: String { rawValue }107    }108109    init() {110        #if DEBUG111        _tab = State(initialValue: DebugLaunch.initialTab)112        _walletPath = State(initialValue: DebugLaunch.initialWalletPath)113        _settingsPath = State(initialValue: DebugLaunch.initialSettingsPath)114        // -QYShieldFocus bitcoin|litecoin|dogecoin|bitcoin-cash|ethereum|solana|tron: as if a link of an asset or transaction screen had been followed115        if let section = DebugLaunch.defaults.string(forKey: "QYShieldFocus").flatMap(ShieldSection.init(rawValue:)) {116            _tab = State(initialValue: .shield)117            _shieldFocus = State(initialValue: section)118        }119        #else120        _tab = State(initialValue: .wallet)121        _walletPath = State(initialValue: NavigationPath())122        _settingsPath = State(initialValue: NavigationPath())123        #endif124    }125126    var body: some View {127        @Bindable var model = model128        TabView(selection: $tab) {129            Tab("Wallet", systemImage: "wallet.bifold", value: MainTab.wallet) {130                NavigationStack(path: $walletPath) { DashboardView() }131            }132            Tab("Shield", systemImage: "shield.lefthalf.filled", value: MainTab.shield) {133                NavigationStack { ShieldTab(focus: $shieldFocus) }134            }135            Tab("Activity", systemImage: "list.bullet.rectangle", value: MainTab.activity) {136                NavigationStack(path: $activityPath) { ActivityView() }137            }138            Tab("Settings", systemImage: "gearshape", value: MainTab.settings) {139                NavigationStack(path: $settingsPath) {140                    SettingsView(endpoints: $model.endpoints)141                }142            }143        }144        .sensoryFeedback(.selection, trigger: tab)145        // every plan of a security screen (sweep of exposed coins of any UTXO coin, revocation on any EVM network, a146        // future Shield plan) arrives as the uniform review; the two older handoffs stay as its fallback147        .environment(\.secSendReviewHandoff, SecSendReviewHandoff { review in handedReview = review })148        .environment(\.bitcoinPlanHandoff, BitcoinPlanHandoff { plan in149            Task { @MainActor in handedReview = await wallet.service?.review(for: plan) }150        })151        .environment(\.ethereumReviewHandoff, EthereumReviewHandoff { review in152            Task { @MainActor in handedReview = await wallet.service?.review(for: review) }153        })154        .environment(\.walletHooks, WalletHooks(openRecoveryBackup: { securitySheet = .verifyPhrase }, openColdMode: { securitySheet = .coldMode },155                                                openShield: { section in156                                                    shieldFocus = section157                                                    tab = .shield158                                                },159                                                // the network settings (mode, test networks, chain list, endpoints) are a160                                                // screen of the Settings tab: show it, whatever that tab was showing161                                                openNetworkSettings: {162                                                    var path = NavigationPath()163                                                    path.append(SecurityRoute.networks)164                                                    settingsPath = path165                                                    tab = .settings166                                                }))167        .sheet(item: $securitySheet) { sheet in168            NavigationStack {169                Group {170                    switch sheet {171                    case .verifyPhrase: VerifyPhraseView()172                    case .coldMode: ColdModeView()173                    }174                }175                .toolbar {176                    ToolbarItem(placement: .cancellationAction) { Button("Close") { securitySheet = nil } }177                }178            }179            .presentedPrivacyCover()180        }181        .sheet(item: $handedReview) { review in182            SendFlow(review: review).presentedPrivacyCover()183        }184        #if DEBUG185        .onChange(of: DebugNavigator.shared.serial) { _, _ in186            handedReview = nil187            tab = DebugLaunch.initialTab188            walletPath = DebugLaunch.initialWalletPath189            let action = DebugLaunch.defaults.string(forKey: "QYAction")190            Task {191                switch action {192                case "sync": await wallet.synchronize()193                case "sync-chain":194                    if let id = DebugLaunch.chain, let chain = wallet.snapshot?.activeChain(id) { await wallet.synchronize(chains: [chain.id]) }195                default: break196                }197            }198        }199        .debugOpenFirstTransaction(path: $activityPath)200        #endif201    }202}203
Files main
Menu

Theme