Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project : QYVORA7// File : App/Sources/Wallet/WalletFormat.swift8// Module : Wallet9// 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 QyvoraCore43import QyvoraBitcoin44import QyvoraWallet45import QyvoraUI4647/// Formatting shared by the wallet screens. Pure functions; nothing here invents a value.48enum WalletFormat {49 /// "$1,234.56" in the display currency.50 static func fiat(_ value: Double, _ currency: DisplayCurrency) -> String {51 value.formatted(.currency(code: currency.rawValue.uppercased()))52 }5354 /// Fiat value of a base-unit amount, when a quote exists.55 static func fiat(units: UInt256, decimals: Int, quote: MarketQuote?) -> Double? {56 guard let quote, let amount = Double(BaseUnits.format(units, decimals: decimals)), amount.isFinite else { return nil }57 return amount * quote.price58 }5960 static func exposureLabel(_ exposure: PublicKeyExposure) -> String {61 switch exposure {62 case .hashedUnrevealed: return "Key not revealed"63 case .revealedBySpend: return "Key revealed by a spend"64 case .revealedByScript: return "Key in the script"65 case .undetermined: return "Exposure unknown"66 }67 }6869 static func exposureTone(_ exposure: PublicKeyExposure) -> QBadge.Tone {70 switch exposure {71 case .hashedUnrevealed: return .positive72 case .revealedBySpend, .revealedByScript: return .warning73 case .undetermined: return .neutral74 }75 }7677 static func day(_ date: Date) -> String {78 let calendar = Calendar.current79 if calendar.isDateInToday(date) { return "Today" }80 if calendar.isDateInYesterday(date) { return "Yesterday" }81 return date.formatted(date: .complete, time: .omitted)82 }8384 static func timestamp(_ date: Date) -> String {85 date.formatted(date: .abbreviated, time: .standard)86 }87}8889extension WalletSnapshot {90 var isWatchOnly: Bool { profile.kind == .watchOnly }91 var currency: DisplayCurrency { profile.displayCurrency }92}9394extension PriceRange {95 var chartRange: ChartRange {96 switch self {97 case .day: return .day98 case .week: return .week99 case .month: return .month100 case .year: return .year101 }102 }103}104