Repository Public
1// Author: Simon-Pierre Boucher — contact@spboucher.ai2// File: Components/BalanceCard.swift3// Description: The portfolio's estimated total on the app's hero surface: an estimate by construction (on-chain balances × displayed prices), labelled as such, with its sources, its age and what is missing from it. Optional shortcut actions sit beside it.4import SwiftUI5import SPWalletCore67struct BalanceCard: View {8 let model: AppModel9 var nav: Navigator?1011 var body: some View {12 HeroCard {13 HStack(alignment: .top, spacing: 20) {14 VStack(alignment: .leading, spacing: 8) {15 HStack(spacing: 8) {16 Text("VALEUR TOTALE ESTIMÉE").font(.caption.weight(.semibold)).tracking(1.2).opacity(0.75)17 tag18 }19 figure20 footnote21 }22 Spacer(minLength: 12)23 if let nav {24 HStack(spacing: 6) {25 QuickAction(symbol: "arrow.up.right", title: "Envoyer", onDark: true) { nav.section = .send }.disabled(!model.canOperate).opacity(model.canOperate ? 1 : 0.45)26 QuickAction(symbol: "arrow.down.left", title: "Recevoir", onDark: true) { nav.section = .receive }27 QuickAction(symbol: "arrow.left.arrow.right", title: "Échanger", onDark: true) { nav.section = .swap }.disabled(!model.canOperate).opacity(model.canOperate ? 1 : 0.45)28 QuickAction(symbol: "point.topleft.down.to.point.bottomright.curvepath", title: "Pont", onDark: true) { nav.section = .bridge }.disabled(!model.canOperate).opacity(model.canOperate ? 1 : 0.45)29 }.padding(.top, 6)30 }31 }32 }33 }3435 private func chip(_ text: String, _ symbol: String, warn: Bool = false) -> some View {36 Label(text, systemImage: symbol).font(.caption.weight(.medium)).lineLimit(1)37 .padding(.horizontal, 9).padding(.vertical, 4)38 .background((warn ? Theme.warning : Color.white).opacity(warn ? 0.9 : 0.16), in: Capsule())39 .foregroundStyle(warn ? Color.black : Color.white)40 }4142 @ViewBuilder private var tag: some View {43 if let src = model.portfolio {44 if src.fromCache { chip("Données du \(Fmt.date(src.fetchedAt))", "clock.badge.exclamationmark", warn: true) }45 else if !model.settings.prices || src.value.prices == nil { chip("Prix indisponibles", "xmark.octagon", warn: true) }46 else if src.value.pricesStale { chip("Certains prix périmés", "clock.badge.exclamationmark", warn: true) }47 else { chip("Estimation", "tilde") }48 }49 }5051 @ViewBuilder private var figure: some View {52 if let p = model.portfolio?.value, p.prices != nil, model.settings.prices {53 let total = p.estimatedTotal(in: model.currency)54 Text(model.settings.hideBalances ? "••••••" : Fmt.fiat(total.value, model.currency)).font(Theme.figure(46)).monospacedDigit().lineLimit(1).minimumScaleFactor(0.5)55 .textSelection(.enabled)56 } else {57 Text("—").font(Theme.figure(46))58 }59 }6061 @ViewBuilder private var footnote: some View {62 if let p = model.portfolio?.value {63 let total = p.estimatedTotal(in: model.currency), unread = p.balances.filter { !$0.isAvailable }.count64 let held = p.balances.filter(\.isNonZero)65 HStack(spacing: 14) {66 Label("\(held.count) actif\(held.count > 1 ? "s" : "") · \(Set(held.map(\.network)).count) réseau\(Set(held.map(\.network)).count > 1 ? "x" : "")", systemImage: "circle.hexagongrid")67 if let s = p.priceSource { Label("Prix \(s)\(p.pricesAsOf.map { " · \(Fmt.relative($0))" } ?? "")", systemImage: "chart.line.uptrend.xyaxis") }68 Label("Soldes lus \(Fmt.relative(p.asOf))", systemImage: "checkmark.seal")69 }.font(.caption).opacity(0.8).lineLimit(1)70 if !total.complete, p.prices != nil {71 Label(unread > 0 ? "Total incomplet : \(unread) solde(s) illisible(s) et/ou actifs sans prix non comptés." : "Total incomplet : certains actifs détenus n’ont pas de prix et ne sont pas comptés.", systemImage: "exclamationmark.triangle.fill")72 .font(.caption.weight(.medium)).foregroundStyle(Color(red: 1, green: 0.82, blue: 0.4))73 }74 } else {75 Text("Aucune donnée synchronisée.").font(.caption).opacity(0.8)76 }77 }78}79