Repository Public
1// SP Wallet iOS2// File: Features/Swap/OperationTracker.swift3// Description: Follow-up of a swap, a CCTP transfer or a THORChain swap through its REAL states, read from the proposal: the4// approval pre-transaction, the source transaction, then — for a cross-network operation — the second leg. A5// broadcast is never shown as done; the amount received appears only when the server read it from the chain; a6// refund is not a success. Offers the owner's actions as served: finish, look now, a new mint signature and the7// reclaim of a Solana deposit (both with a passkey over a verified object).8//9// Author: Simon-Pierre Boucher10// Contact: contact@spboucher.ai11import SwiftUI12import SPWalletCore1314struct OperationTracker: View {15 @Environment(AppModel.self) private var model16 let proposalId: String17 @State private var proposal: Proposal?18 @State private var loadError: Error?19 @State private var busy = false20 @State private var actionError: Error?21 @State private var mintRetry: MintRetryApproval?22 @State private var reclaim: DepositReclaimApproval?2324 var body: some View {25 VStack(alignment: .leading, spacing: 14) {26 if let p = proposal { content(p) }27 else if let loadError { ErrorNotice(error: loadError) }28 else { ProgressView().frame(maxWidth: .infinity) }29 }30 .task(id: proposalId) {31 var settledRefreshDone = false32 while !Task.isCancelled {33 do { proposal = try await SwapAPI(model.env.client).proposal(proposalId); loadError = nil } catch { if proposal == nil { loadError = error } }34 var pause = 4.035 if let p = proposal, SwapLogic.outcome(of: p).isSettled {36 if !settledRefreshDone { settledRefreshDone = true; await model.refreshAll() }37 // a settled operation only changes again through a Solana deposit reclaim38 let sol = (try? p.bridgeSection())?.sol39 guard let s = sol?.reclaimState, s != .done else { break }40 pause = 2041 }42 try? await Task.sleep(for: .seconds(pause))43 }44 }45 }4647 // MARK: content4849 @ViewBuilder private func content(_ p: Proposal) -> some View {50 let outcome = SwapLogic.outcome(of: p)51 let head = SwapLogic.label(outcome.completion, kind: p.kind)52 VStack(alignment: .leading, spacing: 6) {53 Text(Money.exact(p.amountDisplay) + " " + p.symbol).font(.system(size: 28, weight: .semibold)).tracking(-0.5).foregroundStyle(Theme.ink)54 HStack(spacing: 10) {55 if outcome.completion == .inProgress { ProgressView() } else { Image(systemName: head.symbol).font(.system(size: 20)).foregroundStyle(head.tone.color) }56 Text(head.text).font(.spHeadline).foregroundStyle(Theme.ink).fixedSize(horizontal: false, vertical: true)57 }58 .accessibilityElement(children: .combine)59 .accessibilityIdentifier("optracker.outcome")60 }61 if outcome.unreadable {62 Notice(tone: .warn, title: String(localized: "Détail de l’opération illisible"), message: String(localized: "L’app ne sait pas lire l’état renvoyé par le serveur ; elle n’en déduit rien. L’état de la transaction source reste affiché ci-dessous."))63 }64 if outcome.completion == .inProgress, p.kind != "swap", p.state == .finalized {65 Notice(tone: .info, title: String(localized: "Transaction source confirmée — l’opération n’est PAS terminée"),66 message: String(localized: "Les fonds ont quitté le réseau source. L’opération n’est terminée que lorsque la destination est confirmée."))67 }68 if p.state == .pendingApproval {69 Notice(tone: .warn, title: String(localized: "Préparée, pas approuvée"),70 message: String(localized: "Cette proposition attend une approbation, mais l’app n’approuve que ce qu’elle vient de vérifier. Refuse-la puis prépare l’opération de nouveau (elle expire seule sinon)."))71 Button { act { try await SwapAPI(model.env.client).reject(p.id) } } label: { HStack { if busy { ProgressView() }; Text(String(localized: "Refuser cette proposition")) } }72 .buttonStyle(.spSecondary).disabled(busy || !model.canOperate).accessibilityIdentifier("optracker.reject")73 }74 if p.state == .notBroadcast {75 Notice(tone: .warn, title: String(localized: "Signée mais non diffusée"), message: String(localized: "Ce serveur a la diffusion désactivée : rien n’a quitté le serveur et rien ne sera confirmé."))76 }77 sourceCard(p)78 if let s = try? p.swapSection(), p.kind == "swap" { swapCard(s, final: outcome.isComplete) }79 if let b = try? p.bridgeSection() { BridgeProgress(proposal: p, bridge: b, busy: busy, mintRetry: mintRetry, reclaim: reclaim,80 finish: { act { try await BridgeAPI(model.env.client).finish(p.id) } },81 askMint: { ask { mintRetry = try await BridgeAPI(model.env.client).retryMintOptions(p.id) } },82 confirmMint: { if let m = mintRetry { act { let r = try await BridgeAPI(model.env.client).retryMint(m, with: model.env.passkeys); mintRetry = nil; return r } } },83 askReclaim: { ask { reclaim = try await BridgeAPI(model.env.client).reclaimOptions(p.id) } },84 confirmReclaim: { if let r = reclaim { act { let q = try await BridgeAPI(model.env.client).reclaim(r, with: model.env.passkeys); reclaim = nil; return q } } },85 cancelAsk: { mintRetry = nil; reclaim = nil }) }86 if let x = try? p.xswapSection() { XSwapProgress(proposal: p, x: x, busy: busy, refresh: { act { try await XSwapAPI(model.env.client).refresh(p.id) } }) }87 if let e = actionError { ErrorNotice(error: e).accessibilityIdentifier("optracker.error") }88 if let ex = try? p.executionStatus(), !ex.steps.isEmpty { ExecutionSteps(status: ex) }89 }9091 private func sourceCard(_ p: Proposal) -> some View {92 VStack(alignment: .leading, spacing: 0) {93 Text(p.kind == "swap" ? String(localized: "Transaction d’échange") : String(localized: "Transaction sur le réseau source")).spEyebrow().padding(.bottom, 6)94 HStack(spacing: 8) {95 Image(systemName: p.state.symbol).foregroundStyle(p.state.tone.color)96 Text(p.state.label).font(.spBody.weight(.medium)).foregroundStyle(Theme.ink)97 }98 .padding(.vertical, 6).accessibilityElement(children: .combine).accessibilityIdentifier("optracker.state")99 FieldRow(label: String(localized: "Réseau"), value: p.networkName ?? p.network)100 if let c = p.confirmations { Divider(); FieldRow(label: String(localized: "Confirmations"), value: String(c)) }101 if let t = p.txid { Divider(); FieldRow(label: String(localized: "Identifiant de transaction"), value: t, mono: true, copyable: true) }102 if let e = p.error { Divider(); FieldRow(label: String(localized: "Erreur"), value: e + (p.errorCode.map { " (\($0))" } ?? ""), tone: .danger) }103 ExplorerLink(url: p.explorer)104 }105 .spCard(padding: 16)106 }107108 private func swapCard(_ s: SwapSection, final: Bool) -> some View {109 VStack(alignment: .leading, spacing: 0) {110 Text(String(localized: "Échange")).spEyebrow().padding(.bottom, 6)111 if s.needsApproval == true || s.approvalState != nil {112 FieldRow(label: String(localized: "Transaction d’approbation du jeton (avant l’échange)"), value: ApprovalStateText.label(s.approvalState), tone: s.approvalState == "confirmed" ? .ok : .info)113 if let t = s.approvalTxid { FieldRow(label: String(localized: "Identifiant de la transaction d’approbation"), value: t, mono: true, copyable: true) }114 Divider()115 }116 FieldRow(label: String(localized: "Sortie attendue (estimation)"), value: Money.exact(s.expectedOutDisplay) + " " + s.toSymbol)117 Divider()118 FieldRow(label: String(localized: "Minimum garanti"), value: Money.exact(s.minOutDisplay) + " " + s.toSymbol)119 Divider()120 if let r = s.receivedDisplay {121 // the server reads the output from the receipt as soon as the transaction is mined: until it is final it can still be reorganised122 FieldRow(label: final ? String(localized: "Reçu (lu sur la chaîne, transaction confirmée)") : String(localized: "Reçu d’après la transaction minée — PAS encore finale"),123 value: Money.exact(r) + " " + s.toSymbol, tone: final ? .ok : .info).accessibilityIdentifier(final ? "optracker.received" : "optracker.receivedNotFinal")124 } else {125 FieldRow(label: String(localized: "Reçu"), value: String(localized: "Pas encore lu sur la chaîne"), tone: .neutral).accessibilityIdentifier("optracker.notReceived")126 }127 }128 .spCard(padding: 16)129 }130131 // MARK: actions132133 /** An action whose answer is the proposal after it. */134 private func act(_ run: @escaping @MainActor () async throws -> Proposal) {135 guard !busy else { return }136 busy = true; actionError = nil137 Task {138 defer { busy = false }139 do { proposal = try await run() }140 catch PasskeyError.cancelled { /* nothing signed */ }141 catch { actionError = error }142 }143 }144 /** Ask for a verified challenge (nothing is signed yet). */145 private func ask(_ run: @escaping @MainActor () async throws -> Void) {146 guard !busy else { return }147 busy = true; actionError = nil148 Task { defer { busy = false }; do { try await run() } catch { actionError = error } }149 }150}151152enum ApprovalStateText {153 static func label(_ s: String?) -> String {154 switch s {155 case "pending": String(localized: "En attente d’envoi")156 case "sent": String(localized: "Envoyée, non confirmée")157 case "confirmed": String(localized: "Confirmée")158 case nil: String(localized: "Prévue, pas encore envoyée")159 case let other?: other160 }161 }162}163164/** The unified execution steps, exactly as the server lists them. */165struct ExecutionSteps: View {166 let status: ExecutionStatus167 private func kind(_ k: String) -> String {168 switch k {169 case "approval": String(localized: "Approbation du jeton")170 case "send": String(localized: "Envoi")171 case "swap": String(localized: "Échange")172 case "burn": String(localized: "Brûlage (source)")173 case "attestation": String(localized: "Attestation Circle")174 case "mint": String(localized: "Émission (destination)")175 case "deposit": String(localized: "Dépôt au coffre")176 case "observation": String(localized: "Observation par THORChain")177 case "outbound": String(localized: "Sortie vers le portefeuille")178 default: k179 }180 }181 private func state(_ s: ExecState) -> (String, Tone, String) {182 switch s {183 case .pending: (String(localized: "en attente"), .neutral, "circle.dashed")184 case .awaitingApproval: (String(localized: "attend l’approbation"), .neutral, "circle.dashed")185 case .signing: (String(localized: "signature"), .info, "clock.arrow.2.circlepath")186 case .broadcast: (String(localized: "diffusée, non confirmée"), .info, "clock.arrow.2.circlepath")187 case .confirming: (String(localized: "en confirmation"), .info, "clock.arrow.2.circlepath")188 case .confirmed: (String(localized: "confirmée"), .ok, "checkmark.circle.fill")189 case .failed: (String(localized: "échouée"), .danger, "xmark.octagon.fill")190 case .refunded: (String(localized: "remboursée"), .warn, "arrow.uturn.backward.circle.fill")191 default: (s.rawValue, .neutral, "questionmark.circle")192 }193 }194 var body: some View {195 VStack(alignment: .leading, spacing: 0) {196 Text(String(localized: "Étapes d’exécution (selon le serveur)")).spEyebrow().padding(.bottom, 8)197 ForEach(Array(status.steps.enumerated()), id: \.offset) { k, step in198 let (text, tone, symbol) = state(step.state)199 if k > 0 { Divider() }200 VStack(alignment: .leading, spacing: 3) {201 HStack(alignment: .firstTextBaseline, spacing: 8) {202 Image(systemName: symbol).foregroundStyle(tone.color).font(.system(size: 14, weight: .semibold))203 Text(kind(step.kind) + " · " + step.network).font(.spBody.weight(.medium)).foregroundStyle(Theme.ink)204 Spacer(minLength: 6)205 Text(text).font(.spFootnote.weight(.semibold)).foregroundStyle(tone.color)206 }207 if let c = step.code { Text(c).font(.spFootnote).foregroundStyle(Theme.mute) }208 if let t = step.txid { Text(t).font(.system(size: 11.5, design: .monospaced)).foregroundStyle(Theme.mute).textSelection(.enabled).fixedSize(horizontal: false, vertical: true) }209 ExplorerLink(url: step.explorer)210 }211 .padding(.vertical, 7)212 }213 }214 .spCard(padding: 16)215 }216}217218// MARK: - CCTP219220enum BridgeText {221 static func stage(_ s: BridgeStage) -> String {222 switch s {223 case .review: String(localized: "À approuver")224 case .burning: String(localized: "Brûlage des USDC sur le réseau source")225 case .attesting: String(localized: "Attestation par Circle")226 case .ready: String(localized: "Attesté : prêt à être émis sur la destination")227 case .minting: String(localized: "Émission sur le réseau de destination")228 case .mintFailed: String(localized: "Émission échouée : une nouvelle signature est requise")229 case .done: String(localized: "Terminé : USDC reçus sur la destination")230 case .failed: String(localized: "Abandonné : rien n’a été brûlé par cette opération")231 default: s.rawValue232 }233 }234 static func tone(_ s: BridgeStage) -> Tone {235 switch s { case .done: .ok; case .failed, .mintFailed: .danger; case .review, .ready: .warn; default: .info }236 }237 static let order: [BridgeStage] = [.burning, .attesting, .ready, .minting, .done]238 /** Position of the transfer in the five steps; `mint_failed` stands at the mint. nil for review / failed / an unknown stage. */239 static func position(_ s: BridgeStage) -> Int? { s == .mintFailed ? 3 : order.firstIndex(of: s) }240 static func reclaim(_ s: ReclaimState) -> String {241 switch s {242 case .pending: String(localized: "Le brûlage n’est pas encore confirmé")243 case .locked: String(localized: "Verrouillé par le programme (cinq jours après le brûlage)")244 case .available: String(localized: "Récupérable maintenant")245 case .sent: String(localized: "Récupération envoyée, non confirmée")246 case .done: String(localized: "Dépôt récupéré")247 case .failed: String(localized: "Récupération échouée : le dépôt est toujours là")248 default: s.rawValue249 }250 }251}252253struct BridgeProgress: View {254 @Environment(AppModel.self) private var model255 let proposal: Proposal256 let bridge: BridgeSection257 let busy: Bool258 let mintRetry: MintRetryApproval?259 let reclaim: DepositReclaimApproval?260 let finish: () -> Void261 let askMint: () -> Void262 let confirmMint: () -> Void263 let askReclaim: () -> Void264 let confirmReclaim: () -> Void265 let cancelAsk: () -> Void266267 var body: some View {268 let b = bridge269 VStack(alignment: .leading, spacing: 0) {270 Text(String(localized: "Transfert USDC (Circle CCTP) vers \(b.toNetworkName ?? b.toNetwork)")).spEyebrow().padding(.bottom, 8)271 HStack(spacing: 8) {272 Image(systemName: BridgeText.tone(b.stage).icon).foregroundStyle(BridgeText.tone(b.stage).color)273 Text(BridgeText.stage(b.stage)).font(.spBody.weight(.semibold)).foregroundStyle(Theme.ink).fixedSize(horizontal: false, vertical: true)274 }275 .accessibilityElement(children: .combine).accessibilityIdentifier("bridge.stage")276 if let pos = BridgeText.position(b.stage) {277 VStack(alignment: .leading, spacing: 6) {278 ForEach(Array(BridgeText.order.enumerated()), id: \.offset) { k, s in279 let done = k < pos || b.isComplete, current = k == pos && !b.isComplete280 HStack(spacing: 8) {281 Image(systemName: done ? "checkmark.circle.fill" : current ? (b.stage == .mintFailed ? "xmark.octagon.fill" : "clock.arrow.2.circlepath") : "circle")282 .foregroundStyle(done ? Theme.emerald : current ? (b.stage == .mintFailed ? Theme.danger : Theme.blue) : Theme.mute).font(.system(size: 13, weight: .semibold))283 Text(BridgeText.stage(s)).font(.spFootnote).foregroundStyle(done || current ? Theme.ink : Theme.mute)284 }285 }286 }.padding(.vertical, 8)287 }288 if let hold = b.hold {289 Notice(tone: .warn, title: String(localized: "En attente : \(hold)"), message: b.holdDetail ?? b.delayReason).padding(.vertical, 6)290 }291 Divider()292 FieldRow(label: String(localized: "Vitesse"), value: b.speed.map { $0 == .fast ? String(localized: "Rapide") : $0 == .standard ? String(localized: "Standard") : $0.rawValue } ?? String(localized: "non indiquée"))293 Divider()294 FieldRow(label: String(localized: "Frais du pont approuvés (plafond)"), value: Money.exact(b.cctpMaxFeeDisplay) + " USDC")295 if let f = b.feeExecutedDisplay { Divider(); FieldRow(label: String(localized: "Frais du pont réellement prélevés"), value: Money.exact(f) + " USDC") }296 Divider()297 FieldRow(label: String(localized: "Minimum reçu"), value: Money.exact(b.minReceiveDisplay) + " USDC")298 Divider()299 if let r = b.receivedDisplay, b.isComplete {300 FieldRow(label: String(localized: "Reçu sur la destination (confirmé)"), value: Money.exact(r) + " USDC", tone: .ok).accessibilityIdentifier("bridge.received")301 } else {302 FieldRow(label: String(localized: "Reçu sur la destination"), value: String(localized: "Pas encore : l’émission n’est pas confirmée"), tone: .neutral).accessibilityIdentifier("bridge.notReceived")303 }304 if b.needsApproval == true || b.approvalState != nil {305 Divider(); FieldRow(label: String(localized: "Transaction d’approbation du jeton (avant le brûlage)"), value: ApprovalStateText.label(b.approvalState))306 if let t = b.approvalTxid { FieldRow(label: String(localized: "Identifiant de la transaction d’approbation"), value: t, mono: true, copyable: true) }307 }308 if let t = proposal.txid { Divider(); FieldRow(label: String(localized: "Transaction 1 — brûlage (\(proposal.networkName ?? proposal.network))"), value: t, mono: true, copyable: true); ExplorerLink(url: proposal.explorer) }309 if let t = b.mintTxid {310 Divider(); FieldRow(label: String(localized: "Transaction 2 — émission (\(b.toNetworkName ?? b.toNetwork))"), value: t, mono: true, copyable: true)311 if b.mintedBy == "other" { Text(String(localized: "Émission soumise par un tiers (elle est sans permission) : les USDC arrivent quand même à ce portefeuille.")).font(.spFootnote).foregroundStyle(Theme.mute) }312 ExplorerLink(url: b.mintExplorer)313 }314 }315 .spCard(padding: 16)316317 if b.canFinish == true, mintRetry == nil {318 VStack(alignment: .leading, spacing: 6) {319 Button { finish() } label: { HStack { if busy { ProgressView() }; Text(String(localized: "Terminer maintenant")) } }.buttonStyle(.spSecondary).disabled(busy || !model.canOperate).accessibilityIdentifier("bridge.finish")320 Text(String(localized: "Lance l’étape suivante sans attendre le serveur. Ne signe rien de plus que ce que l’approbation du brûlage couvrait.")).font(.spFootnote).foregroundStyle(Theme.mute)321 }322 }323 if b.needsPasskey == true || b.stage == .mintFailed { mintRetryCard }324 if let sol = b.sol { solanaCard(sol) }325 }326327 @ViewBuilder private var mintRetryCard: some View {328 VStack(alignment: .leading, spacing: 10) {329 Notice(tone: .danger, title: String(localized: "L’émission doit être signée de nouveau"),330 message: String(localized: "Les USDC brûlés ne sont pas perdus : ils restent réclamables. Une nouvelle transaction d’émission exige ta clé d’accès."))331 if let m = mintRetry {332 VStack(alignment: .leading, spacing: 0) {333 FieldRow(label: String(localized: "Transfert concerné"), value: m.object.proposalId, mono: true)334 Divider(); FieldRow(label: String(localized: "Message Circle (empreinte)"), value: m.object.messageHash, mono: true)335 Divider(); FieldRow(label: String(localized: "Frais de réseau de la nouvelle émission, plafond"), value: feeCeiling(m))336 Divider(); FieldRow(label: String(localized: "Empreinte approuvée par la clé d’accès"), value: m.approval.digest.hex, mono: true, copyable: true)337 }.spCard(padding: 16)338 Button { confirmMint() } label: { HStack { if busy { ProgressView().tint(Theme.onPrimary) } else { Image(systemName: "person.badge.key.fill") }; Text(String(localized: "Signer la nouvelle émission avec la clé d’accès")) } }339 .buttonStyle(.spPrimary).disabled(busy || !model.canOperate).accessibilityIdentifier("bridge.retryMint.confirm")340 Button(String(localized: "Pas maintenant")) { cancelAsk() }.buttonStyle(.spSecondary).disabled(busy)341 } else {342 Button { askMint() } label: { HStack { if busy { ProgressView() }; Text(String(localized: "Préparer la nouvelle émission")) } }343 .buttonStyle(.spSecondary).disabled(busy || !model.canOperate).accessibilityIdentifier("bridge.retryMint")344 }345 }346 }347348 private func feeCeiling(_ m: MintRetryApproval) -> String {349 let native = model.network(bridge.toNetwork)?.native350 func show(_ units: String) -> String {351 guard let native, let u = try? BaseUnits(units) else { return units + " " + String(localized: "(unités de base)") }352 return Money.exact(u.formatted(decimals: native.decimals)) + " " + native.symbol353 }354 switch m.object.parameters {355 case .evm(let g): return show(g.maxNetworkFee)356 case .solana(let s): return s.singleSignerNetworkFee.map { show($0.description) } ?? String(localized: "non calculable")357 }358 }359360 @ViewBuilder private func solanaCard(_ sol: SolanaBridgeSection) -> some View {361 let lamports = model.network("solana")?.native362 VStack(alignment: .leading, spacing: 0) {363 Text(sol.role == "source" ? String(localized: "Côté Solana : dépôt du compte d’événement") : String(localized: "Côté Solana : destination")).spEyebrow().padding(.bottom, 6)364 if let r = sol.recipient { FieldRow(label: String(localized: "Adresse Solana du portefeuille"), value: r, mono: true, copyable: true); Divider() }365 if let t = sol.tokenAccount { FieldRow(label: String(localized: "Compte de jetons USDC"), value: t, mono: true, copyable: true); Divider() }366 if let e = sol.eventAccount { FieldRow(label: String(localized: "Compte d’événement du brûlage"), value: e, mono: true, copyable: true); Divider() }367 if let d = sol.depositDisplay { FieldRow(label: String(localized: "Dépôt remboursable"), value: Money.exact(d) + " " + (sol.symbol ?? lamports?.symbol ?? "")); Divider() }368 if let s = sol.reclaimState {369 FieldRow(label: String(localized: "Récupération du dépôt"), value: BridgeText.reclaim(s), tone: s == .done ? .ok : s == .failed ? .danger : nil).accessibilityIdentifier("bridge.reclaimState")370 if let at = sol.reclaimableAt, s == .locked || s == .pending {371 FieldRow(label: sol.reclaimEstimated == true ? String(localized: "Récupérable vers (estimation)") : String(localized: "Récupérable à partir du"), value: at.formatted(date: .abbreviated, time: .shortened))372 }373 if let e = sol.reclaimError { FieldRow(label: String(localized: "Erreur de la dernière tentative"), value: e, tone: .danger) }374 if let t = sol.reclaimTxid { FieldRow(label: String(localized: "Transaction de récupération"), value: t, mono: true, copyable: true); ExplorerLink(url: sol.reclaimExplorer) }375 if let r = sol.reclaimedDisplay, sol.isReclaimed { FieldRow(label: String(localized: "Récupéré (confirmé)"), value: Money.exact(r) + " " + (sol.symbol ?? lamports?.symbol ?? ""), tone: .ok) }376 }377 }378 .spCard(padding: 16)379 if sol.canReclaim {380 if let r = reclaim {381 VStack(alignment: .leading, spacing: 0) {382 FieldRow(label: String(localized: "Compte d’événement fermé"), value: r.object.eventAccount, mono: true)383 Divider(); FieldRow(label: String(localized: "Dépôt qui revient au portefeuille"), value: amount(r.deposit, lamports))384 Divider(); FieldRow(label: String(localized: "Frais de réseau de la récupération"), value: amount(r.networkFee, lamports))385 Divider(); FieldRow(label: String(localized: "Empreinte approuvée par la clé d’accès"), value: r.approval.digest.hex, mono: true, copyable: true)386 }.spCard(padding: 16)387 Button { confirmReclaim() } label: { HStack { if busy { ProgressView().tint(Theme.onPrimary) } else { Image(systemName: "person.badge.key.fill") }; Text(String(localized: "Récupérer le dépôt avec la clé d’accès")) } }388 .buttonStyle(.spPrimary).disabled(busy || !model.canOperate).accessibilityIdentifier("bridge.reclaim.confirm")389 Button(String(localized: "Pas maintenant")) { cancelAsk() }.buttonStyle(.spSecondary).disabled(busy)390 } else {391 Button { askReclaim() } label: { HStack { if busy { ProgressView() }; Text(String(localized: "Préparer la récupération du dépôt")) } }392 .buttonStyle(.spSecondary).disabled(busy || !model.canOperate).accessibilityIdentifier("bridge.reclaim")393 }394 }395 }396397 private func amount(_ units: String, _ def: AssetDef?) -> String {398 guard let def, let u = try? BaseUnits(units) else { return units + " " + String(localized: "(unités de base)") }399 return Money.exact(u.formatted(decimals: def.decimals)) + " " + def.symbol400 }401}402403// MARK: - THORChain404405enum XSwapText {406 static func stage(_ s: XSwapStage) -> String {407 switch s {408 case .review: String(localized: "À approuver")409 case .sending: String(localized: "Envoi au coffre THORChain")410 case .sent: String(localized: "Envoyé au coffre, pas encore observé par THORChain")411 case .observed: String(localized: "Dépôt observé par THORChain : échange en cours")412 case .outbound: String(localized: "Sortie annoncée, pas encore vue sur la destination")413 case .received: String(localized: "Reçu sur le réseau de destination")414 case .refunded: String(localized: "Remboursé par THORChain : l’échange n’a pas eu lieu")415 case .failed: String(localized: "Abandonné : rien n’est parti vers le coffre")416 default: s.rawValue417 }418 }419 static func tone(_ s: XSwapStage) -> Tone {420 switch s { case .received: .ok; case .refunded, .review: .warn; case .failed: .danger; default: .info }421 }422}423424struct XSwapProgress: View {425 @Environment(AppModel.self) private var model426 let proposal: Proposal427 let x: XSwapSection428 let busy: Bool429 let refresh: () -> Void430431 var body: some View {432 VStack(alignment: .leading, spacing: 0) {433 Text(String(localized: "Échange natif (THORChain) vers \(x.toNetworkName ?? x.toNetwork)")).spEyebrow().padding(.bottom, 8)434 HStack(spacing: 8) {435 Image(systemName: XSwapText.tone(x.stage).icon).foregroundStyle(XSwapText.tone(x.stage).color)436 Text(XSwapText.stage(x.stage)).font(.spBody.weight(.semibold)).foregroundStyle(Theme.ink).fixedSize(horizontal: false, vertical: true)437 }438 .padding(.bottom, 6).accessibilityElement(children: .combine).accessibilityIdentifier("xswap.stage")439 if x.isRefunded {440 Notice(tone: .warn, title: String(localized: "Remboursement, pas un succès"), message: String(localized: "THORChain a renvoyé l’actif source (moins ses frais). Tu n’as pas reçu l’actif demandé.")).padding(.vertical, 6)441 }442 if x.receivedBelowMinimum {443 Notice(tone: .danger, title: String(localized: "Reçu, mais SOUS le minimum approuvé"), message: x.holdDetail).padding(.vertical, 6)444 } else if let hold = x.hold {445 Notice(tone: .warn, title: String(localized: "En attente : \(hold)"), message: x.holdDetail).padding(.vertical, 6)446 }447 if x.refundPlanned == true, !x.isRefunded { Notice(tone: .warn, title: String(localized: "THORChain annonce un remboursement"), message: String(localized: "L’échange ne sera pas exécuté ; l’actif source doit revenir.")).padding(.vertical, 6) }448 Divider()449 FieldRow(label: String(localized: "Sortie attendue (estimation)"), value: Money.exact(x.expectedOutDisplay) + " " + x.toSymbol)450 Divider()451 FieldRow(label: String(localized: "Minimum approuvé"), value: Money.exact(x.minOutDisplay) + " " + x.toSymbol)452 Divider()453 if let r = x.receivedDisplay, x.isComplete {454 FieldRow(label: String(localized: "Reçu (vu sur la destination)"), value: Money.exact(r) + " " + x.toSymbol, tone: x.receivedBelowMinimum ? .danger : .ok).accessibilityIdentifier("xswap.received")455 } else if let r = x.refundedDisplay, x.isRefunded {456 FieldRow(label: String(localized: "Remboursé (actif source)"), value: Money.exact(r) + " " + proposal.symbol, tone: .warn).accessibilityIdentifier("xswap.refunded")457 } else {458 FieldRow(label: String(localized: "Reçu"), value: String(localized: "Pas encore vu sur la destination"), tone: .neutral)459 }460 Divider()461 FieldRow(label: String(localized: "Coffre (reçoit l’actif source)"), value: x.vault, mono: true, copyable: true)462 ExplorerLink(url: x.vaultExplorer, title: String(localized: "Voir le coffre"))463 Divider()464 FieldRow(label: String(localized: "Mémo"), value: x.memo, mono: true, copyable: true)465 if let t = x.outTxid {466 Divider()467 FieldRow(label: x.outKind == "refund" ? String(localized: "Transaction de remboursement") : String(localized: "Transaction de sortie"), value: t, mono: true, copyable: true)468 ExplorerLink(url: x.outExplorer)469 }470 }471 .spCard(padding: 16)472 if x.done != true, !x.isFailed, x.stage != .review {473 Button { refresh() } label: { HStack { if busy { ProgressView() }; Text(String(localized: "Regarder maintenant")) } }474 .buttonStyle(.spSecondary).disabled(busy || !model.canOperate).accessibilityIdentifier("xswap.refresh")475 }476 }477}478