taler-ios

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

commit 586eed9692448837f9a43b3531e0ce660f813469
parent 483e5fa2e18f0af439bdcbb0d6c18663dc7d42de
Author: Marc Stibane <marc@taler.net>
Date:   Fri, 13 Oct 2023 16:22:49 +0200

TwoRowButtons

Diffstat:
MTalerWallet.xcodeproj/project.pbxproj | 12++++++------
DTalerWallet1/Views/Balances/BalanceRowButtons.swift | 56--------------------------------------------------------
MTalerWallet1/Views/Balances/BalanceRowView.swift | 16++++++++++++----
ATalerWallet1/Views/Balances/TwoRowButtons.swift | 56++++++++++++++++++++++++++++++++++++++++++++++++++++++++
MTalerWallet1/Views/Exchange/ExchangeSectionView.swift | 49++++++++++++++++++++++++++++++++++++++-----------
5 files changed, 112 insertions(+), 77 deletions(-)

diff --git a/TalerWallet.xcodeproj/project.pbxproj b/TalerWallet.xcodeproj/project.pbxproj @@ -70,7 +70,7 @@ 4E3EAE4C2A990778009F1BE8 /* AmountView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EB095492989CBFE0043A8A1 /* AmountView.swift */; }; 4E3EAE4D2A990778009F1BE8 /* P2pAcceptDone.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E3B4BC22A42252300CC88B8 /* P2pAcceptDone.swift */; }; 4E3EAE4E2A990778009F1BE8 /* AnyTransition+backslide.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E363CBD2A23CB2100D7E98C /* AnyTransition+backslide.swift */; }; - 4E3EAE4F2A990778009F1BE8 /* BalanceRowButtons.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EB065432A4CD1A80039B91D /* BalanceRowButtons.swift */; }; + 4E3EAE4F2A990778009F1BE8 /* TwoRowButtons.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EB065432A4CD1A80039B91D /* TwoRowButtons.swift */; }; 4E3EAE502A990778009F1BE8 /* Model+Transactions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EB095322989CBFE0043A8A1 /* Model+Transactions.swift */; }; 4E3EAE512A990778009F1BE8 /* Controller+playSound.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E578E912A481D8600F21F1C /* Controller+playSound.swift */; }; 4E3EAE522A990778009F1BE8 /* WalletEmptyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EB095392989CBFE0043A8A1 /* WalletEmptyView.swift */; }; @@ -170,7 +170,7 @@ 4EA1ABBE29A3833A008821EA /* PublicConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EA1ABBD29A3833A008821EA /* PublicConstants.swift */; }; 4EA551252A2C923600FEC9A8 /* CurrencyInputView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EA551242A2C923600FEC9A8 /* CurrencyInputView.swift */; }; 4EAD117629F672FA008EDD0B /* KeyboardResponder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EAD117529F672FA008EDD0B /* KeyboardResponder.swift */; }; - 4EB065442A4CD1A80039B91D /* BalanceRowButtons.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EB065432A4CD1A80039B91D /* BalanceRowButtons.swift */; }; + 4EB065442A4CD1A80039B91D /* TwoRowButtons.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EB065432A4CD1A80039B91D /* TwoRowButtons.swift */; }; 4EB094D629896CD20043A8A1 /* TalerWalletTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EB094D429896CD20043A8A1 /* TalerWalletTests.swift */; }; 4EB094D729896CD20043A8A1 /* WalletBackendTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EB094D529896CD20043A8A1 /* WalletBackendTests.swift */; }; 4EB094DC29896D030043A8A1 /* TalerWalletUITestsLaunchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EB094D929896D030043A8A1 /* TalerWalletUITestsLaunchTests.swift */; }; @@ -336,7 +336,7 @@ 4EA1ABBD29A3833A008821EA /* PublicConstants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PublicConstants.swift; sourceTree = "<group>"; }; 4EA551242A2C923600FEC9A8 /* CurrencyInputView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CurrencyInputView.swift; sourceTree = "<group>"; }; 4EAD117529F672FA008EDD0B /* KeyboardResponder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeyboardResponder.swift; sourceTree = "<group>"; }; - 4EB065432A4CD1A80039B91D /* BalanceRowButtons.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BalanceRowButtons.swift; sourceTree = "<group>"; }; + 4EB065432A4CD1A80039B91D /* TwoRowButtons.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TwoRowButtons.swift; sourceTree = "<group>"; }; 4EB094D429896CD20043A8A1 /* TalerWalletTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TalerWalletTests.swift; sourceTree = "<group>"; }; 4EB094D529896CD20043A8A1 /* WalletBackendTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WalletBackendTests.swift; sourceTree = "<group>"; }; 4EB094D929896D030043A8A1 /* TalerWalletUITestsLaunchTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TalerWalletUITestsLaunchTests.swift; sourceTree = "<group>"; }; @@ -683,7 +683,7 @@ 4EB095372989CBFE0043A8A1 /* BalancesListView.swift */, 4EB0953A2989CBFE0043A8A1 /* BalancesSectionView.swift */, 4EB095362989CBFE0043A8A1 /* BalanceRowView.swift */, - 4EB065432A4CD1A80039B91D /* BalanceRowButtons.swift */, + 4EB065432A4CD1A80039B91D /* TwoRowButtons.swift */, 4EB095382989CBFE0043A8A1 /* PendingRowView.swift */, 4E87C8742A34B411001C6406 /* UncompletedRowView.swift */, ); @@ -1071,7 +1071,7 @@ 4E3EAE4D2A990778009F1BE8 /* P2pAcceptDone.swift in Sources */, 4E3EAE4E2A990778009F1BE8 /* AnyTransition+backslide.swift in Sources */, 4EFA39602AA7946B00742548 /* ToSButtonView.swift in Sources */, - 4E3EAE4F2A990778009F1BE8 /* BalanceRowButtons.swift in Sources */, + 4E3EAE4F2A990778009F1BE8 /* TwoRowButtons.swift in Sources */, 4E3EAE502A990778009F1BE8 /* Model+Transactions.swift in Sources */, 4E3EAE512A990778009F1BE8 /* Controller+playSound.swift in Sources */, 4E3EAE522A990778009F1BE8 /* WalletEmptyView.swift in Sources */, @@ -1174,7 +1174,7 @@ 4E3B4BC32A42252300CC88B8 /* P2pAcceptDone.swift in Sources */, 4E363CBE2A23CB2100D7E98C /* AnyTransition+backslide.swift in Sources */, 4EFA39612AA7946B00742548 /* ToSButtonView.swift in Sources */, - 4EB065442A4CD1A80039B91D /* BalanceRowButtons.swift in Sources */, + 4EB065442A4CD1A80039B91D /* TwoRowButtons.swift in Sources */, 4EB095592989CBFE0043A8A1 /* Model+Transactions.swift in Sources */, 4E578E922A481D8600F21F1C /* Controller+playSound.swift in Sources */, 4EB0955F2989CBFE0043A8A1 /* WalletEmptyView.swift in Sources */, diff --git a/TalerWallet1/Views/Balances/BalanceRowButtons.swift b/TalerWallet1/Views/Balances/BalanceRowButtons.swift @@ -1,56 +0,0 @@ -/* - * This file is part of GNU Taler, ©2022-23 Taler Systems S.A. - * See LICENSE.md - */ -import SwiftUI -import taler_swift - -struct BalanceRowButtons: View { - let amount: Amount - let narrow: Bool - let lineLimit: Int - let sendAction: () -> Void - let recvAction: () -> Void - @Environment(\.sizeCategory) var sizeCategory - - var body: some View { - let currency = amount.currencyStr - Group { - Button("Request\nPayment", action: recvAction) - .lineLimit(lineLimit) - .disabled(false) - .buttonStyle(TalerButtonStyle(type: .bordered, - dimmed: false, - narrow: narrow, - aligned: .center)) - Button("Send\n\(currency)", action: sendAction) - .lineLimit(lineLimit) - .disabled(amount.isZero) - .buttonStyle(TalerButtonStyle(type: .bordered, - dimmed: false, - narrow: narrow, - aligned: .center)) - } - } -} - -struct BalanceRowButtons_Previews: PreviewProvider { - static var previews: some View { - List { - VStack { - let amount = try! Amount(fromString: LONGCURRENCY + ":1234.56") - BalanceRowButtons(amount: Amount(currency: "TestKUDOS", value: 1234), - narrow: false, lineLimit: 0, - sendAction: {}, recvAction: {}) - BalanceButton(amount: amount, rowAction: {}) - } - HStack { - let amount = try! Amount(fromString: "KUDOS" + ":1234.56") - BalanceRowButtons(amount: amount, - narrow: true, lineLimit: 2, - sendAction: {}, recvAction: {}) - BalanceButton(amount: amount, rowAction: {}) - } - } - } -} diff --git a/TalerWallet1/Views/Balances/BalanceRowView.swift b/TalerWallet1/Views/Balances/BalanceRowView.swift @@ -36,6 +36,10 @@ struct BalanceRowView: View { let recvAction: () -> Void let rowAction: () -> Void @Environment(\.sizeCategory) var sizeCategory + let sendTitle1 = String(localized: "Send", comment: "Top of button <Send Money>") + let sendTitle2 = String(localized: "Money", comment: "Bottom of button <Send Money>") + let requestTitle1 = String(localized: "Request", comment: "Top of button <Request Payment>") + let requestTitle2 = String(localized: "Payment", comment: "Bottom of button <Request Payment>") func needVStack(_ amount: Amount) -> Bool { // Sizes: 320 (SE), 375 (X, Xs, 12, 13 mini), 390 (12,13,14), 414 (Plus, Max), 428 (Pro Max) @@ -61,19 +65,23 @@ struct BalanceRowView: View { var body: some View { Group { + let requestTitle = requestTitle1 + "\n" + requestTitle2 + let sendTitle = sendTitle1 + "\n" + sendTitle2 if needVStack(amount) { VStack (alignment: .trailing) { BalanceButton(amount: amount, rowAction: rowAction) HStack { - BalanceRowButtons(amount: amount, narrow: false, lineLimit: 5, - sendAction: sendAction, recvAction: recvAction) } + TwoRowButtons(sendTitle: sendTitle, recvTitle: requestTitle, + lineLimit: 5, sendDisabled: amount.isZero, + sendAction: sendAction, recvAction: recvAction) } } else { HStack { - BalanceRowButtons(amount: amount, narrow: true, lineLimit: 5, - sendAction: sendAction, recvAction: recvAction) BalanceButton(amount: amount, rowAction: rowAction) + TwoRowButtons(sendTitle: sendTitle, recvTitle: requestTitle, + lineLimit: 5, sendDisabled: amount.isZero, + sendAction: sendAction, recvAction: recvAction) } // .fixedSize(horizontal: true, vertical: true) // should make all buttons equal height - but doesn't } diff --git a/TalerWallet1/Views/Balances/TwoRowButtons.swift b/TalerWallet1/Views/Balances/TwoRowButtons.swift @@ -0,0 +1,56 @@ +/* + * This file is part of GNU Taler, ©2022-23 Taler Systems S.A. + * See LICENSE.md + */ +import SwiftUI +import taler_swift + +struct TwoRowButtons: View { + let sendTitle: String + let recvTitle: String + let lineLimit: Int + let sendDisabled: Bool + let sendAction: () -> Void + let recvAction: () -> Void + @Environment(\.sizeCategory) var sizeCategory + + var body: some View { + Group { + Button(sendTitle, action: sendAction) + .lineLimit(lineLimit) + .disabled(sendDisabled) + .buttonStyle(TalerButtonStyle(type: .bordered, + dimmed: false, + aligned: .center)) + Button(recvTitle, action: recvAction) + .lineLimit(lineLimit) + .disabled(false) + .buttonStyle(TalerButtonStyle(type: .bordered, + dimmed: false, + aligned: .center)) + } + } +} + +struct TwoRowButtons_Previews: PreviewProvider { + static var previews: some View { + List { + VStack { + let amount = try! Amount(fromString: LONGCURRENCY + ":1234.56") + TwoRowButtons(sendTitle: "Send\n" + LONGCURRENCY, + recvTitle: "Receive\n" + LONGCURRENCY, + lineLimit: 0, sendDisabled: true, + sendAction: {}, recvAction: {}) + BalanceButton(amount: amount, rowAction: {}) + } + HStack { + let amount = try! Amount(fromString: DEMOCURRENCY + ":1234.56") + TwoRowButtons(sendTitle: "Send\n" + DEMOCURRENCY, + recvTitle: "Receive\n" + DEMOCURRENCY, + lineLimit: 2, sendDisabled: true, + sendAction: {}, recvAction: {}) + BalanceButton(amount: amount, rowAction: {}) + } + } + } +} diff --git a/TalerWallet1/Views/Exchange/ExchangeSectionView.swift b/TalerWallet1/Views/Exchange/ExchangeSectionView.swift @@ -12,6 +12,25 @@ struct ExchangeRowView: View { @Binding var centsToTransfer: UInt64 @State private var buttonSelected: Int? = nil + + func selectAndUpdate(_ button: Int) { + Task { // runs on MainActor + do { + buttonSelected = button // will trigger NavigationLink +// try await model.updateExchange(scopeInfo: balance.scopeInfo) + } catch { // TODO: error handling - couldn't updateExchange + // symLog.log("error: \(error)") + } + } + } + let depositTitle = String(localized: "Deposit", comment: "Top of button <Deposit (currency)>") + let withdrawTitle = String(localized: "Withdraw", comment: "Top of button <Withdraw (currency)>") + func needVStack(_ currency: String) -> Bool { + // Sizes: 320 (SE), 375 (X, Xs, 12, 13 mini), 390 (12,13,14), 414 (Plus, Max), 428 (Pro Max) + + return false + } + var body: some View { let baseURL = exchange.exchangeBaseUrl @@ -31,18 +50,26 @@ struct ExchangeRowView: View { ) { EmptyView() }.frame(width: 0).opacity(0) }.listRowSeparator(.hidden) - HStack { // buttons just set "buttonSelected" so the NavigationLink will trigger - Button("Deposit\n\(currency)") { buttonSelected = 1 } - .multilineTextAlignment(.center) - .buttonStyle(TalerButtonStyle(type: .bordered)) - .disabled(true) // TODO: after implementing Deposit check available + let sendTitle = depositTitle + "\n" + currency // TODO: amount.currencyStr + let recvTitle = withdrawTitle + "\n" + currency // TODO: amount.currencyStr + if needVStack(currency) { + VStack { + TwoRowButtons(sendTitle: sendTitle, + recvTitle: recvTitle, + lineLimit: 5, sendDisabled: true, // TODO: amount.isZero + sendAction: { selectAndUpdate(1) }, + recvAction: { selectAndUpdate(2) }) + } + } else { + HStack { // buttons just set "buttonSelected" so the NavigationLink will trigger + TwoRowButtons(sendTitle: sendTitle, + recvTitle: recvTitle, + lineLimit: 5, sendDisabled: true, // TODO: amount.isZero + sendAction: { selectAndUpdate(1) }, + recvAction: { selectAndUpdate(2) }) - Button("Withdraw\n\(currency)") { buttonSelected = 2 } - .multilineTextAlignment(.center) - .buttonStyle(TalerButtonStyle(type: .bordered)) - }.listRowSeparator(.visible) -// .listRowSeparatorTint(.red) - .fixedSize(horizontal: false, vertical: true) + } + } } } /// This view shows the currency name in an exchange section