SPB Git

Repository Public

OnboardingIntroView.swift 16.7 KB 349 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project          : QYVORA7// File             : App/Sources/OnboardingIntroView.swift8// Module           : Sources9// 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 QyvoraCrypto44import QyvoraUI4546/// Introduction shown before a wallet exists: what QYVORA is, what its post-quantum cryptography does and does47/// not cover, the test-network restriction, then the three ways to start. The three closures are the only48/// outputs; the wallet developer connects them to the creation, import and watch-only flows.49struct OnboardingIntroView: View {50    let onCreate: () -> Void51    let onImport: () -> Void52    let onWatchOnly: () -> Void53    let onRestore: () -> Void5455    @State private var page: Int56    @Environment(\.accessibilityReduceMotion) private var reduceMotion57    private let pageCount = 45859    init(initialPage: Int = 0, onCreate: @escaping () -> Void, onImport: @escaping () -> Void, onWatchOnly: @escaping () -> Void,60         onRestore: @escaping () -> Void) {61        _page = State(initialValue: min(3, max(0, initialPage)))62        self.onCreate = onCreate63        self.onImport = onImport64        self.onWatchOnly = onWatchOnly65        self.onRestore = onRestore66    }6768    var body: some View {69        VStack(spacing: 0) {70            topBar71            TabView(selection: $page) {72                sovereigntyPage.tag(0)73                layersPage.tag(1)74                testNetworkPage.tag(2)75                choicePage.tag(3)76            }77            .tabViewStyle(.page(indexDisplayMode: .never))78            bottomBar79        }80        .qScreen()81        .sensoryFeedback(.selection, trigger: page)82    }8384    // MARK: Chrome8586    var topBar: some View {87        HStack {88            HStack(spacing: 10) {89                QMark().frame(width: 28, height: 28)90                Text("QYVORA").font(.footnote.weight(.semibold)).kerning(3).foregroundStyle(QColor.textPrimary)91            }92            .accessibilityElement(children: .ignore)93            .accessibilityLabel("QYVORA")94            Spacer()95            if page < pageCount - 1 {96                Button("Skip") { go(to: pageCount - 1) }97                    .font(.callout.weight(.medium))98                    .foregroundStyle(QColor.textSecondary)99                    .frame(minWidth: 44, minHeight: 44)100                    .accessibilityHint("Goes to the wallet set-up choices")101            }102        }103        .frame(minHeight: 44)104        .padding(.horizontal, 24)105        .padding(.top, 4)106    }107108    var bottomBar: some View {109        VStack(spacing: 18) {110            HStack(spacing: 6) {111                ForEach(0..<pageCount, id: \.self) { i in112                    Capsule()113                        .fill(i == page ? QColor.textPrimary : QColor.stroke)114                        .frame(width: i == page ? 22 : 6, height: 6)115                }116            }117            .animation(reduceMotion ? nil : .snappy(duration: 0.25), value: page)118            .accessibilityElement(children: .ignore)119            .accessibilityLabel("Page \(page + 1) of \(pageCount)")120            // Kept in the layout on the last page so that the page indicator does not move.121            Button("Continue") { go(to: page + 1) }122                .buttonStyle(.qPrimary)123                .opacity(page < pageCount - 1 ? 1 : 0)124                .disabled(page >= pageCount - 1)125                .accessibilityHidden(page >= pageCount - 1)126        }127        .padding(.horizontal, 24)128        .padding(.top, 12)129        .padding(.bottom, 16)130    }131132    func go(to target: Int) {133        if reduceMotion { page = target } else { withAnimation(.smooth(duration: 0.35)) { page = target } }134    }135136    func pageScroll<Content: View>(@ViewBuilder _ content: () -> Content) -> some View {137        ScrollView {138            VStack(alignment: .leading, spacing: 24) { content() }139                .padding(.horizontal, 24)140                .padding(.top, 28)141                .padding(.bottom, 12)142                .frame(maxWidth: 560, alignment: .leading)143                .frame(maxWidth: .infinity)144        }145        .scrollBounceBehavior(.basedOnSize)146    }147148    func heading(eyebrow: String, title: String, lead: String) -> some View {149        VStack(alignment: .leading, spacing: 12) {150            QEyebrow(eyebrow)151            Text(title)152                .font(.system(.largeTitle, design: .default, weight: .bold))153                .foregroundStyle(QColor.textPrimary)154                .accessibilityAddTraits(.isHeader)155            Text(lead)156                .font(QFont.body)157                .foregroundStyle(QColor.textSecondary)158        }159        .fixedSize(horizontal: false, vertical: true)160    }161162    // MARK: Pages163164    var sovereigntyPage: some View {165        pageScroll {166            heading(eyebrow: "Self-custody",167                    title: "Your keys stay on this iPhone.",168                    lead: "QYVORA is a wallet that you hold yourself, for Bitcoin, Litecoin, Dogecoin, Bitcoin Cash, Ethereum and six other EVM networks, Solana and TRON. Nobody else can move your funds, and nobody else can restore them for you.")169            VStack(spacing: 0) {170                fact("key", "Created and kept on the device",171                     "Keys are generated here and sealed in a local vault. The recovery phrase is the only backup: write it down.")172                Divider().overlay(QColor.stroke)173                fact("person.slash", "No account",174                     "No sign-up, no e-mail address, no QYVORA server holding anything about you.")175                Divider().overlay(QColor.stroke)176                fact("network", "Endpoints you can replace",177                     "Balances and broadcasts go through public network endpoints. You can review them and point the app to your own node in Settings.")178            }179            .background(QColor.surface, in: RoundedRectangle(cornerRadius: QMetric.radius, style: .continuous))180            .overlay(RoundedRectangle(cornerRadius: QMetric.radius, style: .continuous).strokeBorder(QColor.stroke, lineWidth: 1))181        }182    }183184    func fact(_ systemImage: String, _ title: String, _ text: String) -> some View {185        HStack(alignment: .top, spacing: 14) {186            QIconTile(systemImage, tint: QColor.violet)187            VStack(alignment: .leading, spacing: 4) {188                Text(title).font(QFont.headline).foregroundStyle(QColor.textPrimary)189                Text(text).font(QFont.callout).foregroundStyle(QColor.textSecondary)190            }191            .fixedSize(horizontal: false, vertical: true)192            Spacer(minLength: 0)193        }194        .padding(16)195        .accessibilityElement(children: .combine)196    }197198    var layersPage: some View {199        pageScroll {200            heading(eyebrow: "Post-quantum, precisely",201                    title: "Three layers, three different answers.",202                    lead: "\u{201C}Post-quantum wallet\u{201D} can mean three things. QYVORA states each one separately, because a claim about one layer does not carry over to another.")203            VStack(spacing: 12) {204                layer("A", "Vault, backups, transfers, identity",205                      "Designed to resist a quantum attacker: 256-bit symmetric encryption, with ML-KEM, ML-DSA and SLH-DSA where a public-key step is needed. It still depends on your password and on an engine that is not audited.",206                      badge: "Post-quantum design", image: "checkmark.shield", tone: .positive)207                layer("B", "Public keys exposed on chain",208                      "Depends on the chain and on how funds are used. QYVORA measures the exposure on every chain and helps reduce it where the chain allows: fresh addresses on Bitcoin and the coins like it, revoked approvals on EVM networks. On Solana the address is the key itself. It cannot remove it.",209                      badge: "Measured, reducible", image: "gauge.with.dots.needle.33percent", tone: .warning)210                layer("C", "The blockchains themselves",211                      "Not quantum-resistant. Transactions are signed with secp256k1, or Ed25519 on Solana, because the networks require it. No wallet can change that.",212                      badge: "Not quantum-resistant", image: "xmark.shield", tone: .negative)213            }214        }215    }216217    func layer(_ letter: String, _ title: String, _ text: String, badge: String, image: String, tone: QBadge.Tone) -> some View {218        QCard {219            VStack(alignment: .leading, spacing: 10) {220                HStack(alignment: .firstTextBaseline, spacing: 12) {221                    Text(letter)222                        .font(Font.system(.title2, design: .monospaced).weight(.semibold))223                        .foregroundStyle(QColor.textTertiary)224                        .accessibilityLabel("Layer \(letter)")225                    Text(title).font(QFont.headline).foregroundStyle(QColor.textPrimary)226                }227                Text(text).font(QFont.callout).foregroundStyle(QColor.textSecondary)228                QBadge(badge, systemImage: image, tone: tone)229            }230            .fixedSize(horizontal: false, vertical: true)231        }232        .accessibilityElement(children: .combine)233    }234235    var testNetworkPage: some View {236        pageScroll {237            if MainnetPolicy.auditCompleted {238                heading(eyebrow: "Networks",239                        title: "Main and test networks are available.",240                        lead: "This release records a completed independent audit of the cryptographic engine. Test networks remain available for trying things without risk.")241            } else if MainnetPolicy.mainnetAvailable {242                heading(eyebrow: "Before you start",243                        title: "Test networks by default.",244                        lead: "The cryptographic engine of QYVORA is written from scratch and has not been audited by a third party. In this internal build, main networks are off by default; they can be enabled in the settings for internal testing, with per-transaction limits on every chain.")245            } else {246                heading(eyebrow: "Before you start",247                        title: "Test networks only.",248                        lead: "The cryptographic engine of QYVORA is written from scratch and has not been independently audited. This build does not operate on any main network.")249            }250            QCard {251                VStack(alignment: .leading, spacing: 14) {252                    QEyebrow("Audit status")253                    Text(QyvoraEngine.auditStatus)254                        .font(QFont.callout)255                        .foregroundStyle(QColor.textPrimary)256                        .fixedSize(horizontal: false, vertical: true)257                    Divider().overlay(QColor.stroke)258                    networkLine("Bitcoin Signet and Ethereum Sepolia", enabled: true)259                    // not enabled until the user chooses them (at set-up, or later from the wallet): said as such260                    networkLine("Test networks of Litecoin, Dogecoin, Bitcoin Cash, six other EVM networks, Solana and TRON", enabled: true, onLabel: "Your choice")261                    networkLine("Main networks", enabled: MainnetPolicy.auditCompleted, offLabel: MainnetWording.short)262                }263            }264            if !MainnetPolicy.mainnetEnabled {265                WarningBanner(.info, message: "Test coins have no monetary value. Do not send real coins or tokens to an address shown on a test network. Not every test network can be read to the same extent: Dogecoin Testnet has no public indexer, and some EVM networks have no history source; the wallet says so where it applies.")266            }267        }268    }269270    func networkLine(_ name: String, enabled: Bool, onLabel: String = "Enabled", offLabel: String = "Disabled") -> some View {271        HStack(alignment: .firstTextBaseline, spacing: 10) {272            Image(systemName: enabled ? "checkmark.circle" : "lock")273                .foregroundStyle(enabled ? QColor.positive : QColor.textTertiary)274                .accessibilityHidden(true)275            Text(name).font(QFont.callout).foregroundStyle(enabled ? QColor.textPrimary : QColor.textSecondary)276            Spacer(minLength: 8)277            Text(enabled ? onLabel : offLabel)278                .font(.caption.weight(.semibold))279                .foregroundStyle(enabled ? QColor.positive : QColor.textSecondary)280        }281        .accessibilityElement(children: .combine)282    }283284    var choicePage: some View {285        pageScroll {286            heading(eyebrow: "Set up",287                    title: "How do you want to start?",288                    lead: "Choose how this device gets its wallet.")289            VStack(spacing: 12) {290                Button(action: onCreate) {291                    choiceLabel("plus", "Create a new wallet", "Generates a recovery phrase on this device.", primary: true)292                }293                .buttonStyle(ChoiceButtonStyle(primary: true))294                Button(action: onImport) {295                    choiceLabel("arrow.down.to.line", "Import a recovery phrase", "Restores a wallet from 12 or 24 words.", primary: false)296                }297                .buttonStyle(ChoiceButtonStyle(primary: false))298                Button(action: onRestore) {299                    choiceLabel("iphone.and.arrow.forward", "Restore from a backup or another iPhone",300                                "An encrypted backup file, or a transfer from another iPhone.", primary: false)301                }302                .buttonStyle(ChoiceButtonStyle(primary: false))303                Button(action: onWatchOnly) {304                    choiceLabel("eye", "Watch-only", "Follows a wallet without holding its keys. Nothing can be signed.", primary: false)305                }306                .buttonStyle(ChoiceButtonStyle(primary: false))307            }308        }309    }310311    func choiceLabel(_ systemImage: String, _ title: String, _ subtitle: String, primary: Bool) -> some View {312        HStack(spacing: 14) {313            Image(systemName: systemImage)314                .font(.body.weight(.semibold))315                .frame(width: 28)316                .accessibilityHidden(true)317            VStack(alignment: .leading, spacing: 3) {318                Text(title).font(QFont.headline)319                Text(subtitle).font(QFont.callout).opacity(primary ? 0.85 : 0.65)320            }321            .multilineTextAlignment(.leading)322            .fixedSize(horizontal: false, vertical: true)323            Spacer(minLength: 4)324            Image(systemName: "chevron.right").font(.footnote.weight(.semibold)).opacity(0.6).accessibilityHidden(true)325        }326        .accessibilityElement(children: .combine)327    }328}329330struct ChoiceButtonStyle: ButtonStyle {331    let primary: Bool332333    func makeBody(configuration: Configuration) -> some View {334        let shape = RoundedRectangle(cornerRadius: QMetric.radius, style: .continuous)335        configuration.label336            .foregroundStyle(primary ? QColor.onAccent : QColor.textPrimary)337            .padding(.horizontal, 16)338            .padding(.vertical, 16)339            .frame(maxWidth: .infinity, minHeight: 72, alignment: .leading)340            .background {341                if primary { shape.fill(QColor.accentGradient) } else { shape.fill(QColor.surface) }342            }343            .overlay { if !primary { shape.strokeBorder(QColor.stroke, lineWidth: 1) } }344            .opacity(configuration.isPressed ? 0.82 : 1)345            .scaleEffect(configuration.isPressed ? 0.985 : 1)346            .animation(.snappy(duration: 0.18), value: configuration.isPressed)347    }348}349
Files main
Menu

Theme