taler-ios

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

commit 65ed8ed5e37bc76a705037e404e77c12804887f4
parent f972b7df432cfbe5f53815faad10ea620df90b26
Author: Marc Stibane <marc@taler.net>
Date:   Thu, 18 Jul 2024 14:27:53 +0200

Pass the function to compute fees as dependency

Diffstat:
MTalerWallet1/Views/HelperViews/AmountInputV.swift | 59++++++++++++++++++++++++++++-------------------------------
MTalerWallet1/Views/Peer2peer/SendAmount.swift | 9+++++++--
MTalerWallet1/Views/Sheets/WithdrawBankIntegrated/WithdrawURIView.swift | 9+++++++--
3 files changed, 42 insertions(+), 35 deletions(-)

diff --git a/TalerWallet1/Views/HelperViews/AmountInputV.swift b/TalerWallet1/Views/HelperViews/AmountInputV.swift @@ -9,6 +9,12 @@ import SwiftUI import taler_swift import SymLog +struct ComputeFeeResult { + let insufficient: Bool + let feeAmount: Amount? + let feeStr: String +} + struct AmountInputV: View { private let symLog = SymLogV(0) let stack: CallStack @@ -21,9 +27,10 @@ struct AmountInputV: View { let summaryIsEditable: Bool // if true we call SubjectInputV next @Binding var summary: String // @Binding var insufficient: Bool -// @Binding var feeAmount: Amount? + @Binding var feeAmount: Amount? let shortcutAction: ((_ amount: Amount) -> Void)? let buttonAction: () -> Void + let computeFee: ((_ amount: Amount) async -> ComputeFeeResult?)? @EnvironmentObject private var controller: Controller @EnvironmentObject private var model: WalletModel @@ -75,19 +82,14 @@ struct AmountInputV: View { title: amountLabel, shortcutAction: shortcutAction) // .accessibility(sortPriority: 2) - if flags.insufficient { - Text(insufficientLabel) - .talerFont(.body) - .foregroundColor(.red) - .padding(4) -// } else { -// Text(feeLabel(feeStr)) -// .talerFont(.body) -// .foregroundColor((feeAmount?.isZero ?? true) ? WalletColors().secondary(colorScheme, colorSchemeContrast) -// : .red) -// .padding(4) -// .accessibility(sortPriority: 1) - } + + let color = flags.insufficient || !(feeAmount?.isZero ?? true) ? .red + : WalletColors().secondary(colorScheme, colorSchemeContrast) + Text(flags.insufficient ? insufficientLabel : feeLabel(feeStr)) + .talerFont(.body) + .foregroundColor(color) + .padding(4) + .accessibility(sortPriority: 1) Button("Next") { buttonAction() } .buttonStyle(TalerButtonStyle(type: .prominent, disabled: flags.disabled)) .disabled(flags.disabled) @@ -98,24 +100,19 @@ struct AmountInputV: View { // symLog.log("onAppear") DebugViewC.shared.setSheetID(SHEET_PAY_TEMPL_AMOUNT) } -// .task(id: amountToTransfer.value) { -// if let url { -// symLog.log(".task preparePayForTemplate") -// if let result = await preparePayForTemplate(model: model, -// url: url, -// amount: amountToTransfer, -// summary: summaryIsEditable ? summary ?? " " -// : nil, -// announce: announce) -// { symLog.log("preparePayForTemplate finished") + .task(id: amountToTransfer.value) { + // re-compute the fees on every tapped digit or backspace + if let computeFee { + symLog.log(".task computeFee") + if let result: ComputeFeeResult = await computeFee(amountToTransfer) { + symLog.log("computeFee() finished") + feeStr = result.feeStr // insufficient = result.insufficient // feeAmount = result.feeAmount -// feeStr = result.feeStr -// preparePayResult = result.ppCheck -// } else { -// symLog.log("preparePayForTemplateM failed") -// } -// } -// } + } else { + symLog.log("computeFee() failed") + } + } + } } } diff --git a/TalerWallet1/Views/Peer2peer/SendAmount.swift b/TalerWallet1/Views/Peer2peer/SendAmount.swift @@ -65,6 +65,10 @@ struct SendAmount: View { : false } + private func computeFeeSend(_ amount: Amount) async -> ComputeFeeResult? { + return nil + } + var body: some View { #if PRINT_CHANGES let _ = Self._printChanges() @@ -114,9 +118,10 @@ struct SendAmount: View { summaryIsEditable: true, summary: $summary, // insufficient: $insufficient, -// feeAmount: $feeAmount, + feeAmount: $feeAmount, shortcutAction: shortcutAction, - buttonAction: buttonAction) + buttonAction: buttonAction, + computeFee: computeFeeSend) .background(NavigationLink(destination: shortcutDestination, isActive: $shortcutSelected) { EmptyView() }.frame(width: 0).opacity(0).hidden() ) diff --git a/TalerWallet1/Views/Sheets/WithdrawBankIntegrated/WithdrawURIView.swift b/TalerWallet1/Views/Sheets/WithdrawBankIntegrated/WithdrawURIView.swift @@ -55,6 +55,10 @@ struct WithdrawURIView: View { buttonSelected = true } + private func computeFeeWithdraw(_ amount: Amount) async -> ComputeFeeResult? { + return nil + } + var body: some View { if possibleExchanges.count > 0 { if let defaultBaseUrl = defaultExchangeBaseUrl ?? possibleExchanges.first?.exchangeBaseUrl { @@ -105,9 +109,10 @@ struct WithdrawURIView: View { summaryIsEditable: false, summary: $summary, // insufficient: $insufficient, -// feeAmount: $feeAmount, + feeAmount: $feeAmount, shortcutAction: shortcutAction, - buttonAction: buttonAction) + buttonAction: buttonAction, + computeFee: computeFeeWithdraw) .background(NavigationLink(destination: shortcutDestination, isActive: $shortcutSelected) { EmptyView() }.frame(width: 0).opacity(0).hidden() )