Repository Public
1// SP Wallet iOS2// File: App/Router.swift3// Description: Navigation state shared by the iPhone tab bar and the iPad sidebar: the current section, the sheets of the main4// flows, and deep links (spwallet://…) from widgets and App Intents. A link only ever OPENS a screen; no link, QR5// code or shortcut can start or approve a transaction.6//7// Author: Simon-Pierre Boucher8// Contact: contact@spboucher.ai9import SwiftUI10import SPWalletCore1112enum AppSection: String, CaseIterable, Identifiable, Hashable {13 case home, portfolio, activity, explore, swap, bridge, nfts, markets, futures, agents, research, alerts, risk, security, settings14 var id: String { rawValue }1516 var title: String {17 switch self {18 case .home: String(localized: "Accueil")19 case .portfolio: String(localized: "Portefeuille")20 case .activity: String(localized: "Activité")21 case .explore: String(localized: "Explorer")22 case .swap: String(localized: "Échanger")23 case .bridge: String(localized: "Transférer entre réseaux")24 case .nfts: String(localized: "NFT")25 case .markets: String(localized: "Marchés")26 case .futures: String(localized: "Contrats à terme")27 case .agents: String(localized: "Agents de trading")28 case .research: String(localized: "Recherche")29 case .alerts: String(localized: "Alertes")30 case .risk: String(localized: "Risque et limites")31 case .security: String(localized: "Sécurité")32 case .settings: String(localized: "Réglages")33 }34 }35 var icon: String {36 switch self {37 case .home: "house.fill"38 case .portfolio: "chart.pie.fill"39 case .activity: "list.bullet.rectangle.fill"40 case .explore: "square.grid.2x2.fill"41 case .swap: "arrow.left.arrow.right"42 case .bridge: "point.topleft.down.to.point.bottomright.curvepath.fill"43 case .nfts: "photo.stack.fill"44 case .markets: "chart.bar.xaxis"45 case .futures: "chart.line.uptrend.xyaxis"46 case .agents: "cpu.fill"47 case .research: "doc.text.magnifyingglass"48 case .alerts: "bell.fill"49 case .risk: "gauge.with.dots.needle.67percent"50 case .security: "lock.shield.fill"51 case .settings: "gearshape.fill"52 }53 }54 /** The five destinations of the iPhone tab bar. Everything else is reached from Explore or from the relevant screen. */55 static let tabs: [AppSection] = [.home, .portfolio, .activity, .explore, .settings]56 static let sidebarGroups: [(String, [AppSection])] = [57 (String(localized: "Portefeuille"), [.home, .portfolio, .activity]),58 (String(localized: "Opérations"), [.swap, .bridge, .nfts]),59 (String(localized: "Marchés"), [.markets, .futures, .agents, .research]),60 (String(localized: "Surveillance"), [.alerts, .risk, .security]),61 (String(localized: "App"), [.settings]),62 ]63}6465enum FlowSheet: Identifiable, Hashable {66 case send(network: String?, asset: String?)67 case receive(network: String?)68 var id: String { switch self { case .send(let n, let a): "send-\(n ?? "")-\(a ?? "")"; case .receive(let n): "receive-\(n ?? "")" } }69}7071@MainActor @Observable72final class Router {73 var section: AppSection = .home74 var sheet: FlowSheet?75 /** Asset to open in Portfolio (deep link / App Intent). */76 var pendingAsset: String?7778 func go(_ s: AppSection) { section = s }7980 /** spwallet://home | portfolio | activity | alerts | asset/<SYMBOL> — navigation only. */81 func open(_ url: URL) {82 guard url.scheme == "spwallet" else { return }83 let host = url.host ?? ""84 switch host {85 case "asset":86 let sym = url.pathComponents.dropFirst().first ?? ""87 guard sym.range(of: "^[A-Za-z0-9.₮-]{1,16}$", options: .regularExpression) != nil else { return }88 pendingAsset = sym; section = .portfolio89 default:90 if let s = AppSection(rawValue: host) { section = s }91 }92 }93}9495/** Hardware-keyboard commands (iPad): navigation and refresh. No command performs a financial operation. */96struct AppCommands: Commands {97 let router: Router98 let model: AppModel99 var body: some Commands {100 CommandMenu(String(localized: "Aller à")) {101 Button(AppSection.home.title) { router.go(.home) }.keyboardShortcut("1")102 Button(AppSection.portfolio.title) { router.go(.portfolio) }.keyboardShortcut("2")103 Button(AppSection.activity.title) { router.go(.activity) }.keyboardShortcut("3")104 Button(AppSection.swap.title) { router.go(.swap) }.keyboardShortcut("4")105 Button(AppSection.markets.title) { router.go(.markets) }.keyboardShortcut("5")106 Button(AppSection.futures.title) { router.go(.futures) }.keyboardShortcut("6")107 Button(AppSection.agents.title) { router.go(.agents) }.keyboardShortcut("7")108 Button(AppSection.alerts.title) { router.go(.alerts) }.keyboardShortcut("8")109 Button(AppSection.security.title) { router.go(.security) }.keyboardShortcut("9")110 Divider()111 Button(AppSection.settings.title) { router.go(.settings) }.keyboardShortcut(",")112 }113 CommandMenu(String(localized: "Portefeuille")) {114 Button(String(localized: "Actualiser")) { Task { await model.refreshAll() } }.keyboardShortcut("r")115 Button(String(localized: "Envoyer…")) { router.sheet = .send(network: nil, asset: nil) }.keyboardShortcut("e", modifiers: [.command, .shift]).disabled(!model.canOperate)116 Button(String(localized: "Recevoir…")) { router.sheet = .receive(network: nil) }.keyboardShortcut("d", modifiers: [.command, .shift])117 Button(String(localized: "Verrouiller")) { if model.phase == .ready { model.phase = .locked } }.keyboardShortcut("l", modifiers: [.command, .shift])118 }119 }120}121