commit b21d9f2e47a260d1a9101f63442ad6c4e488bd84 parent 6f0d9e24c69adbb5ac1b69021a80829f0eaf81e7 Author: Marc Stibane <marc@taler.net> Date: Tue, 15 Oct 2024 09:43:02 +0200 cleanup, remove warning Diffstat:
16 files changed, 196 insertions(+), 232 deletions(-)
diff --git a/TalerWallet.xcodeproj/project.pbxproj b/TalerWallet.xcodeproj/project.pbxproj @@ -816,7 +816,6 @@ 4EB0953A2989CBFE0043A8A1 /* BalancesSectionView.swift */, 4E77976E2C4BEA4E005D6ECB /* BalanceCellV.swift */, 4E448AB62C4A4109007D5C92 /* BalancesPendingRowV.swift */, - 4EB065432A4CD1A80039B91D /* TwoRowButtons.swift */, 4EB095382989CBFE0043A8A1 /* PendingRowView.swift */, ); path = Balances; @@ -893,6 +892,7 @@ 4E2B337C2C8B1D5500186A3E /* ActionsSheet.swift */, 4EB095362989CBFE0043A8A1 /* SendRequestV.swift */, 4EA076B22BC0607400685A10 /* DepositWithdrawV.swift */, + 4EB065432A4CD1A80039B91D /* TwoRowButtons.swift */, 4ECB627E2A0BA4DA004ABBB7 /* Peer2peer */, ); path = Actions; diff --git a/TalerWallet1/Controllers/Controller.swift b/TalerWallet1/Controllers/Controller.swift @@ -50,7 +50,6 @@ class Controller: ObservableObject { private let symLog = SymLogC() @Published var backendState: BackendState = .none // only used for launch animation - @Published var frontendState: Int = 0 // 1 incoming, -1 outgoing, 0 Balances @Published var currencyTicker: Int = 0 // updates whenever a new currency is added @Published var isConnected: Bool = true @AppStorage("useHaptics") var useHaptics: Bool = true // extension mustn't define this, so it must be here diff --git a/TalerWallet1/Views/Actions/DepositWithdrawV.swift b/TalerWallet1/Views/Actions/DepositWithdrawV.swift @@ -12,15 +12,12 @@ import SymLog struct DepositWithdrawV: View { private let symLog = SymLogV(0) let stack: CallStack - let sendDisabled: Bool + let sendDisabled: Bool // can't send/deposit if wallet has no coins - @EnvironmentObject private var model: WalletModel - @AppStorage("minimalistic") var minimalistic: Bool = false - - func selectAndUpdate(_ button: Int) { + @MainActor + func dismissAndPost(_ name: NSNotification.Name) { dismissTop(stack.push()) - NotificationCenter.default.post(name: button == 3 ? .DepositAction : .WithdrawAction, - object: nil) // will trigger NavigationLink + NotificationCenter.default.post(name: name, object: nil) // will trigger NavigationLink } var body: some View { @@ -31,13 +28,12 @@ struct DepositWithdrawV: View { TwoRowButtons(stack: stack.push(), sendTitle: depositTitle, sendType: .deposit, - sendA11y: depositTitle,//1.tabbed(oneLine: true), + sendA11y: depositTitle, recvTitle: withdrawTitle, recvType: .withdrawal, - recvA11y: withdrawTitle,//1.tabbed(oneLine: true), - lineLimit: 5, + recvA11y: withdrawTitle, sendDisabled: sendDisabled, - sendAction: { selectAndUpdate(3) }, - recvAction: { selectAndUpdate(4) }) + sendAction: { dismissAndPost(.DepositAction) }, + recvAction: { dismissAndPost(.WithdrawAction) }) } } diff --git a/TalerWallet1/Views/Actions/Peer2peer/P2PReadyV.swift b/TalerWallet1/Views/Actions/Peer2peer/P2PReadyV.swift @@ -57,7 +57,7 @@ struct P2PReadyV: View { .navigationBarBackButtonHidden(true) .interactiveDismissDisabled() // can only use "Done" button to dismiss .safeAreaInset(edge: .bottom) { - Button("Done", action: { dismissTop(stack.push()) } ) + Button("Done") { dismissTop(stack.push()) } .buttonStyle(TalerButtonStyle(type: .prominent)) .padding(.horizontal) } diff --git a/TalerWallet1/Views/Actions/Peer2peer/RequestPayment.swift b/TalerWallet1/Views/Actions/Peer2peer/RequestPayment.swift @@ -230,7 +230,6 @@ struct RequestPaymentContent: View { .navigationTitle(navTitle) .onAppear { DebugViewC.shared.setViewID(VIEW_P2P_REQUEST, stack: stack.push()) - // if we set >> controller.frontendState = 1 << here, then becomeFirstResponder won't work! symLog.log("❗️ \(navTitle) onAppear") } .onDisappear { diff --git a/TalerWallet1/Views/Actions/Peer2peer/SendAmountV.swift b/TalerWallet1/Views/Actions/Peer2peer/SendAmountV.swift @@ -262,7 +262,6 @@ struct SendAmountContent: View { } .onAppear { DebugViewC.shared.setViewID(VIEW_P2P_SEND, stack: stack.push()) - // if we set >> controller.frontendState = -1 << here, then becomeFirstResponder won't work! symLog.log("❗️ \(navTitle) onAppear") } .onDisappear { diff --git a/TalerWallet1/Views/Actions/SendRequestV.swift b/TalerWallet1/Views/Actions/SendRequestV.swift @@ -12,16 +12,12 @@ import SymLog struct SendRequestV: View { private let symLog = SymLogV(0) let stack: CallStack - let sendDisabled: Bool + let sendDisabled: Bool // can't send/deposit if wallet has no coins - @EnvironmentObject private var model: WalletModel - @EnvironmentObject private var controller: Controller - @AppStorage("minimalistic") var minimalistic: Bool = false - - func selectAndUpdate(_ button: Int) { + @MainActor + func dismissAndPost(_ name: NSNotification.Name) { dismissTop(stack.push()) - NotificationCenter.default.post(name: button == 1 ? .SendAction : .RequestAction, - object: nil) // will trigger NavigationLink + NotificationCenter.default.post(name: name, object: nil) // will trigger NavigationLink } var body: some View { @@ -32,13 +28,12 @@ struct SendRequestV: View { TwoRowButtons(stack: stack.push(), sendTitle: sendTitle, sendType: .peerPushDebit, - sendA11y: sendTitle,//1.tabbed(oneLine: true), + sendA11y: sendTitle, recvTitle: requTitle, recvType: .peerPullCredit, - recvA11y: requTitle,//1.tabbed(oneLine: true), - lineLimit: 5, + recvA11y: requTitle, sendDisabled: sendDisabled, - sendAction: { controller.frontendState = -1; selectAndUpdate(1) }, - recvAction: { controller.frontendState = 1; selectAndUpdate(2) }) + sendAction: { dismissAndPost(.SendAction) }, + recvAction: { dismissAndPost(.RequestAction) }) } } diff --git a/TalerWallet1/Views/Actions/TwoRowButtons.swift b/TalerWallet1/Views/Actions/TwoRowButtons.swift @@ -0,0 +1,172 @@ +/* + * This file is part of GNU Taler, ©2022-24 Taler Systems S.A. + * See LICENSE.md + */ +/** + * @author Marc Stibane + */ +import SwiftUI +import taler_swift + +let LINELIMIT = 5 + +struct TypeButton: View { + let title: String + let a11y: String + var type: TransactionType + let disabled: Bool + let action: () -> Void + + @AppStorage("minimalistic") var minimalistic: Bool = false + + var body: some View { +#if DEBUG + let debug = 1==0 + let red = debug ? Color.red : Color.clear + let green = debug ? Color.green : Color.clear + let blue = debug ? Color.blue : Color.clear + let orange = debug ? Color.orange : Color.clear +#endif + let badge = ButtonIconBadge(type: type, foreColor: .accentColor, done: false) + let hLayout = HStack { + badge + Spacer() + Text(title) + .fixedSize(horizontal: true, vertical: false) + Spacer() + } +#if DEBUG + .border(red) +#endif + + let vLayout = VStack { + let fragments = title.components(separatedBy: "\n") + if fragments.count > 1 { + Text(fragments[0]) + HStack { + badge + Spacer() + Text(fragments[1]) + .fixedSize(horizontal: true, vertical: false) + Spacer() + } +#if DEBUG + .border(orange) +#endif + if fragments.count > 2 { + Text(fragments[2]) +// .fixedSize(horizontal: true, vertical: false) +#if DEBUG + .border(green) +#endif + } + } else { + hLayout + } + } +#if DEBUG + .border(red) +#endif + + Button(action: action) { + if minimalistic { + badge + } else { + if #available(iOS 16.0, *) { + ViewThatFits(in: .horizontal) { + hLayout + vLayout + } + } else { vLayout } // view for iOS 15 + } + } + .accessibilityLabel(Text(a11y)) + .lineLimit(LINELIMIT) + .disabled(disabled) + .buttonStyle(TalerButtonStyle(type: .bordered, + dimmed: false, + disabled: disabled, + aligned: .center)) + } +} + + +struct TwoRowButtons: View { + let stack: CallStack + let sendTitle: String + var sendType: TransactionType + let sendA11y: String + let recvTitle: String + var recvType: TransactionType + let recvA11y: String + let sendDisabled: Bool + let sendAction: () -> Void + let recvAction: () -> Void + + func sendButton(_ title: String) -> TypeButton { + TypeButton(title: title, + a11y: sendA11y, + type: sendType, + disabled: sendDisabled, + action: sendAction) + } + + func recvButton(_ title: String) -> TypeButton { + TypeButton(title: title, + a11y: recvA11y, + type: recvType, + disabled: false, + action: recvAction) + } + + var body: some View { + let hLayout = HStack(spacing: HSPACING) { + // side by side, text in 1+ lines (\t -> \n) + sendButton(sendTitle.tabbed(oneLine: false)) + recvButton(recvTitle.tabbed(oneLine: false)) + } + let vLayout = VStack { + // one below the other, text in one line (\t -> " ") + sendButton(sendTitle.tabbed(oneLine: true)) + recvButton(recvTitle.tabbed(oneLine: true)) + } + + if #available(iOS 16.0, *) { + ViewThatFits(in: .horizontal) { + hLayout +// .border(.green) + vLayout +// .border(.red) + } + } else { vLayout } // iOS 15 has no ViewThatFits + } +} +// MARK: - +#if DEBUG +struct TwoRowButtons_Previews: PreviewProvider { + static var previews: some View { + List { + TwoRowButtons(stack: CallStack("Preview"), + sendTitle: "Send " + TESTCURRENCY, + sendType: .peerPushDebit, + sendA11y: "Send " + TESTCURRENCY, + recvTitle: "Request " + LONGCURRENCY, + recvType: .peerPullCredit, + recvA11y: "Request " + LONGCURRENCY, + sendDisabled: true, + sendAction: {}, recvAction: {}) + .listRowSeparator(.hidden) + TwoRowButtons(stack: CallStack("Preview"), + sendTitle: "Send " + DEMOCURRENCY, + sendType: .peerPushDebit, + sendA11y: "Send " + DEMOCURRENCY, + recvTitle: "Request " + DEMOCURRENCY, + recvType: .peerPullCredit, + recvA11y: "Request " + DEMOCURRENCY, + sendDisabled: true, + sendAction: {}, recvAction: {}) + .listRowSeparator(.hidden) + } + } +} +#endif diff --git a/TalerWallet1/Views/Balances/BalancesListView.swift b/TalerWallet1/Views/Balances/BalancesListView.swift @@ -66,7 +66,6 @@ struct BalancesListView: View { } .onAppear() { DebugViewC.shared.setViewID(VIEW_BALANCES, stack: stack.push("onAppear")) - controller.frontendState = 0 // neutral selectedBalance = nil } .listStyle(myListStyle.style).anyView diff --git a/TalerWallet1/Views/Balances/TwoRowButtons.swift b/TalerWallet1/Views/Balances/TwoRowButtons.swift @@ -1,176 +0,0 @@ -/* - * This file is part of GNU Taler, ©2022-24 Taler Systems S.A. - * See LICENSE.md - */ -/** - * @author Marc Stibane - */ -import SwiftUI -import taler_swift - -struct TypeButton: View { - let title: String - let a11y: String - let lineLimit: Int - var type: TransactionType - let disabled: Bool - let action: () -> Void - - @AppStorage("minimalistic") var minimalistic: Bool = false - - var body: some View { -#if DEBUG - let debug = 1==0 - let red = debug ? Color.red : Color.clear - let green = debug ? Color.green : Color.clear - let blue = debug ? Color.blue : Color.clear - let orange = debug ? Color.orange : Color.clear -#endif - let badge = ButtonIconBadge(type: type, foreColor: .accentColor, done: false) - let hLayout = HStack { - badge - Spacer() - Text(title) - .fixedSize(horizontal: true, vertical: false) - Spacer() - } -#if DEBUG - .border(red) -#endif - - let vLayout = VStack { - let fragments = title.components(separatedBy: "\n") - if fragments.count > 1 { - Text(fragments[0]) - HStack { - badge - Spacer() - Text(fragments[1]) - .fixedSize(horizontal: true, vertical: false) - Spacer() - } -#if DEBUG - .border(orange) -#endif - if fragments.count > 2 { - Text(fragments[2]) -// .fixedSize(horizontal: true, vertical: false) -#if DEBUG - .border(green) -#endif - } - } else { - hLayout - } - } -#if DEBUG - .border(red) -#endif - - Button(action: action) { - if minimalistic { - badge - } else { - if #available(iOS 16.0, *) { - ViewThatFits(in: .horizontal) { - hLayout - vLayout - } - } else { vLayout } // view for iOS 15 - } - } - .accessibilityLabel(Text(a11y)) - .lineLimit(lineLimit) - .disabled(disabled) - .buttonStyle(TalerButtonStyle(type: .bordered, - dimmed: false, - disabled: disabled, - aligned: .center)) - } -} - - -struct TwoRowButtons: View { - let stack: CallStack - let sendTitle: String - var sendType: TransactionType - let sendA11y: String - let recvTitle: String - var recvType: TransactionType - let recvA11y: String - let lineLimit: Int - let sendDisabled: Bool - let sendAction: () -> Void - let recvAction: () -> Void - - func sendButton(_ title: String) -> TypeButton { - TypeButton(title: title, - a11y: sendA11y, - lineLimit: lineLimit, - type: sendType, - disabled: sendDisabled, - action: sendAction) - } - - func recvButton(_ title: String) -> TypeButton { - TypeButton(title: title, - a11y: recvA11y, - lineLimit: lineLimit, - type: recvType, - disabled: false, - action: recvAction) - } - - var body: some View { - let hLayout = HStack(spacing: HSPACING) { - // side by side, text in 1+ lines (\t -> \n) - sendButton(sendTitle.tabbed(oneLine: false)) - recvButton(recvTitle.tabbed(oneLine: false)) - } - let vLayout = VStack { - // one below the other, text in one line (\t -> " ") - sendButton(sendTitle.tabbed(oneLine: true)) - recvButton(recvTitle.tabbed(oneLine: true)) - } - - if #available(iOS 16.0, *) { - ViewThatFits(in: .horizontal) { - hLayout -// .border(.green) - vLayout -// .border(.red) - } - } else { // iOS 15 has no ViewThatFits - vLayout - } - } -} -// MARK: - -#if DEBUG -struct TwoRowButtons_Previews: PreviewProvider { - static var previews: some View { - List { - TwoRowButtons(stack: CallStack("Preview"), - sendTitle: "Send " + TESTCURRENCY, - sendType: .peerPushDebit, - sendA11y: "Send " + TESTCURRENCY, - recvTitle: "Request " + LONGCURRENCY, - recvType: .peerPullCredit, - recvA11y: "Request " + LONGCURRENCY, - lineLimit: 2, sendDisabled: true, - sendAction: {}, recvAction: {}) - .listRowSeparator(.hidden) - TwoRowButtons(stack: CallStack("Preview"), - sendTitle: "Send " + DEMOCURRENCY, - sendType: .peerPushDebit, - sendA11y: "Send " + DEMOCURRENCY, - recvTitle: "Request " + DEMOCURRENCY, - recvType: .peerPullCredit, - recvA11y: "Request " + DEMOCURRENCY, - lineLimit: 2, sendDisabled: true, - sendAction: {}, recvAction: {}) - .listRowSeparator(.hidden) - } - } -} -#endif diff --git a/TalerWallet1/Views/Banking/ManualWithdrawDone.swift b/TalerWallet1/Views/Banking/ManualWithdrawDone.swift @@ -51,7 +51,7 @@ struct ManualWithdrawDone: View { .interactiveDismissDisabled() // can only use "Done" button to dismiss // .navigationTitle(navTitle) .safeAreaInset(edge: .bottom) { - Button("Done", action: { dismissTop(stack.push()) } ) + Button("Done") { dismissTop(stack.push()) } .buttonStyle(TalerButtonStyle(type: .prominent)) .padding(.horizontal) } diff --git a/TalerWallet1/Views/Sheets/Payment/PaymentDone.swift b/TalerWallet1/Views/Sheets/Payment/PaymentDone.swift @@ -46,7 +46,7 @@ struct PaymentDone: View { .interactiveDismissDisabled() // can only use "Done" button to dismiss .navigationTitle(navTitle) .safeAreaInset(edge: .bottom) { - Button("Done", action: { dismissTop(stack.push()) } ) + Button("Done") { dismissTop(stack.push()) } .buttonStyle(TalerButtonStyle(type: .prominent)) .padding(.horizontal) } diff --git a/TalerWallet1/Views/Sheets/Refund/RefundURIView.swift b/TalerWallet1/Views/Sheets/Refund/RefundURIView.swift @@ -45,7 +45,7 @@ struct RefundURIView: View { suspendAction: model.suspendTransaction, resumeAction: model.resumeTransaction) .safeAreaInset(edge: .bottom) { - Button("Done", action: { dismissTop(stack.push()) } ) + Button("Done") { dismissTop(stack.push()) } .buttonStyle(TalerButtonStyle(type: .prominent)) .padding(.horizontal) } diff --git a/TalerWallet1/Views/Sheets/URLSheet.swift b/TalerWallet1/Views/Sheets/URLSheet.swift @@ -20,7 +20,6 @@ struct URLSheet: View { @EnvironmentObject private var controller: Controller @State private var amountToTransfer = Amount.zero(currency: EMPTYSTRING) @State private var summary = EMPTYSTRING - @State private var showAlert: Bool = false @State private var urlCommand: UrlCommand = .unknown let navTitle = String(localized: "Checking Link") @@ -30,8 +29,6 @@ struct URLSheet: View { let _ = Self._printChanges() let _ = symLog.vlog() // just to get the # to compare it with .onAppear & onDisappear #endif - let warning = String(localized: "It seems you wanted to request money - but this transaction will let you pay...") - Group { switch urlCommand { case .termsExchange, // TODO: just check the ToS @@ -65,24 +62,8 @@ struct URLSheet: View { } .task { let command = controller.openURL(urlToOpen, stack: stack.push()) - if shouldShowWarning { - let incomingExpected = controller.frontendState == 1 - if incomingExpected && command.isOutgoing { - showAlert = true - } - } urlCommand = command } - .alert(warning, isPresented: $showAlert, actions: { - Button("Cancel", role: .cancel) { - showAlert = false - dismissTop(stack.push()) - } - Button("OK") { - showAlert = false - } - }, message: { Text("\nWarnings can be switched off in Settings") } - ) } } // MARK: - diff --git a/TalerWallet1/Views/Sheets/WithdrawBankIntegrated/WithdrawAcceptDone.swift b/TalerWallet1/Views/Sheets/WithdrawBankIntegrated/WithdrawAcceptDone.swift @@ -55,11 +55,11 @@ struct WithdrawAcceptDone: View { .navigationTitle(navTitle) .safeAreaInset(edge: .bottom) { if let transaction { - Button(transaction.shouldConfirm ? "Authorize later" : "Done", action: { dismissTop(stack.push()) } ) + Button(transaction.shouldConfirm ? "Authorize later" : "Done") { dismissTop(stack.push()) } .buttonStyle(TalerButtonStyle(type: transaction.shouldConfirm ? .bordered : .prominent)) .padding(.horizontal) } else { - Button("Cancel", action: { dismissTop(stack.push()) } ) + Button("Cancel") { dismissTop(stack.push()) } .buttonStyle(TalerButtonStyle(type: .bordered)) .padding(.horizontal) } diff --git a/TalerWallet1/Views/Transactions/ThreeAmountsSection.swift b/TalerWallet1/Views/Transactions/ThreeAmountsSection.swift @@ -196,7 +196,7 @@ struct ThreeAmounts_Previews: PreviewProvider { topTitle: "Withdrawal", baseURL: DEMOEXCHANGE, noFees: false, large: 1==0, summary: nil, merchant: nil) .safeAreaInset(edge: .bottom) { - Button(String(localized: "Accept"), action: {}) + Button(String("Preview")) {} .buttonStyle(TalerButtonStyle(type: .prominent)) .padding(.horizontal) .disabled(true)