commit 67eb5e1121dc2d25193d76ce31859dce1401ee64 parent e45dd7de86e10db36ff6a8b99a9de30bc0a08b25 Author: Marc Stibane <marc@taler.net> Date: Sat, 19 Oct 2024 15:01:09 +0200 info2 Diffstat:
14 files changed, 36 insertions(+), 18 deletions(-)
diff --git a/TalerWallet1/Controllers/Controller.swift b/TalerWallet1/Controllers/Controller.swift @@ -141,7 +141,25 @@ class Controller: ObservableObject { return nil } - func info(for currency: String) -> CurrencyInfo? { + func info(for scope: ScopeInfo) -> CurrencyInfo? { +// return CurrencyInfo.euro() // Fake EUR instead of the real Currency +// return CurrencyInfo.francs() // Fake CHF instead of the real Currency + for info in currencyInfos { + if info.scope == scope { + return info + } + } +// logger.log(" ❗️ no info for \(currency)") + return nil + } + func info(for scope: ScopeInfo, _ ticker: Int) -> CurrencyInfo { + if ticker != currencyTicker { + print(" ❗️Yikes - race condition while getting info for \(scope.currency)") + } + return info(for: scope) ?? CurrencyInfo.zero(scope.currency) + } + + func info2(for currency: String) -> CurrencyInfo? { // return CurrencyInfo.euro() // Fake EUR instead of the real Currency // return CurrencyInfo.francs() // Fake CHF instead of the real Currency for info in currencyInfos { @@ -152,11 +170,11 @@ class Controller: ObservableObject { // logger.log(" ❗️ no info for \(currency)") return nil } - func info(for currency: String, _ ticker: Int) -> CurrencyInfo { + func info2(for currency: String, _ ticker: Int) -> CurrencyInfo { if ticker != currencyTicker { print(" ❗️Yikes - race condition while getting info for \(currency)") } - return info(for: currency) ?? CurrencyInfo.zero(currency) + return info2(for: currency) ?? CurrencyInfo.zero(currency) } func hasInfo(for currency: String) -> Bool { @@ -222,7 +240,7 @@ class Controller: ObservableObject { func getInfo(from exchangeBaseUrl: String, model: WalletModel) async throws -> CurrencyInfo? { let exchange = try await model.getExchangeByUrl(url: exchangeBaseUrl) let scopeInfo = exchange.scopeInfo - if let info = info(for: scopeInfo.currency) { + if let info = info(for: scopeInfo) { return info } let info = try await model.getCurrencyInfoM(scope: scopeInfo, delay: 0) diff --git a/TalerWallet1/Views/Actions/Banking/ManualWithdraw.swift b/TalerWallet1/Views/Actions/Banking/ManualWithdraw.swift @@ -45,7 +45,7 @@ struct ManualWithdraw: View { if let exchange { let scopeInfo = exchange.scopeInfo let currency = scopeInfo.currency - let currencyInfo = controller.info(for: currency, controller.currencyTicker) + let currencyInfo = controller.info2(for: currency, controller.currencyTicker) let navTitle = String(localized: "NavTitle_Withdraw (currency)", defaultValue: "Withdraw \(currencyInfo.symbol)", diff --git a/TalerWallet1/Views/Actions/Peer2peer/RequestPayment.swift b/TalerWallet1/Views/Actions/Peer2peer/RequestPayment.swift @@ -240,7 +240,7 @@ struct RequestPaymentContent: View { scopeInfo = balance.scopeInfo let currency = scopeInfo.currency amountToTransfer.setCurrency(currency) - currencyInfo = controller.info(for: currency, controller.currencyTicker) + currencyInfo = controller.info2(for: currency, controller.currencyTicker) } } // .task(id: amountToTransfer.value) { diff --git a/TalerWallet1/Views/Actions/Peer2peer/SendAmountV.swift b/TalerWallet1/Views/Actions/Peer2peer/SendAmountV.swift @@ -271,7 +271,7 @@ struct SendAmountContent: View { scopeInfo = balance.scopeInfo let currency = scopeInfo.currency amountToTransfer.setCurrency(currency) - currencyInfo = controller.info(for: currency, controller.currencyTicker) + currencyInfo = controller.info2(for: currency, controller.currencyTicker) do { amountAvailable = try await model.getMaxPeerPushDebitAmountM(scopeInfo) } catch { diff --git a/TalerWallet1/Views/Balances/BalancesSectionView.swift b/TalerWallet1/Views/Balances/BalancesSectionView.swift @@ -144,7 +144,7 @@ extension BalancesSectionView: View { }.id(sectionID) .listRowSeparator(.hidden) .task(id: controller.currencyTicker) { - currencyInfo = controller.info(for: currency, controller.currencyTicker) + currencyInfo = controller.info2(for: currency, controller.currencyTicker) } .task(id: shouldReloadBalances + 1_000_000) { symLog.log(".task for BalancesSectionView - load recent+completed+pending") diff --git a/TalerWallet1/Views/Settings/Exchange/ExchangeSectionView.swift b/TalerWallet1/Views/Settings/Exchange/ExchangeSectionView.swift @@ -128,7 +128,7 @@ struct ExchangeSectionView: View { } .task(id: controller.currencyTicker) { symLog.log("task \(didDelete ? 1 : 0)") - currencyInfo = controller.info(for: currency, controller.currencyTicker) + currencyInfo = controller.info2(for: currency, controller.currencyTicker) } .onDisappear() { disabled = false diff --git a/TalerWallet1/Views/Sheets/P2P_Sheets/P2pPayURIView.swift b/TalerWallet1/Views/Sheets/P2P_Sheets/P2pPayURIView.swift @@ -62,7 +62,7 @@ struct P2pPayURIView: View { .navigationTitle(navTitle) .task(id: controller.currencyTicker) { let currency = peerPullDebitResponse.amountRaw.currencyStr - currencyInfo = controller.info(for: currency, controller.currencyTicker) + currencyInfo = controller.info2(for: currency, controller.currencyTicker) } NavigationLink(destination: LazyView { diff --git a/TalerWallet1/Views/Sheets/P2P_Sheets/P2pReceiveURIView.swift b/TalerWallet1/Views/Sheets/P2P_Sheets/P2pReceiveURIView.swift @@ -71,7 +71,7 @@ struct P2pReceiveURIView: View { .navigationTitle(navTitle) .task(id: controller.currencyTicker) { let currency = peerPushCreditResponse.amountRaw.currencyStr - currencyInfo = controller.info(for: currency, controller.currencyTicker) + currencyInfo = controller.info2(for: currency, controller.currencyTicker) } if tosAccepted { NavigationLink(destination: LazyView { diff --git a/TalerWallet1/Views/Sheets/Payment/PayTemplateV.swift b/TalerWallet1/Views/Sheets/Payment/PayTemplateV.swift @@ -183,7 +183,7 @@ struct PayTemplateV: View { .background(WalletColors().backgroundColor.edgesIgnoringSafeArea(.all)) .task(id: controller.currencyTicker) { let currency = amountToTransfer.currencyStr - currencyInfo = controller.info(for: currency, controller.currencyTicker) + currencyInfo = controller.info2(for: currency, controller.currencyTicker) } .onAppear() { symLog.log("onAppear") @@ -218,7 +218,7 @@ struct PayTemplateV: View { // { symLog.log("preparePayForTemplate finished") amountToTransfer = prepAmount ?? zeroAmount summary = prepSummary ?? EMPTYSTRING - templateContract = contract + templateContract = contract // insufficient = result.insufficient // feeAmount = result.feeAmount // feeStr = result.feeStr diff --git a/TalerWallet1/Views/Sheets/Payment/PaymentView.swift b/TalerWallet1/Views/Sheets/Payment/PaymentView.swift @@ -209,7 +209,7 @@ struct PaymentView: View { .navigationTitle(navTitle) .task(id: controller.currencyTicker) { let currency = amountToTransfer.currencyStr - currencyInfo = controller.info(for: currency, controller.currencyTicker) + currencyInfo = controller.info2(for: currency, controller.currencyTicker) symLog.log("Info(for: \(currency)) loaded: \(currencyInfo.scope.currency)") } } else { diff --git a/TalerWallet1/Views/Sheets/Refund/RefundURIView.swift b/TalerWallet1/Views/Sheets/Refund/RefundURIView.swift @@ -50,7 +50,7 @@ struct RefundURIView: View { .padding(.horizontal) } .task(id: controller.currencyTicker) { - currencyInfo = controller.info(for: currency, controller.currencyTicker) + currencyInfo = controller.info2(for: currency, controller.currencyTicker) } } else { LoadingView(scopeInfo: nil, message: url.host) diff --git a/TalerWallet1/Views/Sheets/WithdrawBankIntegrated/WithdrawAcceptView.swift b/TalerWallet1/Views/Sheets/WithdrawBankIntegrated/WithdrawAcceptView.swift @@ -50,7 +50,7 @@ struct WithdrawAcceptView: View { let raw = withdrawalAmountDetails.amountRaw let effective = withdrawalAmountDetails.amountEffective let currency = raw.currencyStr - let currencyInfo = controller.info(for: currency, controller.currencyTicker) + let currencyInfo = controller.info2(for: currency, controller.currencyTicker) let fee = try! Amount.diff(raw, effective) let outColor = WalletColors().transactionColor(false) let inColor = WalletColors().transactionColor(true) diff --git a/TalerWallet1/Views/Sheets/WithdrawBankIntegrated/WithdrawURIView.swift b/TalerWallet1/Views/Sheets/WithdrawBankIntegrated/WithdrawURIView.swift @@ -168,7 +168,7 @@ struct WithdrawURIView: View { .navigationTitle(navTitle) .task(id: controller.currencyTicker) { let currency = amountToTransfer.currencyStr - currencyInfo = controller.info(for: currency, controller.currencyTicker) + currencyInfo = controller.info2(for: currency, controller.currencyTicker) } .onAppear() { symLog.log("onAppear") diff --git a/TalerWallet1/Views/Sheets/WithdrawExchangeV.swift b/TalerWallet1/Views/Sheets/WithdrawExchangeV.swift @@ -43,7 +43,7 @@ struct WithdrawExchangeV: View { amountLastUsed: $amountLastUsed) } .task(id: controller.currencyTicker) { - currencyInfo = controller.info(for: currency, controller.currencyTicker) + currencyInfo = controller.info2(for: currency, controller.currencyTicker) } } else { LoadingView(scopeInfo: nil, message: "No exchangeBaseUrl!")