SPB Git

Repository Public

RootView.swift 6.1 KB 157 lines swift

1// SP Wallet iOS2// File: App/RootView.swift3// Description: Top-level switch (launch, sign-in, device lock, main interface) and the two navigation shells: a five-tab bar on4//              iPhone, a sidebar with a wide detail area on iPad. A privacy cover hides the content in the app switcher.5//6// Author: Simon-Pierre Boucher7// Contact: contact@spboucher.ai8import SwiftUI9import SPWalletCore1011struct RootView: View {12    @Environment(AppModel.self) private var model13    @Environment(\.scenePhase) private var scenePhase1415    var body: some View {16        ZStack {17            switch model.phase {18            case .launching: LaunchView()19            case .signedOut: LoginView()20            case .locked: LockedView()21            case .ready: MainShell()22            }23            // the app switcher snapshot must not show balances or addresses24            if scenePhase != .active, model.phase == .ready || model.phase == .locked { PrivacyCover() }25        }26        .animation(.easeOut(duration: 0.2), value: model.phase)27    }28}2930struct LaunchView: View {31    var body: some View {32        ZStack { Theme.bg.ignoresSafeArea(); VStack(spacing: 16) { BrandMark(size: 72); ProgressView() } }33    }34}3536struct PrivacyCover: View {37    var body: some View { ZStack { Theme.bg.ignoresSafeArea(); BrandMark(size: 72) }.accessibilityHidden(true) }38}3940struct BrandMark: View {41    var size: CGFloat = 6442    var body: some View {43        Image("LaunchMark").resizable().scaledToFit().frame(width: size, height: size).accessibilityLabel("SP Wallet")44    }45}4647struct LockedView: View {48    @Environment(AppModel.self) private var model49    var body: some View {50        ZStack {51            Theme.bg.ignoresSafeArea()52            VStack(spacing: 22) {53                BrandMark(size: 76)54                Text(String(localized: "SP Wallet est verrouillé")).font(.spTitle).foregroundStyle(Theme.ink)55                Text(String(localized: "Le verrou protège l’affichage sur cet appareil. Chaque opération demande en plus ta clé d’accès."))56                    .font(.spCallout).foregroundStyle(Theme.mute).multilineTextAlignment(.center).padding(.horizontal, 36)57                Button { Task { await model.unlock() } } label: { Label(String(localized: "Déverrouiller"), systemImage: "faceid") }58                    .buttonStyle(.spPrimary).padding(.horizontal, 48).accessibilityIdentifier("lock.unlock")59            }60        }61    }62}6364struct MainShell: View {65    @Environment(AppModel.self) private var model66    @Environment(Router.self) private var router67    @Environment(\.horizontalSizeClass) private var sizeClass6869    var body: some View {70        @Bindable var router = router71        Group {72            if sizeClass == .regular { SidebarShell() } else { TabShell() }73        }74        .sheet(item: $router.sheet) { sheet in75            switch sheet {76            case .send(let n, let a): SendFlow(initialNetwork: n, initialAsset: a).wallet(model)77            case .receive(let n): ReceiveView(initialNetwork: n).wallet(model)78            }79        }80    }81}8283private struct TabShell: View {84    @Environment(AppModel.self) private var model85    @Environment(Router.self) private var router86    var body: some View {87        @Bindable var router = router88        TabView(selection: Binding(get: { AppSection.tabs.contains(router.section) ? router.section : .explore }, set: { router.section = $0 })) {89            ForEach(AppSection.tabs) { s in90                Tab(s.title, systemImage: s.icon, value: s) {91                    NavigationStack {92                        // on iPhone the specialised sections are pushed inside Explore93                        if s == .explore, !AppSection.tabs.contains(router.section) { SectionContent(section: router.section).wallet(model) }94                        else { SectionContent(section: s).wallet(model) }95                    }96                }97                .accessibilityIdentifier("tab.\(s.rawValue)")98            }99        }100    }101}102103private struct SidebarShell: View {104    @Environment(Router.self) private var router105    @Environment(AppModel.self) private var model106    var body: some View {107        @Bindable var router = router108        NavigationSplitView {109            List(selection: Binding<AppSection?>(get: { router.section }, set: { if let s = $0 { router.section = s } })) {110                ForEach(AppSection.sidebarGroups, id: \.0) { group in111                    Section(group.0) {112                        ForEach(group.1) { s in113                            Label(s.title, systemImage: s.icon).tag(s)114                                .accessibilityElement(children: .combine).accessibilityIdentifier("sidebar.\(s.rawValue)")115                        }116                    }117                }118            }119            .navigationTitle("SP Wallet")120            .safeAreaInset(edge: .bottom) {121                VStack(spacing: 8) {122                    Button { router.sheet = .send(network: nil, asset: nil) } label: { Label(String(localized: "Envoyer"), systemImage: "arrow.up.right") }123                        .buttonStyle(.spPrimary).disabled(!model.canOperate)124                    Button { router.sheet = .receive(network: nil) } label: { Label(String(localized: "Recevoir"), systemImage: "arrow.down.left") }.buttonStyle(.spSecondary)125                }.padding(14)126            }127        } detail: {128            NavigationStack { SectionContent(section: router.section).wallet(model) }.id(router.section)129        }130        .navigationSplitViewStyle(.balanced)131    }132}133134/** The screen of each section. */135struct SectionContent: View {136    let section: AppSection137    var body: some View {138        switch section {139        case .home: HomeView()140        case .portfolio: PortfolioView()141        case .activity: ActivityView()142        case .explore: ExploreView()143        case .swap: SwapHomeView()144        case .bridge: BridgeHomeView()145        case .nfts: NFTGalleryView()146        case .markets: MarketsHomeView()147        case .futures: FuturesHomeView()148        case .agents: AgentsHomeView()149        case .research: ResearchHomeView()150        case .alerts: AlertsHomeView()151        case .risk: RiskHomeView()152        case .security: SecurityView()153        case .settings: SettingsView()154        }155    }156}157
Files main
Menu

Theme