[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-taler-ios] 32/69: Warnings for tx buttons
From: |
gnunet |
Subject: |
[taler-taler-ios] 32/69: Warnings for tx buttons |
Date: |
Fri, 19 Jan 2024 09:02:05 +0100 |
This is an automated email from the git hooks/post-receive script.
marc-stibane pushed a commit to branch master
in repository taler-ios.
commit b1b30fabfa5664009d93eafc66d13306bfe9634b
Author: Marc Stibane <marc@taler.net>
AuthorDate: Thu Jan 4 17:52:36 2024 +0100
Warnings for tx buttons
---
.../Views/HelperViews/TransactionButton.swift | 53 ++++++++++++++++------
TalerWallet1/Views/Settings/SettingsView.swift | 19 ++++++--
2 files changed, 53 insertions(+), 19 deletions(-)
diff --git a/TalerWallet1/Views/HelperViews/TransactionButton.swift
b/TalerWallet1/Views/HelperViews/TransactionButton.swift
index 40b0c5e..2f1674a 100644
--- a/TalerWallet1/Views/HelperViews/TransactionButton.swift
+++ b/TalerWallet1/Views/HelperViews/TransactionButton.swift
@@ -7,12 +7,30 @@ import taler_swift
import AVFoundation
struct TransactionButton: View {
- let transactionId : String
- let command : TxAction
+ let transactionId: String
+ let command: TxAction
+ let warning: String?
let action: (_ transactionId: String) async throws -> Void
- @State var disabled: Bool = false
- @State var executed: Bool = false
+ @AppStorage("shouldShowWarning") var shouldShowWarning: Bool = true
+
+ @State private var disabled: Bool = false
+ @State private var executed: Bool = false
+ @State private var showAlert: Bool = false
+
+ private func doAction() {
+ disabled = true // don't try this more than once
+ Task { // runs on MainActor
+ do {
+ try await action(transactionId)
+// symLog.log("\(executed) \(transactionId)")
+ executed = true
+ } catch { // TODO: error
+// symLog.log(error.localizedDescription)
+ }
+ }
+ }
+
var body: some View {
let isDestructive = (command == .delete) || (command == .fail)
let isCancel = (command == .abort)
@@ -21,15 +39,10 @@ struct TransactionButton: View {
: nil
Button(role: role, action: {
if !disabled {
- disabled = true // don't try this more than once
- Task { // runs on MainActor
- do {
- try await action(transactionId)
-// symLog.log("\(executed) \(transactionId)")
- executed = true
- } catch { // TODO: error
-// symLog.log(error.localizedDescription)
- }
+ if shouldShowWarning && (isDestructive || isCancel) {
+ showAlert = true
+ } else {
+ doAction()
}
}
}, label: {
@@ -46,6 +59,16 @@ struct TransactionButton: View {
.buttonStyle(.bordered)
.controlSize(.large)
.disabled(disabled)
+ .alert(warning ?? EMPTYSTRING, isPresented: $showAlert, actions: {
+ Button("Cancel", role: .cancel) {
+ showAlert = false
+ }
+ Button(command.localizedActionTitle) {
+ showAlert = false
+ doAction()
+ }
+ }, message: { Text("This operation cannot be undone") }
+ )
}
}
// MARK: -
@@ -58,7 +81,9 @@ struct TransactionButton_Previews: PreviewProvider {
static var previews: some View {
List {
- TransactionButton(transactionId: "Button pressed", command:
.abort, action: action)
+ TransactionButton(transactionId: "Button pressed", command: .abort,
+ warning: "Are you sure you want to abort this
transaction?",
+ action: action)
}
}
}
diff --git a/TalerWallet1/Views/Settings/SettingsView.swift
b/TalerWallet1/Views/Settings/SettingsView.swift
index 777bc3a..4782328 100644
--- a/TalerWallet1/Views/Settings/SettingsView.swift
+++ b/TalerWallet1/Views/Settings/SettingsView.swift
@@ -31,6 +31,8 @@ struct SettingsView: View {
@AppStorage("useHaptics") var useHaptics: Bool = true
@AppStorage("playSoundsI") var playSoundsI: Int = 1
@AppStorage("playSoundsB") var playSoundsB: Bool = true
+ @AppStorage("shouldShowWarning") var shouldShowWarning: Bool = true
+// @AppStorage("increaseContrast") var increaseContrast: Bool = false
@AppStorage("talerFont") var talerFont: Int = 0
@AppStorage("developDelay") var developDelay: Bool = false
@AppStorage("myListStyle") var myListStyle: MyListStyle = .automatic
@@ -101,12 +103,13 @@ struct SettingsView: View {
description: hideDescriptions ? nil :
String(localized: "More info about this app...")) {}
}
#if DEBUG
- Group {
+ if showDevelopItems {
Text("https://bank.taler.grothoff.org/")
Text("https://bank.taler.fdold.eu/")
Text("https://bank.head.taler.net/")
Text("https://bank.test.taler.net/")
Text("https://bank.demo.taler.net/")
+ Text("https://bank.taler.ar/")
}
#endif
if controller.hapticCapability.supportsHaptics {
@@ -120,14 +123,20 @@ struct SettingsView: View {
#if DEBUG
if Double.random(in: -100.0...100.0) > 0 {
SettingsSpeaker(name: String(localized: "Play Payment
Sounds"), value: $playSoundsI,
- description: hideDescriptions ? nil :
String(localized: "When a transaction finished"))
- .id("playSounds")
- SettingsFont(title: String(localized: "Font:"), value:
talerFont, action: redraw)
- .id("font")
+ description: hideDescriptions ? nil :
String(localized: "When a transaction finished"))
+ .id("playSounds")
} else { playToggle }
#else
playToggle
#endif
+// SettingsToggle(name: String(localized: "Increase Contrast"),
value: $increaseContrast, id1: "contrast",
+// description: hideDescriptions ? nil :
String(localized: "If you don't want to set it globally in Settings.app"))
+// .id("increaseContrast")
+ SettingsToggle(name: String(localized: "Show Warnings"),
value: $shouldShowWarning, id1: "warnings",
+ description: hideDescriptions ? nil :
String(localized: "For Delete, Fail & Abort buttons"))
+ .id("showWarnings")
+// SettingsFont(title: String(localized: "Font:"), value:
talerFont, action: redraw)
+// .id("font")
SettingsStyle(title: String(localized: "Liststyle:"),
myListStyle: $myListStyle)
.id("liststyle")
SettingsToggle(name: String(localized: "Minimalistic"), value:
$iconOnly, id1: "minimal",
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [taler-taler-ios] 05/69: ToS language, (continued)
- [taler-taler-ios] 05/69: ToS language, gnunet, 2024/01/19
- [taler-taler-ios] 19/69: cleanup, gnunet, 2024/01/19
- [taler-taler-ios] 02/69: LoadingView, gnunet, 2024/01/19
- [taler-taler-ios] 12/69: PRINT_CHANGES, gnunet, 2024/01/19
- [taler-taler-ios] 07/69: Haptics, gnunet, 2024/01/19
- [taler-taler-ios] 31/69: Withdraw only once, gnunet, 2024/01/19
- [taler-taler-ios] 22/69: Summary in ThreeAmountsV, gnunet, 2024/01/19
- [taler-taler-ios] 30/69: Layout Balances, gnunet, 2024/01/19
- [taler-taler-ios] 20/69: button color if disabled, gnunet, 2024/01/19
- [taler-taler-ios] 10/69: Exchanges->Banking, gnunet, 2024/01/19
- [taler-taler-ios] 32/69: Warnings for tx buttons,
gnunet <=
- [taler-taler-ios] 16/69: remove about protocols, gnunet, 2024/01/19
- [taler-taler-ios] 18/69: ToS for P2P, gnunet, 2024/01/19
- [taler-taler-ios] 29/69: clearDb (instead of reset), gnunet, 2024/01/19
- [taler-taler-ios] 27/69: use minor for Status, gnunet, 2024/01/19
- [taler-taler-ios] 14/69: remove Apple Sounds, gnunet, 2024/01/19
- [taler-taler-ios] 21/69: TransactionDone popToRootView, gnunet, 2024/01/19
- [taler-taler-ios] 09/69: API 2:0:1, gnunet, 2024/01/19
- [taler-taler-ios] 15/69: hapticFeedback, gnunet, 2024/01/19
- [taler-taler-ios] 08/69: fixes, gnunet, 2024/01/19
- [taler-taler-ios] 11/69: Landscape, gnunet, 2024/01/19