taler-ios

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

commit 4015fe85e2d60793a5f6f4c86128e5f478541c68
parent 93932249bf2ccaa676f48094155fc3b3eaee45dc
Author: Marc Stibane <marc@taler.net>
Date:   Sat, 20 Jul 2024 04:26:59 +0200

Pass in currencyInfo

Diffstat:
MTalerWallet1/Views/Banking/DepositAmountV.swift | 11++++++-----
MTalerWallet1/Views/Banking/ManualWithdraw.swift | 11++++++-----
MTalerWallet1/Views/HelperViews/AmountInputV.swift | 11+++++++----
MTalerWallet1/Views/HelperViews/CurrencyField.swift | 15++++++++-------
MTalerWallet1/Views/HelperViews/CurrencyInputView.swift | 50+++++++++++++++++++++++++-------------------------
MTalerWallet1/Views/Peer2peer/RequestPayment.swift | 11++++++-----
MTalerWallet1/Views/Peer2peer/SendAmount.swift | 5+++--
MTalerWallet1/Views/Sheets/Payment/PayTemplateV.swift | 4+++-
MTalerWallet1/Views/Sheets/WithdrawBankIntegrated/WithdrawURIView.swift | 10+++++++++-
9 files changed, 73 insertions(+), 55 deletions(-)

