SPB Git

Repository Public

OnboardingFlow.swift 7.2 KB 203 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project          : QYVORA7// File             : App/Sources/Onboarding/OnboardingFlow.swift8// Module           : Onboarding9// 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 QyvoraUI4344/// The three ways to start a wallet.45enum OnboardingPath: String, Identifiable, Sendable {46    case create, importPhrase, watchOnly47    /// From an encrypted backup file or from another iPhone (the security area's restore screens).48    case restore49    var id: String { rawValue }50}5152/// Hosts the introduction and presents the creation, import and watch-only flows. `isActive` stays true while53/// a flow is on screen, so that the root view does not leave onboarding the moment the wallet exists: the54/// recovery phrase still has to be written down and verified.55struct OnboardingFlow: View {56    @Binding var isActive: Bool57    @State private var path: OnboardingPath?5859    var body: some View {60        OnboardingIntroView(61            initialPage: initialPage,62            onCreate: { start(.create) },63            onImport: { start(.importPhrase) },64            onWatchOnly: { start(.watchOnly) },65            onRestore: { start(.restore) }66        )67        .fullScreenCover(item: $path, onDismiss: { isActive = false }) { path in68            Group {69                switch path {70                case .create: CreateWalletFlow(onClose: close)71                case .importPhrase: ImportWalletFlow(onClose: close)72                case .restore: ImportWalletFlow(onClose: close, entry: .backupOrTransfer)73                case .watchOnly: WatchOnlyFlow(onClose: close)74                }75            }76            .presentedPrivacyCover()77        }78        .onAppear {79            #if DEBUG80            if let debug = DebugLaunch.onboardingPath, path == nil { start(debug) }81            #endif82        }83    }8485    func start(_ new: OnboardingPath) {86        isActive = true87        path = new88    }8990    func close() {91        path = nil92    }9394    var initialPage: Int {95        #if DEBUG96        return DebugLaunch.page97        #else98        return 099        #endif100    }101}102103/// Common frame of an onboarding step: progress, title, scrolling content and a pinned action area.104struct OnboardingScaffold<Content: View, Footer: View>: View {105    let title: String106    let step: Int107    let stepCount: Int108    /// nil hides the close button (steps that must not be abandoned).109    let onClose: (() -> Void)?110    @ViewBuilder let content: Content111    @ViewBuilder let footer: Footer112113    var body: some View {114        VStack(spacing: 0) {115            HStack(spacing: 12) {116                HStack(spacing: 5) {117                    ForEach(0..<stepCount, id: \.self) { i in118                        Capsule().fill(i <= step ? QColor.violet : QColor.stroke).frame(height: 4)119                    }120                }121                .accessibilityElement(children: .ignore)122                .accessibilityLabel("Step \(step + 1) of \(stepCount)")123                if let onClose {124                    Button(action: onClose) {125                        Image(systemName: "xmark").font(.body.weight(.semibold)).foregroundStyle(QColor.textSecondary)126                            .frame(width: 44, height: 44)127                    }128                    .accessibilityLabel("Cancel")129                } else {130                    Color.clear.frame(width: 44, height: 44)131                }132            }133            .padding(.leading, 24)134            .padding(.trailing, 12)135            ScrollView {136                VStack(alignment: .leading, spacing: 20) {137                    Text(title)138                        .font(.system(.title, design: .default, weight: .bold))139                        .foregroundStyle(QColor.textPrimary)140                        .fixedSize(horizontal: false, vertical: true)141                        .accessibilityAddTraits(.isHeader)142                    content143                }144                .padding(.horizontal, 24)145                .padding(.top, 8)146                .padding(.bottom, 24)147                .frame(maxWidth: 560, alignment: .leading)148                .frame(maxWidth: .infinity)149            }150            .scrollDismissesKeyboard(.interactively)151            .debugScroll()152            VStack(spacing: 12) { footer }153                .padding(.horizontal, 24)154                .padding(.vertical, 14)155                .frame(maxWidth: 560)156                .frame(maxWidth: .infinity)157                .background(QColor.background)158        }159        .qScreen()160    }161}162163/// One explanatory line with a glyph.164struct OnboardingPoint: View {165    let systemImage: String166    let title: String167    let text: String168169    var body: some View {170        HStack(alignment: .top, spacing: 14) {171            QIconTile(systemImage, tint: QColor.violet)172            VStack(alignment: .leading, spacing: 4) {173                Text(title).font(QFont.headline).foregroundStyle(QColor.textPrimary)174                Text(text).font(QFont.callout).foregroundStyle(QColor.textSecondary).fixedSize(horizontal: false, vertical: true)175            }176        }177        .accessibilityElement(children: .combine)178    }179}180181/// Last step of every flow.182struct OnboardingDoneStep: View {183    let title: String184    let lines: [String]185    let step: Int186    let stepCount: Int187    let onFinish: () -> Void188189    var body: some View {190        OnboardingScaffold(title: title, step: step, stepCount: stepCount, onClose: nil) {191            Image(systemName: "checkmark.seal")192                .font(.system(size: 52, weight: .light))193                .foregroundStyle(QColor.positive)194                .accessibilityHidden(true)195            ForEach(lines, id: \.self) { line in196                Text(line).font(QFont.body).foregroundStyle(QColor.textPrimary).fixedSize(horizontal: false, vertical: true)197            }198        } footer: {199            Button("Open the wallet", action: onFinish).buttonStyle(.qPrimary)200        }201    }202}203
Files main
Menu

Theme