taler-ios

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

commit a44efce28439095e0fb4bdcef7533b8ff4da5c20
parent aa7472d9254a254d7ac02646d97c6b8b8b170cb7
Author: Marc Stibane <marc@taler.net>
Date:   Thu, 11 Apr 2024 19:18:06 +0200

clientCancellationId

Diffstat:
MTalerWallet1/Model/Model+Withdraw.swift | 9++++++---
MTalerWallet1/Views/Banking/ManualWithdraw.swift | 9+++++++--
2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/TalerWallet1/Model/Model+Withdraw.swift b/TalerWallet1/Model/Model+Withdraw.swift @@ -92,13 +92,15 @@ struct WithdrawalAmountDetails: Decodable { fileprivate struct GetWithdrawalDetailsForAmount: WalletBackendFormattedRequest { typealias Response = WithdrawalAmountDetails func operation() -> String { "getWithdrawalDetailsForAmount" } - func args() -> Args { Args(exchangeBaseUrl: exchangeBaseUrl, amount: amount) } + func args() -> Args { Args(exchangeBaseUrl: exchangeBaseUrl, amount: amount, clientCancellationId: cancellationId) } var exchangeBaseUrl: String var amount: Amount + var cancellationId: String? struct Args: Encodable { var exchangeBaseUrl: String var amount: Amount + var clientCancellationId: String? } } // MARK: - @@ -207,10 +209,11 @@ extension WalletModel { return response } @MainActor // M for MainActor - func getWithdrawalDetailsForAmountM(_ exchangeBaseUrl: String, amount: Amount) + func getWithdrawalDetailsForAmountM(_ exchangeBaseUrl: String, amount: Amount, cancellationId: String? = nil) async throws -> WithdrawalAmountDetails { let request = GetWithdrawalDetailsForAmount(exchangeBaseUrl: exchangeBaseUrl, - amount: amount) + amount: amount, + cancellationId: cancellationId) let response = try await sendRequest(request, ASYNCDELAY) return response } diff --git a/TalerWallet1/Views/Banking/ManualWithdraw.swift b/TalerWallet1/Views/Banking/ManualWithdraw.swift @@ -110,7 +110,6 @@ struct ManualWithdraw: View { } } .task(id: amountToTransfer.value) { // re-run this whenever amountToTransfer changes - symLog.log("getExchangeByUrl(\(scopeInfo?.url))") if let exchangeBaseUrl = scopeInfo?.url { if exchange == nil || exchange?.tosStatus != .accepted { if let exc = await model.getExchangeByUrl(url: exchangeBaseUrl) { @@ -122,9 +121,15 @@ struct ManualWithdraw: View { if !amountToTransfer.isZero { do { let details = try await model.getWithdrawalDetailsForAmountM(exchangeBaseUrl, - amount: amountToTransfer) + amount: amountToTransfer, + cancellationId: "manual") withdrawalAmountDetails = details // agePicker.setAges(ages: withdrawalAmountDetails?.ageRestrictionOptions) +// } catch WALLET_CORE_REQUEST_CANCELLED { + // passing non-nil to clientCancellationId will throw WALLET_CORE_REQUEST_CANCELLED + // when calling getWithdrawalDetailsForAmount again before the last call returned + // since amountToTransfer changed and we don't need the old fee anymore + // we just ignore it and do nothing. } catch { // TODO: error symLog.log(error.localizedDescription) withdrawalAmountDetails = nil