Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project : QYVORA7// File : App/Sources/Onboarding/OnboardingChainsStep.swift8// Module : Onboarding9// Repository : https://git.spboucher.ai/qyvora10// Project Website : Not specified11// Created : 2026-12-0512// 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/// What one recovery phrase covers, for the first screens of the creation and import flows.47enum OnboardingChains {48 static var names: String { ChainRegistry.mainChains.map(\.displayName).joined(separator: ", ") }4950 static let onePhrase = "The same phrase gives your accounts on every network QYVORA supports. Bitcoin and Ethereum are shown first; the others are enabled in one tap, now or later, without a new phrase."51}5253/// First-run choice of the networks the wallet shows. Bitcoin and Ethereum are on by default; nothing is created or54/// moved by enabling a network, and the choice can be changed at any time from the wallet.55struct OnboardingChainsStep: View {56 let step: Int57 let stepCount: Int58 let onDone: () -> Void5960 @Environment(WalletStore.self) private var wallet61 @State private var selected: Set<ChainID> = Set(ChainRegistry.defaultEnabled)62 @State private var loaded = false63 @State private var saving = false64 @State private var error: String?6566 var body: some View {67 OnboardingScaffold(title: "Choose your networks", step: step, stepCount: stepCount, onClose: nil) {68 Text("Your recovery phrase already covers all of them. Choose what the wallet shows and synchronizes; you can change this later from the wallet.")69 .font(QFont.callout).foregroundStyle(QColor.textSecondary).fixedSize(horizontal: false, vertical: true)70 if wallet.snapshot?.isTestMode != false {71 WarningBanner(.info, title: "Test networks", message: "The wallet starts on the test network of each chain: coins there have no monetary value.")72 }73 ForEach(ChainRegistry.groups) { group in74 QListSection(group.title, footnote: group.accountNote) {75 ForEach(group.chains) { main in76 ChainPickerRow(network: shown(main).qNetwork, note: "\(main.nativeName) · \(main.nativeSymbol)",77 lockedReason: selected == [main.id] ? "At least one network stays enabled." : nil,78 isOn: Binding(get: { selected.contains(main.id) }, set: { on in79 if on { selected.insert(main.id) } else if selected.count > 1 { selected.remove(main.id) }80 }))81 }82 }83 }84 InlineError(message: error)85 } footer: {86 LoadingButton("Continue with \(selected.count) network\(selected.count == 1 ? "" : "s")", loadingTitle: "Saving", state: saving ? .loading : .idle) { save() }87 .disabled(saving || selected.isEmpty)88 }89 .qHaptic(.toggled, trigger: selected)90 .task {91 guard !loaded, let enabled = wallet.snapshot?.profile.enabledChains else { return }92 loaded = true93 selected = Set(enabled)94 }95 }9697 /// The network a chain would use now: its default test network unless main networks are on.98 func shown(_ main: ChainDescriptor) -> ChainDescriptor {99 if let snapshot = wallet.snapshot, snapshot.networkMode == .main, snapshot.mainnetEnabled { return main }100 return ChainRegistry.defaultTestNetwork(of: main.id).flatMap(ChainRegistry.descriptor) ?? main101 }102103 func save() {104 guard !saving else { return }105 saving = true106 error = nil107 let chains = ChainRegistry.mainChains.map(\.id).filter { selected.contains($0) }108 Task {109 defer { saving = false }110 do {111 try await wallet.run { try await $0.setEnabledChains(chains) }112 await wallet.refresh()113 onDone()114 } catch {115 self.error = WalletStore.message(for: error)116 }117 }118 }119}120