taler-ios

iOS apps for GNU Taler (wallet)
Log | Files | Refs | README | LICENSE

commit be28f565b289ec7695d70b137087c4db1237d6d5
parent 49bb0f37b18e65847d9944afcecf2838a3294b48
Author: Marc Stibane <marc@taler.net>
Date:   Sat, 27 Jul 2024 07:56:01 +0200

Binding<CurrencyInfo>

Diffstat:
MTalerWallet1/Views/Balances/BalanceCellV.swift | 4++--
MTalerWallet1/Views/Balances/BalancesPendingRowV.swift | 17++++++++++-------
MTalerWallet1/Views/Balances/BalancesSectionView.swift | 12++++++------
MTalerWallet1/Views/Balances/PendingRowView.swift | 10++++++----
MTalerWallet1/Views/Balances/SendRequestV.swift | 5+++--
MTalerWallet1/Views/Banking/DepositAmountV.swift | 4++--
MTalerWallet1/Views/Banking/DepositIbanV.swift | 4++--
MTalerWallet1/Views/Banking/DepositWithdrawV.swift | 5+++--
MTalerWallet1/Views/Banking/ExchangeRowView.swift | 73++++++++++++++++++++++++++++++++++++++-----------------------------------
MTalerWallet1/Views/Banking/ExchangeSectionView.swift | 10+++++++---
MTalerWallet1/Views/Banking/ManualWithdraw.swift | 7++++---
MTalerWallet1/Views/Banking/ManualWithdrawDone.swift | 16+++++++++-------
MTalerWallet1/Views/Banking/QuiteSomeCoins.swift | 2+-
MTalerWallet1/Views/HelperViews/AmountInputV.swift | 6+++---
MTalerWallet1/Views/HelperViews/AmountRowV.swift | 29++++++++++++++++++++---------
MTalerWallet1/Views/HelperViews/AmountV.swift | 6+++---
MTalerWallet1/Views/HelperViews/CurrencyField.swift | 10+++++-----
MTalerWallet1/Views/HelperViews/CurrencyInputView.swift | 15+++++++--------
MTalerWallet1/Views/HelperViews/SubjectInputV.swift | 2+-
MTalerWallet1/Views/Overview/OverviewRowV.swift | 17+++++++++--------
MTalerWallet1/Views/Overview/OverviewSectionV.swift | 16++++++++++------
MTalerWallet1/Views/Peer2peer/P2PReadyV.swift | 4++--
MTalerWallet1/Views/Peer2peer/P2PSubjectV.swift | 4++--
MTalerWallet1/Views/Peer2peer/RequestPayment.swift | 9+++++----
MTalerWallet1/Views/Peer2peer/SendAmount.swift | 11++++++-----
MTalerWallet1/Views/Sheets/P2P_Sheets/P2pPayURIView.swift | 9+++++++--
MTalerWallet1/Views/Sheets/P2P_Sheets/P2pReceiveURIView.swift | 8++++++--
MTalerWallet1/Views/Sheets/Payment/PayTemplateV.swift | 18++++++++++--------
MTalerWallet1/Views/Sheets/Payment/PaymentDone.swift | 4++--
MTalerWallet1/Views/Sheets/Payment/PaymentView.swift | 13+++++++++----
MTalerWallet1/Views/Sheets/Refund/RefundURIView.swift | 9+++++++--
MTalerWallet1/Views/Sheets/WithdrawBankIntegrated/WithdrawAcceptDone.swift | 30+++++++++++++++++++++++-------
MTalerWallet1/Views/Sheets/WithdrawBankIntegrated/WithdrawAcceptView.swift | 8++++----
MTalerWallet1/Views/Sheets/WithdrawBankIntegrated/WithdrawURIView.swift | 6+++---
MTalerWallet1/Views/Sheets/WithdrawExchangeV.swift | 1+
MTalerWallet1/Views/Transactions/ThreeAmountsSection.swift | 46++++++++++++++++++++++++++++++----------------
MTalerWallet1/Views/Transactions/TransactionRowView.swift | 24++++++++++++++++++------
MTalerWallet1/Views/Transactions/TransactionSummaryV.swift | 28+++++++++++++++-------------
MTalerWallet1/Views/Transactions/TransactionsListView.swift | 10+++++-----
39 files changed, 306 insertions(+), 206 deletions(-)

