SPB Git

Repository Public

MigrationView.swift 13.7 KB 322 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project          : QYVORA7// File             : App/Sources/MigrationView.swift8// Module           : Sources9// 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 QyvoraMigration43import QyvoraUI4445extension MigrationEngine.Status {46    var title: String {47        switch self {48        case .available: return "Available"49        case .planned: return "Planned"50        case .awaitingProtocol: return "Awaiting protocol"51        }52    }5354    var systemImage: String {55        switch self {56        case .available: return "checkmark.circle"57        case .planned: return "calendar"58        case .awaitingProtocol: return "lock"59        }60    }6162    var tone: QBadge.Tone {63        switch self {64        case .available: return .positive65        case .planned: return .accent66        case .awaitingProtocol: return .neutral67        }68    }6970    var explanation: String {71        switch self {72        case .available: return "Live on the network and implemented in QYVORA."73        case .planned: return "Possible on the network today; not shipped in this version."74        case .awaitingProtocol: return "Depends on a network change that is not deployed. Cannot be enabled."75        }76    }77}7879extension MigrationEngine.Chain {80    /// The registry's `.ethereum` entry stands for every EVM network (one account, one signature scheme).81    var title: String {82        switch self {83        case .bitcoin: return "Bitcoin"84        case .ethereum: return "Ethereum and EVM"85        case .solana: return "Solana"86        case .tron: return "TRON"87        case .litecoin: return "Litecoin"88        case .dogecoin: return "Dogecoin"89        case .bitcoinCash: return "Bitcoin Cash"90        }91    }9293    var scope: String {94        switch self {95        case .ethereum: return "Ethereum, Base, Arbitrum, OP Mainnet, Polygon, BNB Chain and Avalanche: one account, one signature scheme."96        case .bitcoin, .litecoin, .dogecoin, .bitcoinCash: return "Its own account, a new address for every payment."97        case .solana: return "One account whose address is the Ed25519 public key."98        case .tron: return "One account, secp256k1 signatures."99        }100    }101102    var qChain: QChain {103        switch self {104        case .bitcoin: return .bitcoin105        case .ethereum: return .ethereum106        case .solana: return .solana107        case .tron: return .tron108        case .litecoin: return .litecoin109        case .dogecoin: return .dogecoin110        case .bitcoinCash: return .bitcoinCash111        }112    }113114    var glyph: AssetGlyph.Kind { self == .bitcoin ? .bitcoin : .ethereum }115116    /// Every chain of the registry in the wallet's order (Bitcoin family, EVM, Solana, TRON); a chain added to the117    /// registry later is appended.118    static var displayOrder: [MigrationEngine.Chain] {119        let wanted: [MigrationEngine.Chain] = [.bitcoin, .litecoin, .dogecoin, .bitcoinCash, .ethereum, .solana, .tron]120        return wanted.filter { allCases.contains($0) } + allCases.filter { !wanted.contains($0) }121    }122}123124extension MigrationEngine.Family {125    var title: String {126        switch self {127        case .addressType: return "Address type"128        case .script: return "Script"129        case .signature: return "Signature"130        case .hybridSignature: return "Hybrid signature"131        case .account: return "Account"132        case .assetMigration: return "Asset migration"133        case .keyRotation: return "Key rotation"134        }135    }136}137138/// The registry of the Quantum Migration Engine: what each chain offers today, what is planned, and what139/// waits for a protocol change. The screen reads `MigrationEngine` and decides nothing itself.140struct MigrationView: View {141    @State private var chain: MigrationEngine.Chain142    @Environment(\.accessibilityReduceMotion) private var reduceMotion143144    init(chain: MigrationEngine.Chain = .bitcoin) {145        _chain = State(initialValue: chain)146    }147148    var capabilities: [MigrationEngine.Capability] { MigrationEngine.capabilities(for: chain) }149150    var body: some View {151        ScrollView {152            VStack(alignment: .leading, spacing: QSpace.xl) {153                statement154                chainPicker155                chainSummary156                ForEach([MigrationEngine.Status.available, .planned, .awaitingProtocol], id: \.self) { status in157                    let items = capabilities.filter { $0.status == status }158                    if !items.isEmpty {159                        QListSection("\(status.title) · \(items.count)", footnote: status.explanation, separatorInset: QMetric.padding) {160                            ForEach(items) { CapabilityCard(capability: $0) }161                        }162                        .id(status.rawValue)163                    }164                }165                legend166            }167            .padding(.horizontal, QMetric.screenPadding)168            .padding(.top, QSpace.m)169            .padding(.bottom, QSpace.xxl)170            .frame(maxWidth: 640, alignment: .leading)171            .frame(maxWidth: .infinity)172        }173        .debugScroll()174        .qScreen()175        .navigationTitle("Migration Engine")176        .navigationBarTitleDisplayMode(.inline)177        .qHaptic(.selection, trigger: chain)178    }179180    var resistantChains: [MigrationEngine.Chain] { MigrationEngine.Chain.displayOrder.filter(MigrationEngine.chainOffersQuantumResistance) }181182    @ViewBuilder var statement: some View {183        if resistantChains.isEmpty {184            WarningBanner(.warning, title: "No network of the registry is quantum-resistant today",185                          message: "Bitcoin, Litecoin, Dogecoin, Bitcoin Cash, the EVM networks and TRON are controlled by secp256k1 signatures, Solana by Ed25519 signatures. No deployed mechanism on any of them resists a quantum attacker, and no wallet can add one.")186        } else {187            WarningBanner(.info, title: "Quantum resistance on the networks",188                          message: "The registry reports a quantum-resistant mechanism as available on: \(resistantChains.map(\.title).joined(separator: ", ")). See the available entries below.")189        }190    }191192    var chainPicker: some View {193        ScrollViewReader { proxy in194            ScrollView(.horizontal, showsIndicators: false) {195                HStack(spacing: QSpace.s) {196                    ForEach(MigrationEngine.Chain.displayOrder, id: \.self) { c in197                        chip(c).id(c)198                    }199                }200                .padding(.horizontal, QMetric.screenPadding)201            }202            .padding(.horizontal, -QMetric.screenPadding)203            .onAppear { proxy.scrollTo(chain, anchor: .center) }204        }205        .accessibilityElement(children: .contain)206        .accessibilityLabel("Chain")207    }208209    func chip(_ c: MigrationEngine.Chain) -> some View {210        let selected = c == chain211        return Button {212            withAnimation(QMotion.resolved(QMotion.standard, reduceMotion: reduceMotion)) { chain = c }213        } label: {214            HStack(spacing: QSpace.s) {215                ChainGlyph(c.qChain, size: .small)216                Text(c.title).font(QFont.subheadline).foregroundStyle(selected ? QColor.textPrimary : QColor.textSecondary)217            }218            .padding(.leading, 6)219            .padding(.trailing, QSpace.m)220            .frame(minHeight: QMetric.minTap)221            .background(selected ? QColor.surfaceRaised : QColor.surface, in: Capsule())222            .overlay(Capsule().strokeBorder(selected ? QColor.violet : QColor.stroke, lineWidth: selected ? 1.5 : 1))223            .contentShape(Capsule())224        }225        .buttonStyle(.qPressable)226        .accessibilityAddTraits(selected ? [.isSelected] : [])227    }228229    var chainSummary: some View {230        let resistant = MigrationEngine.chainOffersQuantumResistance(chain)231        let counts = [MigrationEngine.Status.available, .planned, .awaitingProtocol].map { s in capabilities.filter { $0.status == s }.count }232        return QListSection(separatorInset: QMetric.padding) {233            HStack(spacing: QSpace.m) {234                ChainGlyph(chain.qChain)235                VStack(alignment: .leading, spacing: 3) {236                    Text(chain.title).font(QFont.headline).foregroundStyle(QColor.textPrimary)237                        .accessibilityAddTraits(.isHeader)238                    Text(chain.scope).font(QFont.caption).foregroundStyle(QColor.textSecondary)239                }240                .fixedSize(horizontal: false, vertical: true)241                Spacer(minLength: 0)242            }243            .padding(.vertical, QSpace.m)244            .frame(minHeight: QMetric.rowMinHeight)245            .accessibilityElement(children: .combine)246            Label(resistant ? "A quantum-resistant mechanism is available" : "No quantum-resistant mechanism today",247                  systemImage: resistant ? "checkmark.shield" : "xmark.shield")248                .font(QFont.callout.weight(.semibold))249                .foregroundStyle(resistant ? QColor.positive : QColor.negative)250                .fixedSize(horizontal: false, vertical: true)251                .frame(maxWidth: .infinity, alignment: .leading)252                .padding(.vertical, QSpace.m)253            SegmentedSummaryBar(segments: [254                .init(label: "Available", value: Double(counts[0]), detail: "\(counts[0])", color: QColor.positive, pattern: .solid),255                .init(label: "Planned", value: Double(counts[1]), detail: "\(counts[1])", color: QColor.violet, pattern: .striped),256                .init(label: "Awaiting protocol", value: Double(counts[2]), detail: "\(counts[2])", color: QColor.textSecondary, pattern: .hollow),257            ], emptyLabel: "The registry has no entry for this chain")258                .padding(.vertical, QSpace.l)259        }260        .id("summary")261    }262263    var legend: some View {264        Text("\u{201C}Quantum-resistant once in use\u{201D} describes the mechanism itself. It says nothing about funds that stay on today's address types.")265            .font(QFont.caption)266            .foregroundStyle(QColor.textSecondary)267            .fixedSize(horizontal: false, vertical: true)268    }269}270271/// One entry of the registry, as a row of its status card. A locked entry is dimmed and says what it waits for.272struct CapabilityCard: View {273    let capability: MigrationEngine.Capability274275    var isLocked: Bool { capability.status == .awaitingProtocol }276277    var body: some View {278        VStack(alignment: .leading, spacing: QSpace.s) {279            HStack(alignment: .firstTextBaseline, spacing: QSpace.s) {280                if isLocked {281                    Image(systemName: "lock.fill").font(.footnote).foregroundStyle(QColor.textTertiary).accessibilityHidden(true)282                }283                Text(capability.title)284                    .font(QFont.headline)285                    .foregroundStyle(isLocked ? QColor.textSecondary : QColor.textPrimary)286                Spacer(minLength: 0)287            }288            Text(capability.detail)289                .font(QFont.callout)290                .foregroundStyle(QColor.textSecondary)291            if let requirement = capability.requirement {292                VStack(alignment: .leading, spacing: 3) {293                    QEyebrow(isLocked ? "Requires" : "Before it ships")294                    Text(requirement).font(QFont.callout).foregroundStyle(isLocked ? QColor.textSecondary : QColor.textPrimary)295                }296            }297            ViewThatFits(in: .horizontal) {298                HStack(spacing: 6) { badges }299                VStack(alignment: .leading, spacing: 6) { badges }300            }301            if isLocked {302                Text("Disabled. QYVORA cannot enable this before the network supports it.")303                    .font(QFont.caption)304                    .foregroundStyle(QColor.textTertiary)305            }306        }307        .fixedSize(horizontal: false, vertical: true)308        .frame(maxWidth: .infinity, alignment: .leading)309        .padding(.vertical, QSpace.l)310        .accessibilityElement(children: .combine)311        .accessibilityHint(isLocked ? "Disabled, awaiting a protocol change" : "")312    }313314    @ViewBuilder var badges: some View {315        QBadge(capability.status.title, systemImage: capability.status.systemImage, tone: capability.status.tone)316        QBadge(capability.family.title, tone: .neutral)317        if capability.quantumResistant {318            QBadge("Quantum-resistant once in use", systemImage: "shield", tone: .neutral)319        }320    }321}322
Files main
Menu

Theme