taler-ios

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

commit 211d31649c64d9569e3979d12164eaeb4f436c3b
parent cf1566a3bfb9b1a8f1a43b7f6e9e97c99f878227
Author: Marc Stibane <marc@taler.net>
Date:   Mon, 22 Dec 2025 20:53:59 +0100

use disablePeerPayments, disableDirectDeposits

Diffstat:
MTalerWallet1/Model/Model+Balances.swift | 10+++++-----
MTalerWallet1/Views/Actions/ActionsSheet.swift | 21++++++++++++++++-----
MTalerWallet1/Views/Actions/Banking/DepositAmountV.swift | 7++++---
MTalerWallet1/Views/Actions/Peer2peer/RequestPayment.swift | 22+++++++++++++++++++---
MTalerWallet1/Views/Actions/Peer2peer/SendAmountV.swift | 14++++++++++----
MTalerWallet1/Views/HelperViews/ScopePicker.swift | 11++++++-----
6 files changed, 60 insertions(+), 25 deletions(-)

diff --git a/TalerWallet1/Model/Model+Balances.swift b/TalerWallet1/Model/Model+Balances.swift @@ -56,14 +56,14 @@ struct Balance: Identifiable, Decodable, Hashable, Sendable { } } extension Balance { - static func nonZeroBalances(_ balances: [Balance]) -> [Balance] { - balances.filter { balance in - !balance.available.isZero + static func firstwithDeposit(_ balances: [Balance]) -> Balance? { + balances.first { balance in + balance.disableDirectDeposits != true } } - static func firstNonZero(_ balances: [Balance]) -> Balance? { + static func firstWithP2P(_ balances: [Balance]) -> Balance? { balances.first { balance in - !balance.available.isZero + balance.disablePeerPayments != true } } } diff --git a/TalerWallet1/Views/Actions/ActionsSheet.swift b/TalerWallet1/Views/Actions/ActionsSheet.swift @@ -33,9 +33,17 @@ struct ActionsSheet: View { } return false } - private var canSend: Bool { // canDeposit + private var mayDeposit: Bool { // returns true if at least 1 balance didn't disable deposits for balance in controller.balances { - if !balance.available.isZero { + if !(balance.disableDirectDeposits == true) { // false or nil + return true + } + } + return false + } + private var mayP2P: Bool { // returns true if at least 1 balance didn't disable P2P + for balance in controller.balances { + if !(balance.disablePeerPayments == true) { // false or nil return true } } @@ -126,10 +134,13 @@ struct ActionsSheet: View { }.padding(.bottom, 20) } - let sendDisabled = !canSend - let recvDisabled = controller.balances.count == 0 + let noBalances = controller.balances.count == 0 + let noP2P = !self.mayP2P + let sendDisabled = noP2P + let recvDisabled = noBalances || noP2P + let depoDisabled = !mayDeposit SendRequestV(stack: stack.push(), sendDisabled: sendDisabled, recvDisabled: recvDisabled) - DepositWithdrawV(stack: stack.push(), sendDisabled: sendDisabled, recvDisabled: recvDisabled) + DepositWithdrawV(stack: stack.push(), sendDisabled: depoDisabled, recvDisabled: noBalances) QRButton(hideTitle: false) { qrButtonTapped = true } diff --git a/TalerWallet1/Views/Actions/Banking/DepositAmountV.swift b/TalerWallet1/Views/Actions/Banking/DepositAmountV.swift @@ -31,14 +31,15 @@ struct DepositAmountV: View { private func viewDidLoad() async { let balances = controller.balances if let selectedBalance { - if selectedBalance.available.isZero { + let disableDeposits = selectedBalance.disableDirectDeposits ?? false + if disableDeposits { // find another balance - balance = Balance.firstNonZero(balances) + balance = Balance.firstwithDeposit(balances) } else { balance = selectedBalance } } else { - balance = Balance.firstNonZero(balances) + balance = Balance.firstwithDeposit(balances) } if let balance { balanceIndex = balances.firstIndex(of: balance) ?? 0 diff --git a/TalerWallet1/Views/Actions/Peer2peer/RequestPayment.swift b/TalerWallet1/Views/Actions/Peer2peer/RequestPayment.swift @@ -49,14 +49,30 @@ struct RequestPayment: View { self._cash = StateObject(wrappedValue: { oimCash }()) } + private func firstWithP2P(_ balances : inout [Balance]) { + let first = Balance.firstWithP2P(balances) + symLog.log(first?.scopeInfo.currency) + balance = first + } @MainActor private func viewDidLoad() async { + var balances = controller.balances if let selectedBalance { - balance = selectedBalance - balanceIndex = controller.balances.firstIndex(of: selectedBalance) ?? 0 + let disablePeerPayments = selectedBalance.disablePeerPayments ?? false + if disablePeerPayments { + // find another balance + firstWithP2P(&balances) + } else { + balance = selectedBalance + } + } else { + firstWithP2P(&balances) + } + if let balance { + balanceIndex = balances.firstIndex(of: balance) ?? 0 } else { balanceIndex = 0 - balance = (controller.balances.count > 0) ? controller.balances[0] : nil + balance = (balances.count > 0) ? balances[0] : nil } } diff --git a/TalerWallet1/Views/Actions/Peer2peer/SendAmountV.swift b/TalerWallet1/Views/Actions/Peer2peer/SendAmountV.swift @@ -54,18 +54,24 @@ struct SendAmountV: View { self._cash = StateObject(wrappedValue: { oimCash }()) } + private func firstWithP2P(_ balances : inout [Balance]) { + let first = Balance.firstWithP2P(balances) + symLog.log(first?.scopeInfo.currency) + balance = first + } @MainActor private func viewDidLoad() async { - let balances = controller.balances + var balances = controller.balances if let selectedBalance { - if selectedBalance.available.isZero { + let disablePeerPayments = selectedBalance.disablePeerPayments ?? false + if disablePeerPayments { // find another balance - balance = Balance.firstNonZero(controller.balances) + firstWithP2P(&balances) } else { balance = selectedBalance } } else { - balance = Balance.firstNonZero(controller.balances) + firstWithP2P(&balances) } if let balance { balanceIndex = balances.firstIndex(of: balance) ?? 0 diff --git a/TalerWallet1/Views/HelperViews/ScopePicker.swift b/TalerWallet1/Views/HelperViews/ScopePicker.swift @@ -155,17 +155,18 @@ struct ScopeDropDown: View { let otherBalances = controller.balances.filter { $0 != controller.balances[selection] } let theList = LazyVStack(spacing: 0) { ForEach(0..<otherBalances.count, id: \.self) { index in - let item = otherBalances[index] - let rowDisabled = onlyNonZero ? item.available.isZero : false + let balance = otherBalances[index] + let disablePeerPayments = balance.disablePeerPayments ?? false + let rowDisabled = disablePeerPayments || (onlyNonZero ? balance.available.isZero : false) Button(action: { withAnimation { showDropdown.toggle() - selection = controller.balances.firstIndex(of: item) ?? selection + selection = controller.balances.firstIndex(of: balance) ?? selection } }, label: { - let currencyInfo = controller.info(for: item.scopeInfo, controller.currencyTicker) + let currencyInfo = controller.info(for: balance.scopeInfo, controller.currencyTicker) HStack(alignment: .top) { - dropDownRow(item, currencyInfo) // .border(.random) + dropDownRow(balance, currencyInfo) // .border(.random) .foregroundColor(rowDisabled ? .secondary : .primary) Spacer() chevron.foregroundColor(.clear)