commit 98791656fab31ba332ff6a007522413006f9f422
parent 33778743d5b5381f22d6eb5044eda7dbfeabe379
Author: Marc Stibane <marc@taler.net>
Date: Sun, 9 Aug 2026 17:20:58 +0200
DepositAmountAction
Diffstat:
3 files changed, 126 insertions(+), 126 deletions(-)
diff --git a/TalerWallet1/Views/Actions/Banking/DepositAmountAction.swift b/TalerWallet1/Views/Actions/Banking/DepositAmountAction.swift
@@ -0,0 +1,121 @@
+/*
+ * This file is part of GNU Taler, ©2022-26 Taler Systems S.A.
+ * See LICENSE.md
+ */
+/**
+ * @author Marc Stibane
+ */
+import SwiftUI
+import taler_swift
+import SymLog
+
+// Called from DepositSelectV -> BankSectionView
+struct DepositAmountAction: View {
+ private let symLog = SymLogV(0)
+ let stack: CallStack
+ // when Action is tapped while in currency TransactionList…
+ let selectedBalance: Balance? // …then use THIS balance, otherwise show picker
+ @Binding var amountLastUsed: Amount
+ let paytoUri: String?
+ let label: String?
+
+ @EnvironmentObject private var controller: Controller
+ @EnvironmentObject private var model: WalletModel
+
+ @State private var balanceIndex = 0
+ @State private var balance: Balance? = nil // nil only when balances == []
+ @State private var currencyInfo: CurrencyInfo = CurrencyInfo.zero(UNKNOWN)
+ @State private var amountToTransfer = Amount.zero(currency: EMPTYSTRING) // Update currency when used
+ @State private var amountAvailable = Amount.zero(currency: EMPTYSTRING) // GetMaxPeerPushAmount
+
+ @MainActor
+ private func viewDidLoad() async {
+ let balances = controller.balances
+ if let selectedBalance {
+ let disableDeposits = selectedBalance.disableDirectDeposits ?? false
+ if disableDeposits {
+ // find another balance
+ balance = Balance.firstwithDeposit(balances)
+ } else {
+ balance = selectedBalance
+ }
+ } else {
+ balance = Balance.firstwithDeposit(balances)
+ }
+ if let balance {
+ balanceIndex = balances.firstIndex(of: balance) ?? 0
+ } else {
+ balanceIndex = 0
+ balance = balances.isEmpty ? nil : balances[0]
+ }
+ }
+
+ @MainActor
+ private func newBalance() async {
+ // runs whenever the user changes the exchange via ScopePicker, or on new currencyInfo
+ symLog.log("❗️ task \(balanceIndex)")
+ if let balance {
+ let scope = balance.scopeInfo
+ amountToTransfer.setCurrency(scope.currency)
+ currencyInfo = controller.info(for: scope, controller.currencyTicker)
+ do {
+ amountAvailable = try await model.getMaxDepositAmount(scope)
+ } catch {
+ // TODO: Error
+ amountAvailable = balance.available
+ }
+ }
+ }
+
+ var body: some View {
+#if PRINT_CHANGES
+ let _ = Self._printChanges()
+#endif
+ let count = controller.balances.count
+ let _ = symLog.log("count = \(count)")
+ let currencySymbol = currencyInfo.symbol
+ let navA11y = DepositAmountView.navTitle(currencyInfo.name, true) // always include currency for a11y
+ let navTitle = DepositAmountView.navTitle(currencySymbol, currencyInfo.hasSymbol)
+ let scrollView = ScrollView {
+ if let label {
+ Text("to \(label)")
+ .talerFont(.picker)
+ .frame(maxWidth: .infinity, alignment: .leading)
+ .padding(.horizontal)
+ }
+ if count > 1 {
+ ScopePicker(stack: stack.push(),
+ value: $balanceIndex,
+ onlyNonZero: true) // can only send what exists
+ { index in
+ balanceIndex = index
+ balance = controller.balances[index]
+ }
+ .padding(.horizontal)
+ .padding(.bottom, 4)
+ } // TODO: else show static text?
+ DepositAmountView(stack: stack.push(),
+ balance: $balance,
+ balanceIndex: $balanceIndex,
+ amountLastUsed: $amountLastUsed,
+ amountToTransfer: $amountToTransfer,
+ amountAvailable: amountAvailable,
+ paytoUri: paytoUri)
+ } // ScrollView
+ .navigationTitle(navTitle)
+ .frame(maxWidth: .infinity, alignment: .leading)
+ .background(FullBackground())
+ .task {
+ setVoice(to: nil)
+ await viewDidLoad()
+ }
+ .task(id: balanceIndex + (1000 * controller.currencyTicker)) { await newBalance() }
+
+ if #available(iOS 16.4, *) {
+ scrollView.toolbar(.hidden, for: .tabBar)
+ .scrollBounceBehavior(.basedOnSize)
+ } else {
+ scrollView
+ }
+ }
+}
diff --git a/TalerWallet1/Views/Actions/Banking/DepositAmountV.swift b/TalerWallet1/Views/Actions/Banking/DepositAmountV.swift
@@ -1,121 +0,0 @@
-/*
- * This file is part of GNU Taler, ©2022-26 Taler Systems S.A.
- * See LICENSE.md
- */
-/**
- * @author Marc Stibane
- */
-import SwiftUI
-import taler_swift
-import SymLog
-
-// Called from DepositSelectV
-struct DepositAmountV: View {
- private let symLog = SymLogV(0)
- let stack: CallStack
- // when Action is tapped while in currency TransactionList…
- let selectedBalance: Balance? // …then use THIS balance, otherwise show picker
- @Binding var amountLastUsed: Amount
- let paytoUri: String?
- let label: String?
-
- @EnvironmentObject private var controller: Controller
- @EnvironmentObject private var model: WalletModel
-
- @State private var balanceIndex = 0
- @State private var balance: Balance? = nil // nil only when balances == []
- @State private var currencyInfo: CurrencyInfo = CurrencyInfo.zero(UNKNOWN)
- @State private var amountToTransfer = Amount.zero(currency: EMPTYSTRING) // Update currency when used
- @State private var amountAvailable = Amount.zero(currency: EMPTYSTRING) // GetMaxPeerPushAmount
-
- @MainActor
- private func viewDidLoad() async {
- let balances = controller.balances
- if let selectedBalance {
- let disableDeposits = selectedBalance.disableDirectDeposits ?? false
- if disableDeposits {
- // find another balance
- balance = Balance.firstwithDeposit(balances)
- } else {
- balance = selectedBalance
- }
- } else {
- balance = Balance.firstwithDeposit(balances)
- }
- if let balance {
- balanceIndex = balances.firstIndex(of: balance) ?? 0
- } else {
- balanceIndex = 0
- balance = balances.isEmpty ? nil : balances[0]
- }
- }
-
- @MainActor
- private func newBalance() async {
- // runs whenever the user changes the exchange via ScopePicker, or on new currencyInfo
- symLog.log("❗️ task \(balanceIndex)")
- if let balance {
- let scope = balance.scopeInfo
- amountToTransfer.setCurrency(scope.currency)
- currencyInfo = controller.info(for: scope, controller.currencyTicker)
- do {
- amountAvailable = try await model.getMaxDepositAmount(scope)
- } catch {
- // TODO: Error
- amountAvailable = balance.available
- }
- }
- }
-
- var body: some View {
-#if PRINT_CHANGES
- let _ = Self._printChanges()
-#endif
- let count = controller.balances.count
- let _ = symLog.log("count = \(count)")
- let currencySymbol = currencyInfo.symbol
- let navA11y = DepositAmountView.navTitle(currencyInfo.name, true) // always include currency for a11y
- let navTitle = DepositAmountView.navTitle(currencySymbol, currencyInfo.hasSymbol)
- let scrollView = ScrollView {
- if let label {
- Text("to \(label)")
- .talerFont(.picker)
- .frame(maxWidth: .infinity, alignment: .leading)
- .padding(.horizontal)
- }
- if count > 1 {
- ScopePicker(stack: stack.push(),
- value: $balanceIndex,
- onlyNonZero: true) // can only send what exists
- { index in
- balanceIndex = index
- balance = controller.balances[index]
- }
- .padding(.horizontal)
- .padding(.bottom, 4)
- } // TODO: else show static text?
- DepositAmountView(stack: stack.push(),
- balance: $balance,
- balanceIndex: $balanceIndex,
- amountLastUsed: $amountLastUsed,
- amountToTransfer: $amountToTransfer,
- amountAvailable: amountAvailable,
- paytoUri: paytoUri)
- } // ScrollView
- .navigationTitle(navTitle)
- .frame(maxWidth: .infinity, alignment: .leading)
- .background(FullBackground())
- .task {
- setVoice(to: nil)
- await viewDidLoad()
- }
- .task(id: balanceIndex + (1000 * controller.currencyTicker)) { await newBalance() }
-
- if #available(iOS 16.4, *) {
- scrollView.toolbar(.hidden, for: .tabBar)
- .scrollBounceBehavior(.basedOnSize)
- } else {
- scrollView
- }
- }
-}
diff --git a/TalerWallet1/Views/Settings/Bank/BankSectionView.swift b/TalerWallet1/Views/Settings/Bank/BankSectionView.swift
@@ -85,11 +85,11 @@ struct BankSectionView: View {
} else {
let navTitle = String(localized: "NavTitle_Deposit", // _Currency",
defaultValue: "Deposit") // \(currencySymbol)"
- DepositAmountV(stack: stack.push(),
- selectedBalance: selectedBalance,
- amountLastUsed: $amountLastUsed,
- paytoUri: account.payToWorkAround, // TODO: paytoUri,
- label: account.label)
+ DepositAmountAction(stack: stack.push(),
+ selectedBalance: selectedBalance,
+ amountLastUsed: $amountLastUsed,
+ paytoUri: account.payToWorkAround, // TODO: paytoUri,
+ label: account.label)
.navigationTitle(navTitle)
}
} label: {