SPB Git

Repository Public

DeleteWalletSheet.swift 6.6 KB 137 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project          : QYVORA7// File             : App/Sources/Security/DeleteWalletSheet.swift8// Module           : Security9// 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 QyvoraWallet43import QyvoraUI4445/// Erases the wallet from this device after a typed confirmation and, when a vault exists, a fresh authentication.46/// Reminds the user that only the recovery phrase restores the funds.47struct DeleteWalletSheet: View {48    @Environment(WalletStore.self) private var store49    @Environment(AppModel.self) private var model50    @Environment(\.dismiss) private var dismiss51    @State private var typed = ""52    @State private var error: String?53    @State private var busy = false54    @State private var reauthenticate = false5556    static let confirmationWord = "DELETE"5758    var profile: WalletProfile? { store.snapshot?.profile }59    var isWatchOnly: Bool { profile?.kind == .watchOnly }60    var confirmed: Bool { typed.trimmingCharacters(in: .whitespaces) == Self.confirmationWord }6162    var body: some View {63        ScrollView {64            VStack(alignment: .leading, spacing: 18) {65                SheetHeader("Delete wallet from this device", subtitle: "Irreversible on this device.") { dismiss() }66                if isWatchOnly {67                    WarningBanner(.info, title: "Watch-only wallet",68                                  message: "Only public keys and settings are erased. The funds are controlled by the device that holds the keys.")69                } else {70                    WarningBanner(.critical, title: "Only the recovery phrase restores the funds",71                                  message: "The vault, its previous copy, the Keychain material, the identity keys and the settings are erased. Nobody, including the publisher of QYVORA, can recover them. The coins stay on the blockchains and are reachable again only by restoring the recovery phrase (and its passphrase, when one is used).")72                    if profile?.recoveryPhraseVerified != true {73                        WarningBanner(.warning, title: "The backup of the phrase was never verified",74                                      message: "Verify the recovery phrase in Recovery before deleting. If the written copy is wrong, the funds are lost.")75                    }76                    if profile?.usesPassphrase == true {77                        WarningBanner(.warning, message: "This wallet uses a BIP-39 passphrase. The 24 words alone do not restore it.")78                    }79                    Explanation("The post-quantum identity is not derived from the recovery phrase: it is lost unless an encrypted backup holds it.")80                }81                VStack(alignment: .leading, spacing: 6) {82                    Text("Type \(Self.confirmationWord) to confirm").font(QFont.callout).foregroundStyle(QColor.textSecondary)83                    TextField(Self.confirmationWord, text: $typed)84                        .textInputAutocapitalization(.characters)85                        .autocorrectionDisabled()86                        .font(QFont.body.monospaced())87                        .padding(12)88                        .background(QColor.surface, in: RoundedRectangle(cornerRadius: QMetric.radiusSmall, style: .continuous))89                        .overlay(RoundedRectangle(cornerRadius: QMetric.radiusSmall, style: .continuous).strokeBorder(QColor.stroke, lineWidth: 1))90                        .accessibilityLabel("Type \(Self.confirmationWord) to confirm")91                }92                SecInlineError(error)93                Button(role: .destructive) {94                    if store.snapshot?.vault.exists == true { reauthenticate = true } else { delete() }95                } label: {96                    HStack {97                        if busy { ProgressView().controlSize(.small) }98                        Label("Delete wallet", systemImage: "trash")99                    }100                    .font(.headline)101                    .frame(maxWidth: .infinity, minHeight: 50)102                    .foregroundStyle(confirmed ? QColor.onAccent : QColor.textTertiary)103                    .background(confirmed ? QColor.negative : QColor.surfaceRaised, in: RoundedRectangle(cornerRadius: QMetric.radiusSmall, style: .continuous))104                }105                .buttonStyle(.plain)106                .disabled(!confirmed || busy)107                Button("Cancel") { dismiss() }.buttonStyle(.qSecondary)108            }109            .padding(20)110            .frame(maxWidth: 560, alignment: .leading)111            .frame(maxWidth: .infinity)112        }113        .scrollDismissesKeyboard(.interactively)114        .qScreen()115        .interactiveDismissDisabled(busy)116        .requiresReauthentication(isPresented: $reauthenticate, reason: "Delete the wallet from this device") { delete() }117    }118119    func delete() {120        guard confirmed, !busy else { return }121        busy = true122        error = nil123        Task {124            do {125                try await store.run { try await $0.deleteWallet() }126                await store.refresh()127                busy = false128                dismiss()129                model.route = .onboarding130            } catch {131                self.error = SecurityError.text(error)132                busy = false133            }134        }135    }136}137
Files main
Menu

Theme