diff --git a/TalerWallet1/Views/Banking/DepositAmountV.swift b/TalerWallet1/Views/Banking/DepositAmountV.swift @@ -105,11 +105,12 @@ struct DepositAmountV: View { Text("Available:\t\(available)") .talerFont(.title3) .padding(.bottom, 2) - CurrencyInputView(amount: $amountToTransfer, - available: nil, // amountAvailable, - title: minimalistic ? String(localized: "Amount:") - : String(localized: "Amount to deposit:"), - shortcutAction: nil) + CurrencyInputView(currencyInfo: currencyInfo, + amount: $amountToTransfer, + available: nil, // amountAvailable, + title: minimalistic ? String(localized: "Amount:") + : String(localized: "Amount to deposit:"), + shortcutAction: nil) Text(insufficient ? insufficientLabel : feeLabel(feeStr)) diff --git a/TalerWallet1/Views/Banking/ManualWithdraw.swift b/TalerWallet1/Views/Banking/ManualWithdraw.swift @@ -72,11 +72,12 @@ struct ManualWithdraw: View { .multilineTextAlignment(.center) .talerFont(.body) if tosAccepted { - CurrencyInputView(amount: $amountToTransfer, - available: nil, - title: minimalistic ? String(localized: "Amount:") - : String(localized: "Amount to withdraw:"), - shortcutAction: nil) + CurrencyInputView(currencyInfo: currencyInfo, + amount: $amountToTransfer, + available: nil, + title: minimalistic ? String(localized: "Amount:") + : String(localized: "Amount to withdraw:"), + shortcutAction: nil) .padding(.top) QuiteSomeCoins(currencyInfo: currencyInfo, currency: currency, diff --git a/TalerWallet1/Views/HelperViews/AmountInputV.swift b/TalerWallet1/Views/HelperViews/AmountInputV.swift @@ -18,6 +18,8 @@ struct ComputeFeeResult { struct AmountInputV: View { private let symLog = SymLogV(0) let stack: CallStack + let currencyInfo: CurrencyInfo + // the scanned URL let url: URL? let amountAvailable: Amount? // TODO: GetMaxPeerPushAmount @@ -77,10 +79,11 @@ struct AmountInputV: View { .padding(.bottom, 2) // .accessibility(sortPriority: 3) } // available - CurrencyInputView(amount: $amountToTransfer, - available: amountAvailable, - title: amountLabel, - shortcutAction: shortcutAction) + CurrencyInputView(currencyInfo: currencyInfo, + amount: $amountToTransfer, + available: amountAvailable, + title: amountLabel, + shortcutAction: shortcutAction) // .accessibility(sortPriority: 2) let color = flags.insufficient || !(feeAmount?.isZero ?? true) ? .red diff --git a/TalerWallet1/Views/HelperViews/CurrencyField.swift b/TalerWallet1/Views/HelperViews/CurrencyField.swift @@ -30,8 +30,8 @@ import SymLog @MainActor struct CurrencyField: View { private let symLog = SymLogV(0) - @Binding var amount: Amount // the `value´ let currencyInfo: CurrencyInfo + @Binding var amount: Amount // the `value´ private var currencyFieldRepresentable: CurrencyTextfieldRepresentable! = nil @@ -47,11 +47,12 @@ struct CurrencyField: View { currencyFieldRepresentable.updateText(amount: amount) } - public init(amount: Binding<Amount>, currencyInfo: CurrencyInfo) { + public init(currencyInfo: CurrencyInfo, amount: Binding<Amount>) { self._amount = amount self.currencyInfo = currencyInfo - self.currencyFieldRepresentable = CurrencyTextfieldRepresentable(amount: self.$amount, - currencyInfo: currencyInfo) + self.currencyFieldRepresentable = + CurrencyTextfieldRepresentable(currencyInfo: currencyInfo, + amount: self.$amount) } var body: some View { @@ -74,7 +75,7 @@ struct CurrencyField: View { } } } - +// MARK: - // Sub-class UITextField to remove selection and caret class NoCaretTextField: UITextField { override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool { @@ -89,11 +90,11 @@ class NoCaretTextField: UITextField { .null } } - +// MARK: - @MainActor struct CurrencyTextfieldRepresentable: UIViewRepresentable { - @Binding var amount: Amount let 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,20 +11,20 @@ import taler_swift fileprivate let shortcuts = [5000,2500,1000,500] // TODO: adapt for ¥ struct ShortcutButton: View { - let shortcut: Int - let currency: String let currencyInfo: CurrencyInfo + let currency: String let currencyField: CurrencyField + let shortcut: Int let available: Amount? let action: (Int, CurrencyField) -> Void func makeButton(with newShortcut: Int) -> ShortcutButton { - ShortcutButton(shortcut: newShortcut, - currency: currency, - currencyInfo: currencyInfo, - currencyField: currencyField, - available: available, - action: action) + ShortcutButton(currencyInfo: currencyInfo, + currency: currency, + currencyField: currencyField, + shortcut: newShortcut, + available: available, + action: action) } func isDisabled(shortie: Amount) -> Bool { @@ -55,18 +55,19 @@ struct ShortcutButton: View { } // MARK: - struct CurrencyInputView: View { + let currencyInfo: CurrencyInfo @Binding var amount: Amount // the `value´ let available: Amount? let title: String let shortcutAction: ((_ amount: Amount) -> Void)? - @EnvironmentObject private var controller: Controller +// @EnvironmentObject private var controller: Controller @State private var hasBeenShown = false @State private var showKeyboard = 0 @State private var useShortcut = 0 - func action(shortcut: Int, currencyField: CurrencyField) { + @MainActor func action(shortcut: Int, currencyField: CurrencyField) { let shortie = Amount(currency: amount.currencyStr, cent: UInt64(shortcut)) // TODO: adapt for ¥ if let shortcutAction { shortcutAction(shortie) @@ -80,8 +81,7 @@ struct CurrencyInputView: View { var body: some View { let currency = amount.currencyStr - let currencyInfo = controller.info(for: currency, controller.currencyTicker) - let currencyField = CurrencyField(amount: $amount, currencyInfo: currencyInfo) + let currencyField = CurrencyField(currencyInfo: currencyInfo, amount: $amount) VStack (alignment: .center) { // center shortcut buttons Text(title) .frame(maxWidth: .infinity, alignment: .leading) @@ -102,12 +102,12 @@ struct CurrencyInputView: View { showKeyboard += 1 } if #available(iOS 16.0, *) { - let shortcutButton = ShortcutButton(shortcut: 0, - currency: currency, - currencyInfo: currencyInfo, - currencyField: currencyField, - available: available, - action: action) + let shortcutButton = ShortcutButton(currencyInfo: currencyInfo, + currency: currency, + currencyField: currencyField, + shortcut: 0, + available: available, + action: action) ViewThatFits(in: .horizontal) { HStack { ForEach(shortcuts, id: \.self) { @@ -168,15 +168,15 @@ struct CurrencyInputView: View { fileprivate struct Previews: PreviewProvider { @MainActor struct StateContainer: View { - @StateObject private var controller = Controller.shared @State var amountToTransfer = Amount(currency: LONGCURRENCY, cent: 0) var body: some View { -// Preview_Content() - CurrencyInputView(amount: $amountToTransfer, - available: nil, - title: "Amount to withdraw:", - shortcutAction: nil) - .environmentObject(controller) + let currencyInfo = CurrencyInfo.zero(LONGCURRENCY) + + CurrencyInputView(currencyInfo: currencyInfo, + amount: $amountToTransfer, + available: Amount(currency: LONGCURRENCY, cent: 2000), + title: "Amount to withdraw:", + shortcutAction: nil) } } static var previews: some View { diff --git a/TalerWallet1/Views/Peer2peer/RequestPayment.swift b/TalerWallet1/Views/Peer2peer/RequestPayment.swift @@ -74,11 +74,12 @@ struct RequestPayment: View { } let disabled = amountToTransfer.isZero || coinData.invalid || coinData.tooMany ScrollView { VStack(alignment: .trailing) { - CurrencyInputView(amount: $amountToTransfer, - available: nil, - title: minimalistic ? String(localized: "Amount:") - : String(localized: "Amount to request:"), - shortcutAction: shortcutAction) + CurrencyInputView(currencyInfo: currencyInfo, + amount: $amountToTransfer, + available: nil, + title: minimalistic ? String(localized: "Amount:") + : String(localized: "Amount to request:"), + shortcutAction: shortcutAction) .padding(.top) QuiteSomeCoins(currencyInfo: currencyInfo, currency: currency, diff --git a/TalerWallet1/Views/Peer2peer/SendAmount.swift b/TalerWallet1/Views/Peer2peer/SendAmount.swift @@ -110,8 +110,9 @@ struct SendAmount: View { ScrollView { let amountLabel = minimalistic ? String(localized: "Amount:") : String(localized: "Amount to send:") - - AmountInputV(stack: stack.push(), url: nil, + AmountInputV(stack: stack.push(), + currencyInfo: currencyInfo, + url: nil, amountAvailable: amountAvailable, amountToTransfer: $amountToTransfer, wireFee: nil, diff --git a/TalerWallet1/Views/Sheets/Payment/PayTemplateV.swift b/TalerWallet1/Views/Sheets/Payment/PayTemplateV.swift @@ -132,7 +132,9 @@ struct PayTemplateV: View { }// destination to subject input, when user tapped an amount shortcut Group { if amountIsEditable { // template contract amount is not fixed => let the user input an amount first - let amountInput = AmountInputV(stack: stack.push(), url: url, + let amountInput = AmountInputV(stack: stack.push(), + currencyInfo: currencyInfo, + url: url, amountAvailable: nil, amountToTransfer: $amountToTransfer, wireFee: nil, diff --git a/TalerWallet1/Views/Sheets/WithdrawBankIntegrated/WithdrawURIView.swift b/TalerWallet1/Views/Sheets/WithdrawBankIntegrated/WithdrawURIView.swift @@ -40,6 +40,7 @@ struct WithdrawURIView: View { @State private var exchange: Exchange? = nil @State private var possibleExchanges: [Exchange] = [] @State private var defaultExchangeBaseUrl: String? // if nil then use possibleExchanges + @State private var currencyInfo: CurrencyInfo = CurrencyInfo.zero("UNKNOWN") @State private var feeAmount: Amount? = nil @@ -102,7 +103,9 @@ struct WithdrawURIView: View { // TODO: input amount, then let amountLabel = minimalistic ? String(localized: "Amount:") : String(localized: "Amount to withdraw:") - AmountInputV(stack: stack.push(), url: nil, + AmountInputV(stack: stack.push(), + currencyInfo: currencyInfo, + url: nil, amountAvailable: amountAvailable, amountToTransfer: $amountToTransfer, wireFee: wireFee, @@ -126,6 +129,11 @@ struct WithdrawURIView: View { } // directly show the accept view } .navigationTitle(navTitle) + .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_WITHDRAWAL)