diff --git a/TalerWallet1/Views/Balances/BalanceCellV.swift b/TalerWallet1/Views/Balances/BalanceCellV.swift @@ -11,7 +11,7 @@ import SymLog struct BalanceCellV: View { let stack: CallStack? - let currencyInfo: CurrencyInfo + @Binding var currencyInfo: CurrencyInfo let amount: Amount // let sizeCategory: ContentSizeCategory // let rowAction: () -> Void @@ -25,7 +25,7 @@ struct BalanceCellV: View { /// amount (trailing) goes underneath "Balance" (leading). var body: some View { let amountV = AmountV(stack: stack?.push("AmountV"), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, amount: amount, isNegative: false, large: true) diff --git a/TalerWallet1/Views/Balances/BalancesPendingRowV.swift b/TalerWallet1/Views/Balances/BalancesPendingRowV.swift @@ -9,7 +9,7 @@ import taler_swift struct BalancesPendingRowV: View { // let symLog: SymLogV? // inherited from BalancesSectionView let stack: CallStack - let currencyInfo: CurrencyInfo + @Binding var currencyInfo: CurrencyInfo let balance: Balance @Binding var pendingTransactions: [Transaction] let reloadPending: (_ stack: CallStack) async -> () @@ -30,14 +30,14 @@ struct BalancesPendingRowV: View { VStack(spacing: 6) { if hasIncoming { - PendingRowView(currencyInfo: currencyInfo, + PendingRowView(currencyInfo: $currencyInfo, amount: pendingIncoming, incoming: true, shouldConfirm: shouldConfirm, needsKYC: needsKYCin) } if hasOutgoing { - PendingRowView(currencyInfo: currencyInfo, + PendingRowView(currencyInfo: $currencyInfo, amount: pendingOutgoing, incoming: false, shouldConfirm: false, @@ -61,7 +61,7 @@ struct BalancesPendingRowV: View { if let reloadOneAction { let destination = LazyView { TransactionsListView(stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, navTitle: String(localized: "Pending", comment: "ViewTitle of TransactionList"), scopeInfo: balance.scopeInfo, transactions: pendingTransactions, @@ -77,10 +77,12 @@ struct BalancesPendingRowV: View { } // BalancesPendingRowV // MARK: - -struct BalancesPendingRowV_Previews: PreviewProvider { +#if DEBUG +fileprivate struct BalancesPendingRowV_Previews: PreviewProvider { @MainActor - fileprivate struct BindingViewContainer: View { + struct BindingViewContainer: View { @State private var pendingTransactions: [Transaction] = [] + @State private var currencyInfoD: CurrencyInfo = CurrencyInfo.zero(DEMOCURRENCY) var body: some View { let flags: [BalanceFlag] = [.incomingConfirmation] @@ -92,7 +94,7 @@ struct BalancesPendingRowV_Previews: PreviewProvider { flags: flags) BalancesPendingRowV(//symLog: nil, stack: CallStack("Preview"), - currencyInfo: CurrencyInfo.zero(DEMOCURRENCY), + currencyInfo: $currencyInfoD, balance: balance, pendingTransactions: $pendingTransactions, reloadPending: {stack in }, @@ -109,3 +111,4 @@ struct BalancesPendingRowV_Previews: PreviewProvider { } } } +#endif diff --git a/TalerWallet1/Views/Balances/BalancesSectionView.swift b/TalerWallet1/Views/Balances/BalancesSectionView.swift @@ -83,7 +83,7 @@ extension BalancesSectionView: View { let balanceDest = LazyView { TransactionsListView(stack: stack.push("\(Self.className())()"), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, navTitle: String(localized: "Transactions", comment: "ViewTitle of TransactionList"), scopeInfo: scopeInfo, transactions: completedTransactions, @@ -99,7 +99,7 @@ extension BalancesSectionView: View { // .listRowSeparator(.hidden) } BalanceCellV(stack: stack.push("BalanceCell"), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, amount: balance.available, // sizeCategory: sizeCategory, // rowAction: { buttonSelected = 3 }, // trigger TransactionList NavigationLink @@ -108,7 +108,7 @@ extension BalancesSectionView: View { // .border(.red) SendRequestV(stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, amountAvailable: balance.available, amountToTransfer: $amountToTransfer, summary: $summary, @@ -129,7 +129,7 @@ extension BalancesSectionView: View { if pendingTransactions.count > 0 { BalancesPendingRowV(//symLog: symLog, stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, balance: balance, pendingTransactions: $pendingTransactions, reloadPending: reloadPending, @@ -162,7 +162,7 @@ extension BalancesSectionView: View { .listRowSeparator(.hidden) } DepositWithdrawV(stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, // scopeInfo: balance.scopeInfo, amountAvailable: balance.available, amountToTransfer: $amountToTransfer) // does still have the wrong currency @@ -198,7 +198,7 @@ extension BalancesSectionView: View { let threeTransactions = Array(slice) TransactionsArraySliceV(symLog: symLog, stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, scopeInfo: scopeInfo, transactions: threeTransactions, reloadOneAction: reloadOneAction) diff --git a/TalerWallet1/Views/Balances/PendingRowView.swift b/TalerWallet1/Views/Balances/PendingRowView.swift @@ -10,7 +10,7 @@ import taler_swift /// This view shows a pending transaction row in a currency section struct PendingRowView: View { - let currencyInfo: CurrencyInfo + @Binding var currencyInfo: CurrencyInfo let amount: Amount let incoming: Bool let shouldConfirm: Bool @@ -37,7 +37,7 @@ struct PendingRowView: View { let outTitle = minimalistic ? outTitle0 : outTitle1 let pendingTitle = incoming ? inTitle : outTitle - let amountText = AmountV(currencyInfo, amount, isNegative: !incoming) + let amountText = AmountV($currencyInfo, amount, isNegative: !incoming) .foregroundColor(pendingColor) // this is the default view for iOS 15 @@ -72,13 +72,15 @@ struct PendingRowView: View { #if DEBUG @MainActor fileprivate struct Preview_Content: View { + @State private var currencyInfoD: CurrencyInfo = CurrencyInfo.zero(DEMOCURRENCY) + @State private var currencyInfoT: CurrencyInfo = CurrencyInfo.zero(TESTCURRENCY) var body: some View { let test = Amount(currency: TESTCURRENCY, cent: 123) let demo = Amount(currency: DEMOCURRENCY, cent: 123456) List { - PendingRowView(currencyInfo: CurrencyInfo.zero(TESTCURRENCY), + PendingRowView(currencyInfo: $currencyInfoD, amount: test, incoming: true, shouldConfirm: true, needsKYC: false) - PendingRowView(currencyInfo: CurrencyInfo.zero(DEMOCURRENCY), + PendingRowView(currencyInfo: $currencyInfoT, amount: demo, incoming: false, shouldConfirm: false, needsKYC: true) } } diff --git a/TalerWallet1/Views/Balances/SendRequestV.swift b/TalerWallet1/Views/Balances/SendRequestV.swift @@ -12,7 +12,7 @@ import SymLog struct SendRequestV: View { private let symLog = SymLogV(0) let stack: CallStack - let currencyInfo: CurrencyInfo + @Binding var currencyInfo: CurrencyInfo let amountAvailable: Amount // let currency: String // this is the currency to be used @Binding var amountToTransfer: Amount // does still have the wrong currency @@ -60,7 +60,7 @@ struct SendRequestV: View { let requTitle = minimalistic ? requTitle0 : requTitle1 let sendDest = LazyView { SendAmount(stack: stack.push("\(Self.className())()"), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, amountAvailable: amountAvailable, amountToTransfer: $amountToTransfer, // with correct currency summary: $summary, @@ -69,6 +69,7 @@ struct SendRequestV: View { } let requestDest = LazyView { RequestPayment(stack: stack.push("\(Self.className())()"), + currencyInfo: $currencyInfo, amountToTransfer: $amountToTransfer, // with correct currency summary: $summary, scopeInfo: scope, diff --git a/TalerWallet1/Views/Banking/DepositAmountV.swift b/TalerWallet1/Views/Banking/DepositAmountV.swift @@ -13,7 +13,7 @@ import SymLog struct DepositAmountV: View { private let symLog = SymLogV(0) let stack: CallStack - let currencyInfo: CurrencyInfo + @Binding var currencyInfo: CurrencyInfo // let exchangeBaseUrl: String let paytoUri: String? @@ -105,7 +105,7 @@ struct DepositAmountV: View { Text("Available:\t\(available)") .talerFont(.title3) .padding(.bottom, 2) - CurrencyInputView(currencyInfo: currencyInfo, + CurrencyInputView(currencyInfo: $currencyInfo, amount: $amountToTransfer, available: nil, // amountAvailable, title: minimalistic ? String(localized: "Amount:") diff --git a/TalerWallet1/Views/Banking/DepositIbanV.swift b/TalerWallet1/Views/Banking/DepositIbanV.swift @@ -13,7 +13,7 @@ import SymLog struct DepositIbanV: View { private let symLog = SymLogV(0) let stack: CallStack - let currencyInfo: CurrencyInfo + @Binding var currencyInfo: CurrencyInfo let feeLabel: String? let feeIsNotZero: Bool? // nil = no fees at all, false = no fee for this tx let amountAvailable: Amount? @@ -54,7 +54,7 @@ struct DepositIbanV: View { #endif let destination = LazyView { DepositAmountV(stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, paytoUri: paytoUri, // exchangeBaseUrl: baseURL, amountAvailable: amountAvailable, diff --git a/TalerWallet1/Views/Banking/DepositWithdrawV.swift b/TalerWallet1/Views/Banking/DepositWithdrawV.swift @@ -12,7 +12,7 @@ import SymLog struct DepositWithdrawV: View { private let symLog = SymLogV(0) let stack: CallStack - let currencyInfo: CurrencyInfo + @Binding var currencyInfo: CurrencyInfo let amountAvailable: Amount? // let currency: String // this is the currency to be used @Binding var amountToTransfer: Amount // does still have the wrong currency @@ -55,7 +55,7 @@ struct DepositWithdrawV: View { let withdrawTitle = minimalistic ? withdrawTitle0 : withdrawTitle1 let depositDest = LazyView { DepositIbanV(stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, feeLabel: nil, feeIsNotZero: nil, amountAvailable: amountAvailable, @@ -65,6 +65,7 @@ struct DepositWithdrawV: View { } let manualWithdrawDest = LazyView { ManualWithdraw(stack: stack.push(), + currencyInfo: $currencyInfo, isSheet: false, scopeInfo: scope, exchange: $myExchange, diff --git a/TalerWallet1/Views/Banking/ExchangeRowView.swift b/TalerWallet1/Views/Banking/ExchangeRowView.swift @@ -12,7 +12,7 @@ import SymLog struct ExchangeRowView: View { private let symLog = SymLogV(0) let stack: CallStack - let currencyInfo: CurrencyInfo + @Binding var currencyInfo: CurrencyInfo let exchange: Exchange // @Binding var depositIBAN: String // @Binding var accountHolder: String @@ -54,7 +54,7 @@ struct ExchangeRowView: View { .listRowSeparator(.hidden) DepositWithdrawV(stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, // scopeInfo: exchange.scopeInfo, amountAvailable: amountAvailable, amountToTransfer: $amountToTransfer) @@ -75,45 +75,48 @@ struct ExchangeRowView: View { } // MARK: - #if DEBUG -fileprivate struct ExchangeRow_Container : View { - @State private var amountToPreview = Amount(currency: LONGCURRENCY, cent: 1234) - @State private var depositIBAN = "DE1234567890" - @State private var accountHolder = "Marc Stibane" +fileprivate struct ExchangeRow_Previews: PreviewProvider { + @MainActor + struct BindingViewContainer : View { + @State private var amountToPreview = Amount(currency: LONGCURRENCY, cent: 1234) + @State private var depositIBAN = "DE1234567890" + @State private var accountHolder = "Marc Stibane" + @State private var currencyInfoL: CurrencyInfo = CurrencyInfo.zero(LONGCURRENCY) // let amount = Amount(currency: LONGCURRENCY, cent: 123456) - var body: some View { - let scopeInfo = ScopeInfo(type: .exchange, currency: LONGCURRENCY) - let exchange1 = Exchange(exchangeBaseUrl: ARS_AGE_EXCHANGE, - masterPub: "masterPub", - scopeInfo: scopeInfo, - paytoUris: [], - tosStatus: .pending, - exchangeEntryStatus: .preset, - exchangeUpdateStatus: .initial, - ageRestrictionOptions: [12,16]) - let exchange2 = Exchange(exchangeBaseUrl: ARS_EXP_EXCHANGE, - masterPub: "masterPub", - scopeInfo: scopeInfo, - paytoUris: [], - tosStatus: .proposed, - exchangeEntryStatus: .ephemeral, - exchangeUpdateStatus: .ready, - ageRestrictionOptions: []) - ExchangeRowView(stack: CallStack("Preview"), - currencyInfo: CurrencyInfo.zero(LONGCURRENCY), - exchange: exchange1, - amountAvailable: Amount(currency: LONGCURRENCY, cent: 5000), // 50,00 - currency: LONGCURRENCY, -// depositIBAN: $depositIBAN, -// accountHolder: $accountHolder, - amountToTransfer: $amountToPreview) + var body: some View { + let scopeInfo = ScopeInfo(type: .exchange, currency: LONGCURRENCY) + let exchange1 = Exchange(exchangeBaseUrl: ARS_AGE_EXCHANGE, + masterPub: "masterPub", + scopeInfo: scopeInfo, + paytoUris: [], + tosStatus: .pending, + exchangeEntryStatus: .preset, + exchangeUpdateStatus: .initial, + ageRestrictionOptions: [12,16]) + let exchange2 = Exchange(exchangeBaseUrl: ARS_EXP_EXCHANGE, + masterPub: "masterPub", + scopeInfo: scopeInfo, + paytoUris: [], + tosStatus: .proposed, + exchangeEntryStatus: .ephemeral, + exchangeUpdateStatus: .ready, + ageRestrictionOptions: []) + ExchangeRowView(stack: CallStack("Preview"), + currencyInfo: $currencyInfoL, + exchange: exchange1, + amountAvailable: Amount(currency: LONGCURRENCY, cent: 5000), // 50,00 + currency: LONGCURRENCY, +// depositIBAN: $depositIBAN, +// accountHolder: $accountHolder, + amountToTransfer: $amountToPreview) + } } -} -fileprivate struct ExchangeRow_Previews: PreviewProvider { + @MainActor static var previews: some View { List { - ExchangeRow_Container() + BindingViewContainer() } } } diff --git a/TalerWallet1/Views/Banking/ExchangeSectionView.swift b/TalerWallet1/Views/Banking/ExchangeSectionView.swift @@ -47,12 +47,12 @@ struct ExchangeSectionView: View { #endif let scopeInfo = exchange.scopeInfo let currency = scopeInfo.currency - let currencyInfo = controller.info(for: currency, controller.currencyTicker) - let currencyName = currencyInfo.scope.currency +// let currencyInfo = controller.info(for: currency, controller.currencyTicker) +// let currencyName = currencyInfo.scope.currency Section { // ForEach(exchanges) { exchange in ExchangeRowView(stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, exchange: exchange, amountAvailable: amountAvailable(exchange, currency: currency), // depositIBAN: $depositIBAN, @@ -79,6 +79,10 @@ struct ExchangeSectionView: View { BarGraphHeader(stack: stack.push(), scopeInfo: scopeInfo, currencyName: currencyName, shouldReloadBalances: $shouldReloadBalances) } + .task(id: controller.currencyTicker) { + currencyInfo = controller.info(for: currency, controller.currencyTicker) + currencyName = currencyInfo.scope.currency + } } } // MARK: - diff --git a/TalerWallet1/Views/Banking/ManualWithdraw.swift b/TalerWallet1/Views/Banking/ManualWithdraw.swift @@ -14,6 +14,7 @@ import SymLog struct ManualWithdraw: View { private let symLog = SymLogV(0) let stack: CallStack + @Binding var currencyInfo: CurrencyInfo let isSheet: Bool // let exchangeBaseUrl: String let scopeInfo: ScopeInfo? @@ -61,7 +62,7 @@ struct ManualWithdraw: View { // let _ = print(selectedAge, restrictAge) let destination = LazyView { ManualWithdrawDone(stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, exchange: exchange, amountToTransfer: amountToTransfer) // restrictAge: restrictAge) @@ -73,14 +74,14 @@ struct ManualWithdraw: View { .multilineTextAlignment(.center) .talerFont(.body) if tosAccepted { - CurrencyInputView(currencyInfo: currencyInfo, + CurrencyInputView(currencyInfo: $currencyInfo, amount: $amountToTransfer, available: nil, title: minimalistic ? String(localized: "Amount:") : String(localized: "Amount to withdraw:"), shortcutAction: nil) .padding(.top) - QuiteSomeCoins(currencyInfo: currencyInfo, + QuiteSomeCoins(currencyInfo: $currencyInfo, currency: currency, coinData: coinData, shouldShowFee: true, // TODO: set to false if we never charge withdrawal fees diff --git a/TalerWallet1/Views/Banking/ManualWithdrawDone.swift b/TalerWallet1/Views/Banking/ManualWithdrawDone.swift @@ -12,7 +12,7 @@ import SymLog struct ManualWithdrawDone: View { private let symLog = SymLogV(0) let stack: CallStack - let currencyInfo: CurrencyInfo + @Binding var currencyInfo: CurrencyInfo let exchange: Exchange let amountToTransfer: Amount @@ -37,7 +37,7 @@ struct ManualWithdrawDone: View { Group { if let transactionId { TransactionSummaryV(stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, transactionId: transactionId, reloadAction: reloadOneAction, navTitle: navTitle, @@ -74,8 +74,11 @@ struct ManualWithdrawDone: View { // MARK: - #if DEBUG -struct ManualWithdrawDone_Container : View { - @State private var amountToTransfer = Amount(currency: LONGCURRENCY, cent: 510) +fileprivate struct ManualWithdrawDone_Previews: PreviewProvider { + @MainActor + struct BindingViewContainer : View { + @State private var amountToTransfer = Amount(currency: LONGCURRENCY, cent: 510) + @State private var currencyInfoD: CurrencyInfo = CurrencyInfo.zero(DEMOCURRENCY) var body: some View { let scopeInfo = ScopeInfo(type: .exchange, currency: LONGCURRENCY) @@ -88,15 +91,14 @@ struct ManualWithdrawDone_Container : View { exchangeUpdateStatus: .initial, ageRestrictionOptions: []) ManualWithdrawDone(stack: CallStack("Preview"), - currencyInfo: CurrencyInfo.zero(DEMOCURRENCY), + currencyInfo: $currencyInfoD, exchange: exchange, amountToTransfer: amountToTransfer) } } -struct ManualWithdrawDone_Previews: PreviewProvider { static var previews: some View { - ManualWithdrawDone_Container() + BindingViewContainer() } } #endif diff --git a/TalerWallet1/Views/Banking/QuiteSomeCoins.swift b/TalerWallet1/Views/Banking/QuiteSomeCoins.swift @@ -60,7 +60,7 @@ extension CoinData { // MARK: - struct QuiteSomeCoins: View { private let symLog = SymLogV(0) - let currencyInfo: CurrencyInfo + @Binding var currencyInfo: CurrencyInfo let currency: String let coinData: CoinData let shouldShowFee: Bool diff --git a/TalerWallet1/Views/HelperViews/AmountInputV.swift b/TalerWallet1/Views/HelperViews/AmountInputV.swift @@ -18,7 +18,7 @@ struct ComputeFeeResult { struct AmountInputV: View { private let symLog = SymLogV(0) let stack: CallStack - let currencyInfo: CurrencyInfo + @Binding var currencyInfo: CurrencyInfo // the scanned URL let url: URL? @@ -62,7 +62,7 @@ struct AmountInputV: View { var body: some View { let currency = amountToTransfer.currencyStr - let currencyInfo = controller.info(for: currency, controller.currencyTicker) +// let currencyInfo = controller.info(for: currency, controller.currencyTicker) let insufficientLabel = String(localized: "You don't have enough \(currency).") let available = amountAvailable?.formatted(currencyInfo, isNegative: false) ?? nil let flags = checkAvailable(amount: amountToTransfer) @@ -79,7 +79,7 @@ struct AmountInputV: View { .padding(.bottom, 2) // .accessibility(sortPriority: 3) } // available - CurrencyInputView(currencyInfo: currencyInfo, + CurrencyInputView(currencyInfo: $currencyInfo, amount: $amountToTransfer, available: amountAvailable, title: amountLabel, diff --git a/TalerWallet1/Views/HelperViews/AmountRowV.swift b/TalerWallet1/Views/HelperViews/AmountRowV.swift @@ -11,7 +11,7 @@ import taler_swift // Title and Amount struct AmountRowV: View { let stack: CallStack? - let currencyInfo: CurrencyInfo + @Binding var currencyInfo: CurrencyInfo let title: String let amount: Amount let isNegative: Bool // if true, show a "-" before the amount @@ -23,7 +23,7 @@ struct AmountRowV: View { .multilineTextAlignment(.leading) .talerFont(.body) let amountV = AmountV(stack: stack?.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, amount: amount, isNegative: isNegative, large: large) @@ -62,9 +62,9 @@ struct AmountRowV: View { } } extension AmountRowV { - init(_ currencyInfo: CurrencyInfo, title: String, amount: Amount, isNegative: Bool, color: Color) { + init(_ currencyInfo: Binding<CurrencyInfo>, title: String, amount: Amount, isNegative: Bool, color: Color) { self.stack = nil - self.currencyInfo = currencyInfo + self._currencyInfo = currencyInfo self.title = title self.amount = amount self.isNegative = isNegative @@ -82,14 +82,25 @@ fileprivate func talerFromStr(_ from: String) -> Amount { return Amount(currency: "Taler", cent: 480) } } -#Preview { - List { + +#if DEBUG +@MainActor +fileprivate struct BindingViewContainer: View { + @State private var currencyInfoD: CurrencyInfo = CurrencyInfo.zero(DEMOCURRENCY) + var body: some View { let fee = Amount(currency: "Taler", cent: 20) let currencyInfo = CurrencyInfo.zero("Taler") - AmountRowV(stack: nil, currencyInfo: currencyInfo, title: "Fee", amount: fee, isNegative: true, color: Color("Outgoing"), large: false) + AmountRowV(stack: nil, currencyInfo: $currencyInfoD, title: "Fee", amount: fee, isNegative: true, color: Color("Outgoing"), large: false) let cents = Amount(currency: "Taler", cent: 480) - AmountRowV(currencyInfo, title: "Cents", amount: cents, isNegative: false, color: Color("Incoming")) + AmountRowV($currencyInfoD, title: "Cents", amount: cents, isNegative: false, color: Color("Incoming")) let amount = talerFromStr("Taler:4.80") - AmountRowV(currencyInfo, title: "Chosen amount to withdraw", amount: amount, isNegative: false, color: Color("Incoming")) + AmountRowV($currencyInfoD, title: "Chosen amount to withdraw", amount: amount, isNegative: false, color: Color("Incoming")) + } +} + +#Preview { + List { + BindingViewContainer() } } +#endif diff --git a/TalerWallet1/Views/HelperViews/AmountV.swift b/TalerWallet1/Views/HelperViews/AmountV.swift @@ -10,7 +10,7 @@ import taler_swift struct AmountV: View { let stack: CallStack? - let currencyInfo: CurrencyInfo + @Binding var currencyInfo: CurrencyInfo let amount: Amount let isNegative: Bool // if true, show a "-" before the amount let large: Bool // set to false for QR or IBAN @@ -27,9 +27,9 @@ struct AmountV: View { } } extension AmountV { - init(_ currencyInfo: CurrencyInfo, _ amount: Amount, isNegative: Bool) { + init(_ currencyInfo: Binding<CurrencyInfo>, _ amount: Amount, isNegative: Bool) { self.stack = nil - self.currencyInfo = currencyInfo + self._currencyInfo = currencyInfo self.amount = amount self.isNegative = isNegative self.large = false diff --git a/TalerWallet1/Views/HelperViews/CurrencyField.swift b/TalerWallet1/Views/HelperViews/CurrencyField.swift @@ -30,7 +30,7 @@ import SymLog @MainActor struct CurrencyField: View { private let symLog = SymLogV(0) - let currencyInfo: CurrencyInfo + @Binding var currencyInfo: CurrencyInfo @Binding var amount: Amount // the `value´ private var currencyFieldRepresentable: CurrencyTextfieldRepresentable! = nil @@ -47,11 +47,11 @@ struct CurrencyField: View { currencyFieldRepresentable.updateText(amount: amount) } - public init(currencyInfo: CurrencyInfo, amount: Binding<Amount>) { + public init(_ currencyInfo: Binding<CurrencyInfo>, amount: Binding<Amount>) { self._amount = amount - self.currencyInfo = currencyInfo + self._currencyInfo = currencyInfo self.currencyFieldRepresentable = - CurrencyTextfieldRepresentable(currencyInfo: currencyInfo, + CurrencyTextfieldRepresentable(currencyInfo: self.$currencyInfo, amount: self.$amount) } @@ -93,7 +93,7 @@ class NoCaretTextField: UITextField { // MARK: - @MainActor struct CurrencyTextfieldRepresentable: UIViewRepresentable { - let currencyInfo: CurrencyInfo + @Binding var currencyInfo: CurrencyInfo @Binding var amount: Amount private let textField = NoCaretTextField(frame: .zero) diff --git a/TalerWallet1/Views/HelperViews/CurrencyInputView.swift b/TalerWallet1/Views/HelperViews/CurrencyInputView.swift @@ -11,7 +11,7 @@ import taler_swift fileprivate let shortcuts = [5000,2500,1000,500] // TODO: adapt for ¥ struct ShortcutButton: View { - let currencyInfo: CurrencyInfo + @Binding var currencyInfo: CurrencyInfo let currency: String let currencyField: CurrencyField let shortcut: Int @@ -19,7 +19,7 @@ struct ShortcutButton: View { let action: (Int, CurrencyField) -> Void func makeButton(with newShortcut: Int) -> ShortcutButton { - ShortcutButton(currencyInfo: currencyInfo, + ShortcutButton(currencyInfo: $currencyInfo, currency: currency, currencyField: currencyField, shortcut: newShortcut, @@ -55,7 +55,7 @@ struct ShortcutButton: View { } // MARK: - struct CurrencyInputView: View { - let currencyInfo: CurrencyInfo + @Binding var currencyInfo: CurrencyInfo @Binding var amount: Amount // the `value´ let available: Amount? let title: String @@ -81,7 +81,7 @@ struct CurrencyInputView: View { var body: some View { let currency = amount.currencyStr - let currencyField = CurrencyField(currencyInfo: currencyInfo, amount: $amount) + let currencyField = CurrencyField($currencyInfo, amount: $amount) VStack (alignment: .center) { // center shortcut buttons Text(title) .frame(maxWidth: .infinity, alignment: .leading) @@ -102,7 +102,7 @@ struct CurrencyInputView: View { showKeyboard += 1 } if #available(iOS 16.0, *) { - let shortcutButton = ShortcutButton(currencyInfo: currencyInfo, + let shortcutButton = ShortcutButton(currencyInfo: $currencyInfo, currency: currency, currencyField: currencyField, shortcut: 0, @@ -169,10 +169,9 @@ fileprivate struct Previews: PreviewProvider { @MainActor struct StateContainer: View { @State var amountToTransfer = Amount(currency: LONGCURRENCY, cent: 0) + @State private var currencyInfoL: CurrencyInfo = CurrencyInfo.zero(LONGCURRENCY) var body: some View { - let currencyInfo = CurrencyInfo.zero(LONGCURRENCY) - - CurrencyInputView(currencyInfo: currencyInfo, + CurrencyInputView(currencyInfo: $currencyInfoL, amount: $amountToTransfer, available: Amount(currency: LONGCURRENCY, cent: 2000), title: "Amount to withdraw:", diff --git a/TalerWallet1/Views/HelperViews/SubjectInputV.swift b/TalerWallet1/Views/HelperViews/SubjectInputV.swift @@ -12,7 +12,7 @@ import SymLog struct SubjectInputV<TargetView: View>: View { private let symLog = SymLogV(0) let stack: CallStack - let currencyInfo: CurrencyInfo + @Binding var currencyInfo: CurrencyInfo // the scanned URL let url: URL? let amountAvailable: Amount? // TODO: GetMaxPeerPushAmount diff --git a/TalerWallet1/Views/Overview/OverviewRowV.swift b/TalerWallet1/Views/Overview/OverviewRowV.swift @@ -10,7 +10,7 @@ import taler_swift struct CurrenciesCell: View { let stack: CallStack - let currencyInfo: CurrencyInfo + @Binding var currencyInfo: CurrencyInfo let amount: Amount let sizeCategory: ContentSizeCategory let rowAction: () -> Void @@ -23,7 +23,7 @@ struct CurrenciesCell: View { /// Renders the Balance button. "Balance" leading, amountStr trailing. If it doesn't fit in one row then /// amount (trailing) goes underneath "Balance" (leading). var body: some View { - let amountV = AmountV(stack: stack.push(), currencyInfo: currencyInfo, amount: amount, isNegative: false, large: true) + let amountV = AmountV(stack: stack.push(), currencyInfo: $currencyInfo, amount: amount, isNegative: false, large: true) .foregroundColor(.primary) let hLayout = amountV .frame(maxWidth: .infinity, alignment: .trailing) @@ -65,7 +65,7 @@ struct CurrenciesCell: View { /// [Send Money] [Request Payment] struct OverviewRowV: View { let stack: CallStack - let currencyInfo: CurrencyInfo + @Binding var currencyInfo: CurrencyInfo let amount: Amount let sendAction: () -> Void let recvAction: () -> Void @@ -80,7 +80,7 @@ struct OverviewRowV: View { var body: some View { VStack (alignment: .trailing, spacing: 6) { CurrenciesCell(stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, amount: amount, sizeCategory: sizeCategory, rowAction: rowAction, @@ -94,18 +94,19 @@ struct OverviewRowV: View { struct OverviewRowV_Previews: PreviewProvider { @MainActor struct StateContainer: View { + @State private var currencyInfoD: CurrencyInfo = CurrencyInfo.zero(DEMOCURRENCY) + @State private var currencyInfoT: CurrencyInfo = CurrencyInfo.zero(TESTCURRENCY) + var body: some View { let test = Amount(currency: TESTCURRENCY, cent: 123) let demo = Amount(currency: DEMOCURRENCY, cent: 123456) List { Section { - let currencyInfo = CurrencyInfo.zero(DEMOCURRENCY) - OverviewRowV(stack: CallStack("Preview"), currencyInfo: currencyInfo, amount: demo, + OverviewRowV(stack: CallStack("Preview"), currencyInfo: $currencyInfoD, amount: demo, sendAction: {}, recvAction: {}, rowAction: {}, balanceDest: nil) } - let currencyInfo = CurrencyInfo.zero(TESTCURRENCY) - OverviewRowV(stack: CallStack("Preview"), currencyInfo: currencyInfo, amount: test, + OverviewRowV(stack: CallStack("Preview"), currencyInfo: $currencyInfoT, amount: test, sendAction: {}, recvAction: {}, rowAction: {}, balanceDest: nil) } } diff --git a/TalerWallet1/Views/Overview/OverviewSectionV.swift b/TalerWallet1/Views/Overview/OverviewSectionV.swift @@ -82,7 +82,7 @@ extension OverviewSectionV: View { } CurrenciesNavigationLinksV(symLog: symLog, stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, balance: balance, amountToTransfer: $amountToTransfer, // does still have the wrong currency summary: $summary, @@ -92,7 +92,7 @@ extension OverviewSectionV: View { if pendingTransactions.count > 0 { BalancesPendingRowV(//symLog: symLog, stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, balance: balance, pendingTransactions: $pendingTransactions, reloadPending: reloadPending, @@ -103,6 +103,10 @@ extension OverviewSectionV: View { BarGraphHeader(stack: stack.push(), scopeInfo: scopeInfo, currencyName: currencyName, shouldReloadBalances: $shouldReloadBalances) }.id(sectionID) + .task(id: controller.currencyTicker) { + currencyInfo = controller.info(for: currency, controller.currencyTicker) + currencyName = currencyInfo.scope.currency + } .task(id: shouldReloadBalances + 1_000_000) { // if shownSectionID != sectionID { symLog.log(".task for BalancesSectionView - reload Transactions") @@ -125,7 +129,7 @@ extension OverviewSectionV: View { let threeTransactions = Array(slice) TransactionsArraySliceV(symLog: symLog, stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, scopeInfo: scopeInfo, transactions: threeTransactions, reloadOneAction: reloadOneAction) @@ -146,7 +150,7 @@ extension OverviewSectionV: View { fileprivate struct CurrenciesNavigationLinksV: View { let symLog: SymLogV? let stack: CallStack - let currencyInfo: CurrencyInfo + @Binding var currencyInfo: CurrencyInfo let balance: Balance // let sectionCount: Int @@ -180,7 +184,7 @@ fileprivate struct CurrenciesNavigationLinksV: View { HStack(spacing: 0) { let balanceDest = LazyView { TransactionsListView(stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, navTitle: String(localized: "Transactions", comment: "ViewTitle of TransactionList"), scopeInfo: scopeInfo, transactions: completedTransactions, @@ -191,7 +195,7 @@ fileprivate struct CurrenciesNavigationLinksV: View { { EmptyView() }.frame(width: 0).opacity(0).hidden() // TransactionsListView OverviewRowV(stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, amount: balance.available, sendAction: { selectAndUpdate(1) // trigger SendAmount NavigationLink diff --git a/TalerWallet1/Views/Peer2peer/P2PReadyV.swift b/TalerWallet1/Views/Peer2peer/P2PReadyV.swift @@ -13,7 +13,7 @@ import SymLog struct P2PReadyV: View { private let symLog = SymLogV(0) let stack: CallStack - let currencyInfo: CurrencyInfo + @Binding var currencyInfo: CurrencyInfo let summary: String let expireDays: UInt let amountToSend: Bool @@ -43,7 +43,7 @@ struct P2PReadyV: View { Group { if let transactionId { TransactionSummaryV(stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, transactionId: transactionId, reloadAction: reloadOneAction, navTitle: navTitle, diff --git a/TalerWallet1/Views/Peer2peer/P2PSubjectV.swift b/TalerWallet1/Views/Peer2peer/P2PSubjectV.swift @@ -21,7 +21,7 @@ func p2pFee(ppCheck: CheckPeerPushDebitResponse) -> Amount? { struct P2PSubjectV: View { private let symLog = SymLogV(0) let stack: CallStack - let currencyInfo: CurrencyInfo + @Binding var currencyInfo: CurrencyInfo let feeLabel: String? let feeIsNotZero: Bool? // nil = no fees at all, false = no fee for this tx let amountToSend: Bool @@ -113,7 +113,7 @@ struct P2PSubjectV: View { let disabled = (expireDays == 0) || (summary.count < 1) // TODO: check amountAvailable NavigationLink(destination: LazyView { P2PReadyV(stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, summary: summary, expireDays: expireDays, amountToSend: amountToSend, diff --git a/TalerWallet1/Views/Peer2peer/RequestPayment.swift b/TalerWallet1/Views/Peer2peer/RequestPayment.swift @@ -10,6 +10,7 @@ import SymLog struct RequestPayment: View { private let symLog = SymLogV(0) let stack: CallStack + @Binding var currencyInfo: CurrencyInfo @Binding var amountToTransfer: Amount @Binding var summary: String @@ -69,7 +70,7 @@ struct RequestPayment: View { let _ = symLog.vlog() // just to get the # to compare it with .onAppear & onDisappear #endif let currency = amountToTransfer.currencyStr - let currencyInfo = controller.info(for: currency, controller.currencyTicker) +// let currencyInfo = controller.info(for: currency, controller.currencyTicker) let currencySymbol = currencyInfo.specs.altUnitNames?[0] ?? currency let navTitle = String(localized: "NavTitle_Request_Currency", defaultValue: "Request \(currencySymbol)", @@ -80,7 +81,7 @@ struct RequestPayment: View { let inputDestination = LazyView { P2PSubjectV(stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, feeLabel: coinData.feeLabel(currencyInfo), feeIsNotZero: feeIsNotZero(), amountToSend: false, @@ -90,7 +91,7 @@ struct RequestPayment: View { } let shortcutDestination = LazyView { P2PSubjectV(stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, feeLabel: nil, feeIsNotZero: feeIsNotZero(), amountToSend: false, @@ -104,7 +105,7 @@ struct RequestPayment: View { let amountLabel = minimalistic ? String(localized: "Amount:") : String(localized: "Amount to request:") AmountInputV(stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, url: nil, amountAvailable: nil, amountToTransfer: $amountToTransfer, diff --git a/TalerWallet1/Views/Peer2peer/SendAmount.swift b/TalerWallet1/Views/Peer2peer/SendAmount.swift @@ -13,7 +13,7 @@ import SymLog struct SendAmount: View { private let symLog = SymLogV() let stack: CallStack - let currencyInfo: CurrencyInfo + @Binding var currencyInfo: CurrencyInfo let amountAvailable: Amount // TODO: GetMaxPeerPushAmount @Binding var amountToTransfer: Amount @@ -121,7 +121,7 @@ struct SendAmount: View { let inputDestination = LazyView { P2PSubjectV(stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, feeLabel: feeLabel(feeStr), feeIsNotZero: feeIsNotZero(), amountToSend: true, @@ -131,7 +131,7 @@ struct SendAmount: View { } let shortcutDestination = LazyView { P2PSubjectV(stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, feeLabel: nil, feeIsNotZero: feeIsNotZero(), amountToSend: true, @@ -144,7 +144,7 @@ struct SendAmount: View { let amountLabel = minimalistic ? String(localized: "Amount:") : String(localized: "Amount to send:") AmountInputV(stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, url: nil, amountAvailable: amountAvailable, amountToTransfer: $amountToTransfer, @@ -219,6 +219,7 @@ struct SendAmount: View { fileprivate struct Preview_Content: View { @State private var amountToPreview = Amount(currency: LONGCURRENCY, cent: 510) @State private var summary: String = "" + @State private var currencyInfoL: CurrencyInfo = CurrencyInfo.zero(LONGCURRENCY) private func checkCameraAvailable() -> Void { // Open Camera when QR-Button was tapped @@ -235,7 +236,7 @@ fileprivate struct Preview_Content: View { exchangeUpdateStatus: .ready, ageRestrictionOptions: []) SendAmount(stack: CallStack("Preview"), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfoL, amountAvailable: amount, amountToTransfer: $amountToPreview, summary: $summary, diff --git a/TalerWallet1/Views/Sheets/P2P_Sheets/P2pPayURIView.swift b/TalerWallet1/Views/Sheets/P2P_Sheets/P2pPayURIView.swift @@ -11,12 +11,12 @@ import SymLog struct P2pPayURIView: View { private let symLog = SymLogV(0) let stack: CallStack - let currencyInfo: CurrencyInfo // the scanned URL let url: URL @EnvironmentObject private var model: WalletModel + @EnvironmentObject private var controller: Controller @Environment(\.colorScheme) private var colorScheme @Environment(\.colorSchemeContrast) private var colorSchemeContrast @AppStorage("myListStyle") var myListStyle: MyListStyle = .automatic @@ -35,7 +35,7 @@ struct P2pPayURIView: View { let currency = raw.currencyStr let fee = try! Amount.diff(raw, effective) ThreeAmountsSection(stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, topTitle: String(localized: "Amount to pay:"), topAbbrev: String(localized: "Pay:", comment: "mini"), topAmount: raw, fee: fee, @@ -59,6 +59,11 @@ struct P2pPayURIView: View { } .listStyle(myListStyle.style).anyView .navigationTitle(navTitle) + .task(id: controller.currencyTicker) { + let currency = peerPullDebitResponse.amountRaw.currencyStr + currencyInfo = controller.info(for: currency, controller.currencyTicker) +// currencyName = currencyInfo.scope.currency + } NavigationLink(destination: LazyView { P2pAcceptDone(stack: stack.push(), diff --git a/TalerWallet1/Views/Sheets/P2P_Sheets/P2pReceiveURIView.swift b/TalerWallet1/Views/Sheets/P2P_Sheets/P2pReceiveURIView.swift @@ -11,7 +11,6 @@ import SymLog struct P2pReceiveURIView: View { private let symLog = SymLogV(0) let stack: CallStack - let currencyInfo: CurrencyInfo // the scanned URL let url: URL @@ -45,7 +44,7 @@ struct P2pReceiveURIView: View { let currency = raw.currencyStr let fee = try! Amount.diff(raw, effective) ThreeAmountsSection(stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, topTitle: String(localized: "Gross Amount to receive:"), topAbbrev: String(localized: "Receive gross:", comment: "mini"), topAmount: raw, fee: fee, @@ -69,6 +68,11 @@ struct P2pReceiveURIView: View { } .listStyle(myListStyle.style).anyView .navigationTitle(navTitle) + .task(id: controller.currencyTicker) { + let currency = peerPushCreditResponse.amountRaw.currencyStr + currencyInfo = controller.info(for: currency, controller.currencyTicker) +// currencyName = currencyInfo.scope.currency + } if tosAccepted { NavigationLink(destination: LazyView { P2pAcceptDone(stack: stack.push(), diff --git a/TalerWallet1/Views/Sheets/Payment/PayTemplateV.swift b/TalerWallet1/Views/Sheets/Payment/PayTemplateV.swift @@ -81,13 +81,12 @@ struct PayTemplateV: View { var body: some View { if let templateContract { // preparePayResult - let currency = templateContract.currency ?? templateContract.amount?.currencyStr ?? "UNKNOWN" - let currencyInfo = controller.info(for: currency, controller.currencyTicker) +// let currency = templateContract.currency ?? templateContract.amount?.currencyStr ?? UNKNOWN +// let currencyInfo = controller.info(for: currency, controller.currencyTicker) let amountLabel = minimalistic ? String(localized: "Amount:") : String(localized: "Amount to pay:") let finalDestinationI = LazyView { PaymentView(stack: stack.push(), - currencyInfo: currencyInfo, url: url, template: true, amountToTransfer: $amountToTransfer, @@ -97,7 +96,6 @@ struct PayTemplateV: View { } // final destination with amountToTransfer, after user input of amount let finalDestinationS = LazyView { PaymentView(stack: stack.push(), - currencyInfo: currencyInfo, url: url, template: true, amountToTransfer: $amountShortcut, @@ -108,7 +106,7 @@ struct PayTemplateV: View { let inputDestination = LazyView { SubjectInputV(stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, url: url, amountAvailable: nil, amountToTransfer: $amountToTransfer, @@ -121,7 +119,7 @@ struct PayTemplateV: View { } // destination to subject input let shortcutDestination = LazyView { SubjectInputV(stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, url: url, amountAvailable: nil, amountToTransfer: $amountShortcut, @@ -135,7 +133,7 @@ struct PayTemplateV: View { Group { if amountIsEditable { // template contract amount is not fixed => let the user input an amount first let amountInput = AmountInputV(stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, url: url, amountAvailable: nil, amountToTransfer: $amountToTransfer, @@ -174,7 +172,6 @@ struct PayTemplateV: View { } else { // both template contract amount and summary are fixed => directly show the payment // Attention: contains a List, thus mustn't be included in a ScrollView PaymentView(stack: stack.push(), - currencyInfo: currencyInfo, url: url, template: true, amountToTransfer: $amountToTransfer, @@ -185,6 +182,11 @@ struct PayTemplateV: View { }.navigationTitle(navTitle) .frame(maxWidth: .infinity, alignment: .leading) .background(WalletColors().backgroundColor.edgesIgnoringSafeArea(.all)) + .task(id: controller.currencyTicker) { + let currency = amountToTransfer.currencyStr + currencyInfo = controller.info(for: currency, controller.currencyTicker) +// currencyName = currencyInfo.scope.currency + } .onAppear() { symLog.log("onAppear") DebugViewC.shared.setSheetID(SHEET_PAY_TEMPLATE) diff --git a/TalerWallet1/Views/Sheets/Payment/PaymentDone.swift b/TalerWallet1/Views/Sheets/Payment/PaymentDone.swift @@ -11,7 +11,7 @@ import SymLog struct PaymentDone: View { private let symLog = SymLogV(0) let stack: CallStack - let currencyInfo: CurrencyInfo + @Binding var currencyInfo: CurrencyInfo let transactionId: String @EnvironmentObject private var controller: Controller @@ -32,7 +32,7 @@ struct PaymentDone: View { if paymentDone { let navTitle = String(localized: "Paid", comment: "Title, short") TransactionSummaryV(stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, transactionId: transactionId, reloadAction: reloadOneAction, navTitle: navTitle, diff --git a/TalerWallet1/Views/Sheets/Payment/PaymentView.swift b/TalerWallet1/Views/Sheets/Payment/PaymentView.swift @@ -70,7 +70,6 @@ func templateFee(ppCheck: PreparePayResult?) -> Amount? { struct PaymentView: View { private let symLog = SymLogV(0) let stack: CallStack - let currencyInfo: CurrencyInfo // the scanned URL let url: URL @@ -84,6 +83,7 @@ struct PaymentView: View { @EnvironmentObject private var controller: Controller @AppStorage("myListStyle") var myListStyle: MyListStyle = .automatic + @State private var currencyInfo: CurrencyInfo = CurrencyInfo.zero(UNKNOWN) @State var preparePayResult: PreparePayResult? = nil let navTitle = String(localized: "Confirm Payment", comment:"pay merchant") @@ -105,7 +105,7 @@ struct PaymentView: View { // TODO: already paid let fee = try! Amount.diff(raw, effective) // TODO: different currencies ThreeAmountsSection(stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, topTitle: topTitle, topAbbrev: topAbbrev, topAmount: raw, fee: fee, @@ -125,7 +125,7 @@ struct PaymentView: View { Text("You don't have enough \(currency).") .talerFont(.headline) ThreeAmountsSection(stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, topTitle: topTitle, topAbbrev: topAbbrev, topAmount: raw, fee: nil, @@ -151,7 +151,7 @@ struct PaymentView: View { if let effective { NavigationLink(destination: LazyView { PaymentDone(stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, transactionId: preparePayResult.transactionId) }) { Text(navTitle) // Confirm Payment @@ -167,6 +167,11 @@ struct PaymentView: View { } // Cancel } .navigationTitle(navTitle) + .task(id: controller.currencyTicker) { + let currency = amountToTransfer.currencyStr + currencyInfo = controller.info(for: currency, controller.currencyTicker) +// currencyName = currencyInfo.scope.currency + } } else { LoadingView(scopeInfo: nil, message: url.host) .task { // this runs only once diff --git a/TalerWallet1/Views/Sheets/Refund/RefundURIView.swift b/TalerWallet1/Views/Sheets/Refund/RefundURIView.swift @@ -21,6 +21,7 @@ struct RefundURIView: View { @State var refundTransactionId: String? = nil @State var transaction: Transaction? + @State private var currencyInfo: CurrencyInfo = CurrencyInfo.zero(UNKNOWN) func reloadOneAction(_ transactionId: String, viewHandles: Bool) async throws -> Transaction { return try await model.getTransactionByIdT(transactionId, viewHandles: viewHandles) @@ -31,9 +32,9 @@ struct RefundURIView: View { let common = transaction.common let raw = common.amountRaw let currency = raw.currencyStr - let currencyInfo = controller.info(for: currency, controller.currencyTicker) +// let currencyInfo = controller.info(for: currency, controller.currencyTicker) TransactionSummaryV(stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, transactionId: refundTransactionId, reloadAction: reloadOneAction, navTitle: nil, // navTitle, @@ -48,6 +49,10 @@ struct RefundURIView: View { .buttonStyle(TalerButtonStyle(type: .prominent)) .padding(.horizontal) } + .task(id: controller.currencyTicker) { + currencyInfo = controller.info(for: currency, controller.currencyTicker) +// currencyName = currencyInfo.scope.currency + } } else { LoadingView(scopeInfo: nil, message: url.host) .task { diff --git a/TalerWallet1/Views/Sheets/WithdrawBankIntegrated/WithdrawAcceptDone.swift b/TalerWallet1/Views/Sheets/WithdrawBankIntegrated/WithdrawAcceptDone.swift @@ -12,7 +12,7 @@ import SymLog struct WithdrawAcceptDone: View { private let symLog = SymLogV(0) let stack: CallStack - let currencyInfo: CurrencyInfo + @Binding var currencyInfo: CurrencyInfo let exchangeBaseUrl: String? let url: URL @@ -40,7 +40,7 @@ struct WithdrawAcceptDone: View { Group { if let transactionId { TransactionSummaryV(stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, transactionId: transactionId, reloadAction: reloadOneAction, navTitle: navTitle, @@ -85,12 +85,28 @@ struct WithdrawAcceptDone: View { } } // MARK: - +#if DEBUG struct WithdrawAcceptDone_Previews: PreviewProvider { + @MainActor + struct StateContainer: View { + @State private var currencyInfoD: CurrencyInfo = CurrencyInfo.zero(DEMOCURRENCY) + @State private var currencyInfoT: CurrencyInfo = CurrencyInfo.zero(TESTCURRENCY) + + var body: some View { +// let test = Amount(currency: TESTCURRENCY, cent: 123) +// let demo = Amount(currency: DEMOCURRENCY, cent: 123456) + + WithdrawAcceptDone(stack: CallStack("Preview"), + currencyInfo: $currencyInfoD, + exchangeBaseUrl: DEMOEXCHANGE, + url: URL(string: DEMOSHOP)!, + amountToTransfer: nil) + } + } + static var previews: some View { - WithdrawAcceptDone(stack: CallStack("Preview"), - currencyInfo: CurrencyInfo.zero(DEMOCURRENCY), - exchangeBaseUrl: DEMOEXCHANGE, - url: URL(string: DEMOSHOP)!, - amountToTransfer: nil) + StateContainer() +// .environment(\.sizeCategory, .extraExtraLarge) Canvas Device Settings } } +#endif diff --git a/TalerWallet1/Views/Sheets/WithdrawBankIntegrated/WithdrawAcceptView.swift b/TalerWallet1/Views/Sheets/WithdrawBankIntegrated/WithdrawAcceptView.swift @@ -12,7 +12,7 @@ import SymLog struct WithdrawAcceptView: View { private let symLog = SymLogV() let stack: CallStack - let currencyInfo: CurrencyInfo + @Binding var currencyInfo: CurrencyInfo let navTitle = String(localized: "Withdrawal") // the URL from the bank website @@ -56,7 +56,7 @@ struct WithdrawAcceptView: View { let inColor = WalletColors().transactionColor(true) ThreeAmountsSection(stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, topTitle: String(localized: "Chosen amount to withdraw:"), topAbbrev: String(localized: "Chosen:", comment: "mini"), topAmount: raw, fee: fee, @@ -70,7 +70,7 @@ struct WithdrawAcceptView: View { summary: nil, merchant: nil) let coinData = CoinData(details: withdrawalAmountDetails) - QuiteSomeCoins(currencyInfo: currencyInfo, + QuiteSomeCoins(currencyInfo: $currencyInfo, currency: currency, coinData: coinData, shouldShowFee: true, // TODO: set to false if we never charge withdrawal fees @@ -81,7 +81,7 @@ struct WithdrawAcceptView: View { if tosAccepted { NavigationLink(destination: LazyView { WithdrawAcceptDone(stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, exchangeBaseUrl: exchange.exchangeBaseUrl, url: url, amountToTransfer: amountToTransfer) diff --git a/TalerWallet1/Views/Sheets/WithdrawBankIntegrated/WithdrawURIView.swift b/TalerWallet1/Views/Sheets/WithdrawBankIntegrated/WithdrawURIView.swift @@ -100,7 +100,7 @@ struct WithdrawURIView: View { } } // load defaultBaseUrl let acceptDestination = WithdrawAcceptView(stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, url: url, amountToTransfer: $amountToTransfer, exchange: $exchange) @@ -108,7 +108,7 @@ struct WithdrawURIView: View { ScrollView { let shortcutDestination = LazyView { WithdrawAcceptView(stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, url: url, amountToTransfer: $amountShortcut, exchange: $exchange) @@ -117,7 +117,7 @@ struct WithdrawURIView: View { let amountLabel = minimalistic ? String(localized: "Amount:") : String(localized: "Amount to withdraw:") AmountInputV(stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, url: nil, amountAvailable: amountAvailable, amountToTransfer: $amountToTransfer, diff --git a/TalerWallet1/Views/Sheets/WithdrawExchangeV.swift b/TalerWallet1/Views/Sheets/WithdrawExchangeV.swift @@ -30,6 +30,7 @@ struct WithdrawExchangeV: View { Group { if exchange != nil { ManualWithdraw(stack: stack.push(), + currencyInfo: $currencyInfo, isSheet: true, scopeInfo: exchange!.scopeInfo, exchange: $exchange, diff --git a/TalerWallet1/Views/Transactions/ThreeAmountsSection.swift b/TalerWallet1/Views/Transactions/ThreeAmountsSection.swift @@ -10,7 +10,7 @@ import taler_swift struct ThreeAmountsSheet: View { let stack: CallStack - let currencyInfo: CurrencyInfo + @Binding var currencyInfo: CurrencyInfo var common: TransactionCommon var topAbbrev: String var topTitle: String @@ -49,7 +49,7 @@ struct ThreeAmountsSheet: View { let txStateLcl = developerMode && pending ? (common.txState.minor?.localizedState ?? majorLcl) : majorLcl ThreeAmountsSection(stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, topTitle: topTitle, topAbbrev: topAbbrev, topAmount: raw, @@ -70,7 +70,7 @@ struct ThreeAmountsSheet: View { // MARK: - struct ThreeAmountsSection: View { let stack: CallStack - let currencyInfo: CurrencyInfo + @Binding var currencyInfo: CurrencyInfo var topTitle: String var topAbbrev: String var topAmount: Amount @@ -110,7 +110,7 @@ struct ThreeAmountsSection: View { .padding(.bottom) } AmountRowV(stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, title: minimalistic ? topAbbrev : topTitle, amount: topAmount, isNegative: !incoming, @@ -122,7 +122,7 @@ struct ThreeAmountsSection: View { let title = minimalistic ? String(localized: "Exchange fee (short):", defaultValue: "Fee:", comment: "short version") : String(localized: "Exchange fee (long):", defaultValue: "Fee:", comment: "long version") AmountRowV(stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, title: title, amount: fee, isNegative: !incoming, @@ -132,7 +132,7 @@ struct ThreeAmountsSection: View { } if let bottomAmount { AmountRowV(stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, title: minimalistic ? bottomAbbrev : bottomTitle, amount: bottomAmount, isNegative: !incoming, @@ -168,19 +168,27 @@ struct ThreeAmountsSection: View { } } // MARK: - +#if DEBUG struct ThreeAmounts_Previews: PreviewProvider { - static var previews: some View { - let common = TransactionCommon(type: .withdrawal, - txState: TransactionState(major: .done), - amountEffective: Amount(currency: LONGCURRENCY, cent: 10), - amountRaw: Amount(currency: LONGCURRENCY, cent: 20), - transactionId: "someTxID", - timestamp: Timestamp(from: 1_666_666_000_000), - txActions: []) - Group { + @MainActor + struct StateContainer: View { + @State private var currencyInfoD: CurrencyInfo = CurrencyInfo.zero(DEMOCURRENCY) + @State private var currencyInfoT: CurrencyInfo = CurrencyInfo.zero(TESTCURRENCY) + + var body: some View { + let common = TransactionCommon(type: .withdrawal, + txState: TransactionState(major: .done), + amountEffective: Amount(currency: LONGCURRENCY, cent: 10), + amountRaw: Amount(currency: LONGCURRENCY, cent: 20), + transactionId: "someTxID", + timestamp: Timestamp(from: 1_666_666_000_000), + txActions: []) +// let test = Amount(currency: TESTCURRENCY, cent: 123) +// let demo = Amount(currency: DEMOCURRENCY, cent: 123456) + List { ThreeAmountsSheet(stack: CallStack("Preview"), - currencyInfo: CurrencyInfo.zero(DEMOCURRENCY), + currencyInfo: $currencyInfoD, common: common, topAbbrev: "Withdrawal", topTitle: "Withdrawal", baseURL: DEMOEXCHANGE, noFees: false, large: 1==0, summary: nil, merchant: nil) @@ -193,4 +201,10 @@ struct ThreeAmounts_Previews: PreviewProvider { } } } + + static var previews: some View { + StateContainer() + // .environment(\.sizeCategory, .extraExtraLarge) Canvas Device Settings + } } +#endif diff --git a/TalerWallet1/Views/Transactions/TransactionRowView.swift b/TalerWallet1/Views/Transactions/TransactionRowView.swift @@ -9,7 +9,7 @@ import SwiftUI import taler_swift struct TransactionRowView: View { - let currencyInfo: CurrencyInfo + @Binding var currencyInfo: CurrencyInfo let transaction : Transaction @Environment(\.sizeCategory) var sizeCategory @@ -55,7 +55,7 @@ struct TransactionRowView: View { let iconBadge = TransactionIconBadge(type: common.type, foreColor: foreColor, done: done, incoming: incoming, shouldConfirm: shouldConfirm, needsKYC: needsKYC) - let amountV = AmountV(currencyInfo, common.amountEffective, isNegative: !incoming) + let amountV = AmountV($currencyInfo, common.amountEffective, isNegative: !incoming) .foregroundColor(foreColor) let topString = topString() @@ -178,12 +178,24 @@ struct TransactionRow_Previews: PreviewProvider { pending: false, id: "some payment ID", time: Timestamp(from: 1_666_666_000_000)) - static var previews: some View { - List { - TransactionRowView(currencyInfo: CurrencyInfo.zero(DEMOCURRENCY), transaction: withdrawal) - TransactionRowView(currencyInfo: CurrencyInfo.zero(DEMOCURRENCY), transaction: payment) + @MainActor + struct StateContainer: View { + @State private var currencyInfoD: CurrencyInfo = CurrencyInfo.zero(DEMOCURRENCY) + @State private var currencyInfoT: CurrencyInfo = CurrencyInfo.zero(TESTCURRENCY) + + var body: some View { + List { + TransactionRowView(currencyInfo: $currencyInfoD, transaction: withdrawal) + TransactionRowView(currencyInfo: $currencyInfoT, transaction: payment) + + } } } + + static var previews: some View { + StateContainer() +// .environment(\.sizeCategory, .extraExtraLarge) Canvas Device Settings + } } // MARK: - extension Transaction { // for PreViews diff --git a/TalerWallet1/Views/Transactions/TransactionSummaryV.swift b/TalerWallet1/Views/Transactions/TransactionSummaryV.swift @@ -27,7 +27,7 @@ extension Transaction { // for Dummys struct TransactionSummaryV: View { private let symLog = SymLogV(0) let stack: CallStack - let currencyInfo: CurrencyInfo + @Binding var currencyInfo: CurrencyInfo let transactionId: String let reloadAction: ((_ transactionId: String, _ viewHandles: Bool) async throws -> Transaction) let navTitle: String? @@ -138,7 +138,7 @@ struct TransactionSummaryV: View { } .listRowSeparator(.hidden) .talerFont(.title) TypeDetail(stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, transaction: $transaction, hasDone: hasDone) @@ -230,7 +230,7 @@ struct TransactionSummaryV: View { .multilineTextAlignment(.leading) // otherwise .listRowSeparator(.hidden) } - Link("Authorize now", destination: destination) + Link("Authorize now: 􀉣", destination: destination) .buttonStyle(TalerButtonStyle(type: .prominent, badge: CONFIRM_BANK)) .accessibilityHint(String(localized: "Will go to bank website to authorize this withdrawal.")) } @@ -269,7 +269,7 @@ struct TransactionSummaryV: View { struct TypeDetail: View { let stack: CallStack - let currencyInfo: CurrencyInfo + @Binding var currencyInfo: CurrencyInfo @Binding var transaction: Transaction let hasDone: Bool @Environment(\.colorScheme) private var colorScheme @@ -305,7 +305,7 @@ struct TransactionSummaryV: View { PendingWithdrawalDetails(transaction: $transaction, details: details) } // ManualDetails or Confirm now (with bank) ThreeAmountsSheet(stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, common: common, topAbbrev: String(localized: "Chosen:", comment: "mini"), topTitle: String(localized: "Chosen amount to withdraw:"), @@ -318,7 +318,7 @@ struct TransactionSummaryV: View { case .deposit(let depositTransaction): Group { let details = depositTransaction.details ThreeAmountsSheet(stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, common: common, topAbbrev: String(localized: "Deposit:", comment: "mini"), topTitle: String(localized: "Amount to deposit:"), @@ -332,7 +332,7 @@ struct TransactionSummaryV: View { let details = paymentTransaction.details TransactionDetailV(paymentTx: paymentTransaction) ThreeAmountsSheet(stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, common: common, topAbbrev: String(localized: "Price:", comment: "mini"), topTitle: String(localized: "Price (net):"), @@ -345,7 +345,7 @@ struct TransactionSummaryV: View { case .refund(let refundTransaction): Group { let details = refundTransaction.details // TODO: more details ThreeAmountsSheet(stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, common: common, topAbbrev: String(localized: "Refunded:", comment: "mini"), topTitle: String(localized: "Refunded amount:"), @@ -364,7 +364,7 @@ struct TransactionSummaryV: View { .talerFont(.title) let input = details.refreshInputAmount AmountRowV(stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, title: minimalistic ? "Refreshed:" : "Refreshed amount:", amount: input, isNegative: false, @@ -372,7 +372,7 @@ struct TransactionSummaryV: View { large: true) if let fee = refreshFee(input: input, output: details.refreshOutputAmount) { AmountRowV(stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, title: minimalistic ? "Fee:" : "Refreshed fee:", amount: fee, isNegative: !fee.isZero, @@ -402,6 +402,7 @@ struct TransactionSummaryV: View { } } } + case .peer2peer(let p2pTransaction): Group { let details = p2pTransaction.details if !transaction.isDone { @@ -434,7 +435,7 @@ struct TransactionSummaryV: View { let localizedType = transaction.isDone ? transaction.localizedTypePast : transaction.localizedType ThreeAmountsSheet(stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, common: common, topAbbrev: localizedType + colon, topTitle: localizedType + colon, @@ -443,10 +444,11 @@ struct TransactionSummaryV: View { summary: details.info.summary, merchant: nil) } // p2p + case .recoup(let recoupTransaction): Group { let details = recoupTransaction.details // TODO: more details ThreeAmountsSheet(stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, common: common, topAbbrev: String(localized: "Recoup:", comment: "mini"), topTitle: String(localized: "Recoup:"), @@ -459,7 +461,7 @@ struct TransactionSummaryV: View { case .denomLoss(let denomLossTransaction): Group { let details = denomLossTransaction.details // TODO: more details ThreeAmountsSheet(stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, common: common, topAbbrev: String(localized: "Lost:", comment: "mini"), topTitle: String(localized: "Money lost:"), diff --git a/TalerWallet1/Views/Transactions/TransactionsListView.swift b/TalerWallet1/Views/Transactions/TransactionsListView.swift @@ -16,7 +16,7 @@ fileprivate let showUpDown = 25 // show up+down buttons in the menubar if li struct TransactionsListView: View { private let symLog = SymLogV(0) let stack: CallStack - let currencyInfo: CurrencyInfo + @Binding var currencyInfo: CurrencyInfo let navTitle: String let scopeInfo: ScopeInfo @@ -37,7 +37,7 @@ struct TransactionsListView: View { List { TransactionsArraySliceV(symLog: symLog, stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, scopeInfo: scopeInfo, transactions: transactions, reloadOneAction: reloadOneAction) @@ -85,7 +85,7 @@ struct TransactionsListView: View { struct TransactionsArraySliceV: View { let symLog: SymLogV? let stack: CallStack - let currencyInfo: CurrencyInfo + @Binding var currencyInfo: CurrencyInfo let scopeInfo: ScopeInfo let transactions: [Transaction] let reloadOneAction: ((_ transactionId: String, _ viewHandles: Bool) async throws -> Transaction) @@ -105,7 +105,7 @@ struct TransactionsArraySliceV: View { NavigationLink { LazyView { TransactionSummaryV(stack: stack.push(), - currencyInfo: currencyInfo, + currencyInfo: $currencyInfo, transactionId: transaction.id, reloadAction: reloadOneAction, navTitle: nil, @@ -117,7 +117,7 @@ struct TransactionsArraySliceV: View { resumeAction: resumeAction) } } label: { - TransactionRowView(currencyInfo: currencyInfo, transaction: transaction) + TransactionRowView(currencyInfo: $currencyInfo, transaction: transaction) } .id(Int(index)) }