taler-ios

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

commit 1e4fc8b8456e4d8ff5484b2e1f154901c065691f
parent b21d9f2e47a260d1a9101f63442ad6c4e488bd84
Author: Marc Stibane <marc@taler.net>
Date:   Tue, 15 Oct 2024 10:56:49 +0200

Simplify

Diffstat:
MTalerWallet1/Views/Actions/DepositWithdrawV.swift | 15+++------------
MTalerWallet1/Views/Actions/SendRequestV.swift | 15+++------------
MTalerWallet1/Views/Actions/TwoRowButtons.swift | 30++++++++++++++++++++----------
3 files changed, 26 insertions(+), 34 deletions(-)

diff --git a/TalerWallet1/Views/Actions/DepositWithdrawV.swift b/TalerWallet1/Views/Actions/DepositWithdrawV.swift @@ -6,19 +6,10 @@ * @author Marc Stibane */ import SwiftUI -import taler_swift -import SymLog struct DepositWithdrawV: View { - private let symLog = SymLogV(0) let stack: CallStack - let sendDisabled: Bool // can't send/deposit if wallet has no coins - - @MainActor - func dismissAndPost(_ name: NSNotification.Name) { - dismissTop(stack.push()) - NotificationCenter.default.post(name: name, object: nil) // will trigger NavigationLink - } + let sendDisabled: Bool // can't send/deposit if wallet has no coins at all var body: some View { let depositTitle = String(localized: "DepositButton_Short", defaultValue: "Deposit", @@ -33,7 +24,7 @@ struct DepositWithdrawV: View { recvType: .withdrawal, recvA11y: withdrawTitle, sendDisabled: sendDisabled, - sendAction: { dismissAndPost(.DepositAction) }, - recvAction: { dismissAndPost(.WithdrawAction) }) + sendAction: .DepositAction, + recvAction: .WithdrawAction) } } diff --git a/TalerWallet1/Views/Actions/SendRequestV.swift b/TalerWallet1/Views/Actions/SendRequestV.swift @@ -6,19 +6,10 @@ * @author Marc Stibane */ import SwiftUI -import taler_swift -import SymLog struct SendRequestV: View { - private let symLog = SymLogV(0) let stack: CallStack - let sendDisabled: Bool // can't send/deposit if wallet has no coins - - @MainActor - func dismissAndPost(_ name: NSNotification.Name) { - dismissTop(stack.push()) - NotificationCenter.default.post(name: name, object: nil) // will trigger NavigationLink - } + let sendDisabled: Bool // can't send/deposit if wallet has no coins at all var body: some View { let sendTitle = String(localized: "SendButton_Short", defaultValue: "Send", @@ -33,7 +24,7 @@ struct SendRequestV: View { recvType: .peerPullCredit, recvA11y: requTitle, sendDisabled: sendDisabled, - sendAction: { dismissAndPost(.SendAction) }, - recvAction: { dismissAndPost(.RequestAction) }) + sendAction: .SendAction, + recvAction: .RequestAction) } } diff --git a/TalerWallet1/Views/Actions/TwoRowButtons.swift b/TalerWallet1/Views/Actions/TwoRowButtons.swift @@ -11,14 +11,21 @@ import taler_swift let LINELIMIT = 5 struct TypeButton: View { + let stack: CallStack let title: String let a11y: String var type: TransactionType let disabled: Bool - let action: () -> Void + let action: NSNotification.Name @AppStorage("minimalistic") var minimalistic: Bool = false + @MainActor + func dismissAndPost() { + dismissTop(stack.push()) + NotificationCenter.default.post(name: action, object: nil) // will trigger NavigationLink + } + var body: some View { #if DEBUG let debug = 1==0 @@ -68,7 +75,7 @@ struct TypeButton: View { .border(red) #endif - Button(action: action) { + Button(action: dismissAndPost) { if minimalistic { badge } else { @@ -89,8 +96,7 @@ struct TypeButton: View { aligned: .center)) } } - - +// MARK: - struct TwoRowButtons: View { let stack: CallStack let sendTitle: String @@ -100,11 +106,12 @@ struct TwoRowButtons: View { var recvType: TransactionType let recvA11y: String let sendDisabled: Bool - let sendAction: () -> Void - let recvAction: () -> Void + let sendAction: NSNotification.Name + let recvAction: NSNotification.Name func sendButton(_ title: String) -> TypeButton { - TypeButton(title: title, + TypeButton(stack: stack.push(), + title: title, a11y: sendA11y, type: sendType, disabled: sendDisabled, @@ -112,7 +119,8 @@ struct TwoRowButtons: View { } func recvButton(_ title: String) -> TypeButton { - TypeButton(title: title, + TypeButton(stack: stack.push(), + title: title, a11y: recvA11y, type: recvType, disabled: false, @@ -154,7 +162,8 @@ struct TwoRowButtons_Previews: PreviewProvider { recvType: .peerPullCredit, recvA11y: "Request " + LONGCURRENCY, sendDisabled: true, - sendAction: {}, recvAction: {}) + sendAction: .SendAction, + recvAction: .RequestAction) .listRowSeparator(.hidden) TwoRowButtons(stack: CallStack("Preview"), sendTitle: "Send " + DEMOCURRENCY, @@ -164,7 +173,8 @@ struct TwoRowButtons_Previews: PreviewProvider { recvType: .peerPullCredit, recvA11y: "Request " + DEMOCURRENCY, sendDisabled: true, - sendAction: {}, recvAction: {}) + sendAction: .SendAction, + recvAction: .RequestAction) .listRowSeparator(.hidden) } }