SPB Git

Repository Public

RiskReviewSheet.swift 11.1 KB 213 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project          : SP Wallet9// File             : Features/Security/RiskReviewSheet.swift10// Description      : The review that precedes a passkey prompt of the risk11//                    engine: releasing a switch (what is released, engaged12//                    when, by whom, why) or switching automatic stops off.13//                    Every value shown is read from the INTENT whose hash is14//                    the challenge, already verified by SPWalletCore. Nothing15//                    is truncated or folded; the sheet cannot be swiped away.16// Module           : Features17// Repository       : https://git.spboucher.ai/sp-wallet-ios18// Created          : 2026-11-1819// Last Modified    : 2026-11-1820//21// =============================================================================22// AUTHOR & PROFESSIONAL AFFILIATION23// =============================================================================24//25// Author           : Simon-Pierre Boucher26// Position         : Professor of Finance27// Institution      : Université du Québec en Outaouais (UQO)28// Department       : Département des sciences administratives29// Organization     : SP Boucher30//31// Website          : https://spboucher.ai32// Git              : https://git.spboucher.ai33//34// =============================================================================35// OFFICIAL CONTACT DIRECTORY36// =============================================================================37//38// General          : info@spboucher.ai39// Professional     : contact@spboucher.ai40// Direct           : simon@spboucher.ai41// Research         : research@spboucher.ai42// Development      : dev@spboucher.ai43// Support          : support@spboucher.ai44// Security/Admin   : admin@spboucher.ai45// Notifications    : notifications@spboucher.ai46//47// Preferred Contact: support@spboucher.ai48//49// =============================================================================50// COPYRIGHT & INTELLECTUAL PROPERTY51// =============================================================================52//53// Copyright (c) 202654// Simon-Pierre Boucher55//56// All rights reserved where applicable.57//58// This file is governed by the applicable project license,59// copyright notices, institutional agreements and relevant law.60//61// Unless expressly authorized by the applicable license or62// rights holder, copying, redistribution, sublicensing,63// publication and commercial exploitation are not permitted.64//65// Existing third-party rights and notices remain unaffected.66//67// =============================================================================68// CONFIDENTIALITY & SECURITY69// =============================================================================70//71// Classification   : Public72// Distribution     : Public repository; use is governed by the project license73// Security Contact : admin@spboucher.ai74//75// Access to this source does not independently grant permission76// to redistribute or disclose confidential materials.77//78// Do not embed credentials, private keys, access tokens,79// certificates or confidential personal information.80//81// =============================================================================82// LICENSE & MAINTENANCE83// =============================================================================84//85// License          : None specified (no license file in this repository)86// Maintainer       : Simon-Pierre Boucher87// Technical Contact: dev@spboucher.ai88//89// =============================================================================90// END OF SP BOUCHER SOURCE HEADER91// =============================================================================9293import SwiftUI94import SPWalletCore9596/** Approval window and digest of a verified intent, shared by every review of this area. */97struct RiskApprovalFacts: View {98    let expiry: Date99    let digest: Data100    var domain: String?101    var body: some View {102        VStack(alignment: .leading, spacing: 0) {103            TimelineView(.periodic(from: .now, by: 1)) { ctx in104                let left = Int(expiry.timeIntervalSince(ctx.date))105                FieldRow(label: String(localized: "Fenêtre d’approbation"), value: left > 0 ? String(localized: "expire dans \(left) s") : String(localized: "expirée"), tone: left > 15 ? nil : .danger)106            }107            Divider()108            FieldRow(label: String(localized: "Empreinte de l’intention (défi signé par la clé d’accès)"), value: digest.hex, mono: true, copyable: true)109            if let domain { Divider(); FieldRow(label: String(localized: "Domaine de l’intention"), value: domain, mono: true) }110        }111        .spCard(padding: 16)112        Label(String(localized: "L’app a recalculé cette empreinte à partir des champs affichés et vérifié qu’elle est le défi demandé à ta clé d’accès."), systemImage: "checkmark.shield.fill")113            .font(.spFootnote).foregroundStyle(Theme.mute)114    }115}116117/** Approve / expired / cancel, with the countdown deciding which is offered. */118struct RiskApproveButtons: View {119    @Environment(AppModel.self) private var model120    let expiry: Date121    let busy: Bool122    var title = String(localized: "Approuver avec la clé d’accès")123    var enabled = true124    var identifier = "risk.review.approve"125    let approve: () -> Void126    let cancel: () -> Void127    var body: some View {128        TimelineView(.periodic(from: .now, by: 1)) { ctx in129            VStack(spacing: 10) {130                if expiry <= ctx.date {131                    Notice(tone: .warn, title: String(localized: "Fenêtre expirée"), message: String(localized: "Ferme cette revue et recommence : une nouvelle intention sera préparée."))132                } else {133                    Button(action: approve) { HStack { if busy { ProgressView().tint(Theme.onPrimary) } else { Image(systemName: "person.badge.key.fill") }; Text(title) } }134                        .buttonStyle(.spPrimary).disabled(busy || !enabled || !model.canOperate).accessibilityIdentifier(identifier)135                }136                Button(String(localized: "Fermer sans approuver"), action: cancel).buttonStyle(.spSecondary).disabled(busy).accessibilityIdentifier("risk.review.cancel")137            }138        }139    }140}141142struct RiskReviewSheet: View {143    @Environment(AppModel.self) private var model144    let risk: RiskModel145    let review: RiskReview146147    var body: some View {148        NavigationStack {149            ScrollView {150                VStack(alignment: .leading, spacing: 14) {151                    switch review {152                    case .release(let a, let displayed): release(a, displayed)153                    case .auto(let a, let current): auto(a, current)154                    }155                    if let e = risk.reviewError { ErrorNotice(error: e).accessibilityIdentifier("risk.review.error") }156                    RiskApproveButtons(expiry: expiry, busy: risk.busy, approve: { Task { await risk.approve(model) } }, cancel: { risk.review = nil })157                }158                .padding(.horizontal, Theme.Space.gutter).padding(.vertical, 12)159                .frame(maxWidth: 620).frame(maxWidth: .infinity)160            }161            .spPage()162            .navigationTitle(String(localized: "Vérifier et approuver")).navigationBarTitleDisplayMode(.inline)163        }164        .interactiveDismissDisabled()165    }166167    private var expiry: Date {168        switch review { case .release(let a, _): a.intent.expiry; case .auto(let a, _): a.intent.expiry }169    }170171    @ViewBuilder private func release(_ a: RiskSwitchReleaseApproval, _ displayed: RiskSwitch) -> some View {172        VStack(alignment: .leading, spacing: 4) {173            Text(String(localized: "Lever")).spEyebrow()174            Text(RiskWords.switchTitle(a.kind)).font(.system(size: 26, weight: .semibold)).foregroundStyle(Theme.ink).fixedSize(horizontal: false, vertical: true)175                .accessibilityIdentifier("risk.review.title")176        }177        Notice(tone: .warn, title: String(localized: "Lever redonne de l’autorité"),178               message: a.kind == .killSwitch ? String(localized: "Après la levée, les ordres qui ajoutent du risque redeviennent possibles pour toi, les clés d’API et les agents, dans leurs limites.")179                : String(localized: "Après la levée, les ordres redeviennent possibles, dans leurs limites."))180        VStack(alignment: .leading, spacing: 0) {181            FieldRow(label: String(localized: "Interrupteur (nom du serveur)"), value: a.intent.kind.rawValue, mono: true); Divider()182            FieldRow(label: String(localized: "Engagé le"), value: RiskWords.date(ms: a.intent.engagedAt) ?? String(localized: "date non enregistrée")); Divider()183            FieldRow(label: String(localized: "Engagé par"), value: a.intent.engagedBy ?? String(localized: "non enregistré"), mono: true); Divider()184            FieldRow(label: String(localized: "Raison enregistrée"), value: a.intent.reason ?? String(localized: "aucune"))185        }186        .spCard(padding: 16)187        Text(String(localized: "L’app a vérifié que l’intention lève bien l’engagement qui était affiché (même date, même auteur, même raison). Un interrupteur réengagé entre-temps est refusé avant la clé d’accès."))188            .font(.spFootnote).foregroundStyle(Theme.mute)189        RiskApprovalFacts(expiry: a.intent.expiry, digest: a.approval.digest, domain: RiskSwitchReleaseIntent.domain)190    }191192    @ViewBuilder private func auto(_ a: AutoKillApproval, _ current: AutoKillSettings) -> some View {193        VStack(alignment: .leading, spacing: 4) {194            Text(String(localized: "Assouplissement")).spEyebrow()195            Text(String(localized: "Désactiver des arrêts automatiques")).font(.system(size: 26, weight: .semibold)).foregroundStyle(Theme.ink).fixedSize(horizontal: false, vertical: true)196        }197        Notice(tone: .warn, title: String(localized: "Ce que le serveur considère comme assoupli"), message: a.loosened.map(RiskWords.autoTitle).joined(separator: " · "))198            .accessibilityIdentifier("risk.review.loosened")199        VStack(alignment: .leading, spacing: 0) {200            ForEach(AutoKillSettings.keys, id: \.self) { key in201                let before = current.value(key), after = a.auto.value(key)202                FieldRow(label: RiskWords.autoTitle(key) + " (\(key))",203                         value: Self.onOff(before) + " → " + Self.onOff(after) + (a.loosened.contains(key) ? " · " + String(localized: "ASSOUPLI") : before == after ? " · " + String(localized: "inchangé") : ""),204                         tone: a.loosened.contains(key) ? .danger : nil)205                if key != AutoKillSettings.keys.last { Divider() }206            }207        }208        .spCard(padding: 16)209        RiskApprovalFacts(expiry: a.intent.expiry, digest: a.approval.digest, domain: AutoKillIntent.domain)210    }211    static func onOff(_ b: Bool) -> String { b ? String(localized: "activé") : String(localized: "désactivé") }212}213
Files main
Menu

Theme