Repository Public
1// Author: Simon-Pierre Boucher — contact@spboucher.ai2// File: Components/AssetRow.swift3// Description: One holding in a list: asset, network, exact balance as read on-chain, and the estimated fiat value with its provenance. A balance that could not be read is shown as unavailable, never as zero.4import SwiftUI5import SPWalletCore67struct AssetRow: View {8 let balance: Balance9 let portfolio: Portfolio10 let currency: FiatCurrency11 var hide = false12 var cached = false1314 var body: some View {15 let price = portfolio.prices?[balance.symbol]16 HStack(spacing: 12) {17 AssetBadge(symbol: balance.symbol)18 VStack(alignment: .leading, spacing: 1) {19 Text(balance.name).fontWeight(.medium).lineLimit(1)20 Text("\(balance.symbol) · \(balance.networkName)").font(.caption).foregroundStyle(.secondary)21 }22 Spacer()23 if let price {24 VStack(alignment: .trailing, spacing: 1) {25 Text(Fmt.price(price.value(in: currency), currency)).font(.callout).monospacedDigit()26 HStack(spacing: 4) {27 if price.stale { Image(systemName: "clock.badge.exclamationmark").foregroundStyle(Theme.warning).help("Prix périmé (\(Fmt.relative(price.priceAt)))") }28 if price.divergent == true { Image(systemName: "arrow.left.and.right.circle").foregroundStyle(Theme.warning).help("Les deux sources de prix divergent") }29 Text(Fmt.percent(price.change24h)).font(.caption).foregroundStyle(Theme.change(price.change24h)).monospacedDigit()30 }31 }.frame(width: 104, alignment: .trailing)32 }33 VStack(alignment: .trailing, spacing: 1) {34 if balance.isAvailable {35 Text(hide ? "••••" : "\(Fmt.amount(balance.display, maxFraction: 8)) \(balance.symbol)").monospacedDigit().fontWeight(.medium)36 Text(hide ? "••••" : Fmt.fiat(portfolio.estimatedValue(of: balance, in: currency), currency)).font(.caption).foregroundStyle(.secondary).monospacedDigit()37 } else {38 Label("Indisponible", systemImage: "xmark.octagon").font(.callout).foregroundStyle(Theme.negative).help("La lecture de ce solde sur la chaîne a échoué. Ce n’est pas un solde nul.")39 }40 }.frame(width: 170, alignment: .trailing)41 }42 .padding(.vertical, 4)43 .opacity(cached ? 0.85 : 1)44 .accessibilityElement(children: .combine)45 }46}47