diff --git a/TalerWallet1/Views/Actions/Banking/DepositAmountAction.swift b/TalerWallet1/Views/Actions/Banking/DepositAmountAction.swift index a10d7759..f3e7b344 100644 --- a/TalerWallet1/Views/Actions/Banking/DepositAmountAction.swift +++ b/TalerWallet1/Views/Actions/Banking/DepositAmountAction.swift @@ -147,6 +147,7 @@ struct DepositAmountAction: View { amountLastUsed: $amountLastUsed, amountToTransfer: $amountToTransfer, amountAvailable: amountAvailable, + paytoUri: paytoUri, depositStarted: depositStarted ) { if let balance { diff --git a/TalerWallet1/Views/Actions/Banking/DepositAmountView.swift b/TalerWallet1/Views/Actions/Banking/DepositAmountView.swift index c781061c..3578fc0d 100644 --- a/TalerWallet1/Views/Actions/Banking/DepositAmountView.swift +++ b/TalerWallet1/Views/Actions/Banking/DepositAmountView.swift @@ -18,6 +18,7 @@ struct DepositAmountView: View { @Binding var amountLastUsed: Amount @Binding var amountToTransfer: Amount let amountAvailable: Amount + let paytoUri: String? let depositStarted: Bool let action: () -> Void @@ -56,26 +57,23 @@ struct DepositAmountView: View { : true // TODO: !(feeAmount?.isZero ?? false) } + /// Show what the deposit costs before it is made: wallet-core's checkDeposit @MainActor - private func computeFeeDeposit(_ amount: Amount) async -> ComputeFeeResult? { - if amount.isZero { - return ComputeFeeResult.zero() + private func computeFeeDeposit() async { + checkDepositResult = nil + feeAmount = nil + feeStr = EMPTYSTRING + guard let paytoUri, let balance, !amountToTransfer.isZero, + (try? amountToTransfer > amountAvailable) == false else { + return } - let insufficient = (try? amount > amountAvailable) ?? true - if insufficient { - return ComputeFeeResult.insufficient() + if let check = try? await model.checkDeposit4711(paytoUri, amount: amountToTransfer, + viewHandles: true), + let fee = try? Amount.diff(check.totalDepositCost, check.effectiveDepositAmount) { + checkDepositResult = check + feeAmount = fee + feeStr = fee.formatted(balance.scopeInfo, isNegative: false).0 } -// private func fee(ppCheck: CheckDepositResponse?) -> Amount? { - do { -// if let ppCheck { -// // Outgoing: fee = effective - raw -// feeAmount = try ppCheck.fees.coin + ppCheck.fees.wire + ppCheck.fees.refresh -// return feeAmount -// } - } catch { - - } - return nil } private func buttonTitle(_ amount: Amount) -> String { @@ -139,6 +137,7 @@ struct DepositAmountView: View { .disabled(disabled || depositStarted) .accessibilityHint(disabled ? hint : EMPTYSTRING) .padding(.horizontal) + .task(id: amountToTransfer.value) { await computeFeeDeposit() } } else { // no balance - Yikes Text("No balance. There seems to be a problem with the database...") }