gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-taler-ios] 10/17: Improvements to error dialog


From: gnunet
Subject: [taler-taler-ios] 10/17: Improvements to error dialog
Date: Thu, 11 Apr 2024 23:13:42 +0200

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 fa746337d19502f678b9425a0be025745e1c2ba5
Author: Iván Ávalos <avalos@disroot.org>
AuthorDate: Fri Mar 22 09:15:24 2024 -0600

    Improvements to error dialog
---
 TalerWallet1/Backend/WalletBackendError.swift      |  1 +
 TalerWallet1/Backend/WalletCore.swift              |  4 +
 TalerWallet1/Helper/Encodable+toJSON.swift         |  3 +
 TalerWallet1/Views/Main/MainView.swift             |  6 +-
 TalerWallet1/Views/Sheets/ErrorSheet.swift         | 89 ++++++++++++----------
 .../Views/Sheets/Payment/PayTemplateV.swift        |  2 +
 TalerWallet1/Views/Sheets/Sheet.swift              |  2 +-
 7 files changed, 63 insertions(+), 44 deletions(-)

diff --git a/TalerWallet1/Backend/WalletBackendError.swift 
b/TalerWallet1/Backend/WalletBackendError.swift
index 785cc69..1465988 100644
--- a/TalerWallet1/Backend/WalletBackendError.swift
+++ b/TalerWallet1/Backend/WalletBackendError.swift
@@ -4,6 +4,7 @@
  */
 /**
  * @author Marc Stibane
+ * @author Iván Ávalos
  */
 import Foundation
 
diff --git a/TalerWallet1/Backend/WalletCore.swift 
b/TalerWallet1/Backend/WalletCore.swift
index 1c10c71..20c614f 100644
--- a/TalerWallet1/Backend/WalletCore.swift
+++ b/TalerWallet1/Backend/WalletCore.swift
@@ -2,6 +2,10 @@
  * This file is part of GNU Taler, ©2022-23 Taler Systems S.A.
  * See LICENSE.md
  */
+/**
+ * @author Marc Stibane
+ * @author Iván Ávalos
+ */
 import SwiftUI              // FOUNDATION has no AppStorage
 import AnyCodable
 import FTalerWalletcore
diff --git a/TalerWallet1/Helper/Encodable+toJSON.swift 
b/TalerWallet1/Helper/Encodable+toJSON.swift
index 58fac4e..b2ffc74 100644
--- a/TalerWallet1/Helper/Encodable+toJSON.swift
+++ b/TalerWallet1/Helper/Encodable+toJSON.swift
@@ -2,6 +2,9 @@
  * This file is part of GNU Taler, ©2022-23 Taler Systems S.A.
  * See LICENSE.md
  */
+/**
+ * @author Iván Ávalos
+ */
 import Foundation
 
 extension Encodable {
diff --git a/TalerWallet1/Views/Main/MainView.swift 
b/TalerWallet1/Views/Main/MainView.swift
index f376643..168b548 100644
--- a/TalerWallet1/Views/Main/MainView.swift
+++ b/TalerWallet1/Views/Main/MainView.swift
@@ -2,6 +2,10 @@
  * This file is part of GNU Taler, ©2022-23 Taler Systems S.A.
  * See LICENSE.md
  */
+/**
+ * @author Marc Stibane
+ * @author Iván Ávalos
+ */
 import SwiftUI
 import os.log
 import SymLog
@@ -83,7 +87,7 @@ struct MainView: View {
             if let error = model.error {
                 ErrorSheet(data: error, devMode: developerMode) {
                     model.cleanError()
-                }
+                }.interactiveDismissDisabled()
             }
         }
     } // body
diff --git a/TalerWallet1/Views/Sheets/ErrorSheet.swift 
b/TalerWallet1/Views/Sheets/ErrorSheet.swift
index 9164d0a..d6d2d1e 100644
--- a/TalerWallet1/Views/Sheets/ErrorSheet.swift
+++ b/TalerWallet1/Views/Sheets/ErrorSheet.swift
@@ -2,20 +2,25 @@
  * This file is part of GNU Taler, ©2022-23 Taler Systems S.A.
  * See LICENSE.md
  */
+/**
+ * @author Iván Ávalos
+ */
 import SwiftUI
 
 enum ErrorData {
-case message(String)
+case message(title: String, message: String)
 case error(Error)
 }
 
 struct ErrorSheet: View {
-    var message: String
+    var title: String
+    var message: String? = nil
     var copyable: Bool
 
     var onDismiss: () -> Void
 
-    init(message: String, copyable: Bool, onDismiss: @escaping () -> Void) {
+    init(title: String, message: String? = nil, copyable: Bool, onDismiss: 
@escaping () -> Void) {
+        self.title = title
         self.message = message
         self.copyable = copyable
         self.onDismiss = onDismiss
@@ -26,27 +31,30 @@ struct ErrorSheet: View {
         let initializationError = String(localized: "Initialization error")
         let serializationError = String(localized: "Serialization error")
         let deserializationError = String(localized: "Deserialization error")
+        let unknownError = String(localized: "Unknown error")
 
         switch error {
         case let walletError as WalletBackendError:
             switch walletError {
             case .walletCoreError(let error):
                 if let json = error?.toJSON(), devMode {
-                    self.init(message: json, copyable: true, onDismiss: 
onDismiss)
+                    self.init(title: walletCoreError, message: json, copyable: 
true, onDismiss: onDismiss)
+                } else if let hint = error?.hint {
+                    self.init(title: walletCoreError, message: hint, copyable: 
false, onDismiss: onDismiss)
                 } else if let message = error?.message {
-                    self.init(message: message, copyable: false, onDismiss: 
onDismiss)
+                    self.init(title: walletCoreError, message: message, 
copyable: false, onDismiss: onDismiss)
                 } else {
-                    self.init(message: walletCoreError, copyable: false, 
onDismiss: onDismiss)
+                    self.init(title: walletCoreError, copyable: false, 
onDismiss: onDismiss)
                 }
             case .initializationError:
-                self.init(message: initializationError, copyable: false, 
onDismiss: onDismiss)
+                self.init(title: initializationError, copyable: false, 
onDismiss: onDismiss)
             case .serializationError:
-                self.init(message: serializationError, copyable: false, 
onDismiss: onDismiss)
+                self.init(title: serializationError, copyable: false, 
onDismiss: onDismiss)
             case .deserializationError:
-                self.init(message: deserializationError, copyable: false, 
onDismiss: onDismiss)
+                self.init(title: deserializationError, copyable: false, 
onDismiss: onDismiss)
             }
         default:
-            self.init(message: error.localizedDescription, copyable: false, 
onDismiss: onDismiss)
+            self.init(title: unknownError, message: 
error.localizedDescription, copyable: false, onDismiss: onDismiss)
         }
     }
 
@@ -54,54 +62,51 @@ struct ErrorSheet: View {
         let unknownError = String(localized: "Unknown error")
 
         switch data {
-        case .message(let message):
-            self.init(message: message, copyable: false, onDismiss: onDismiss)
+        case .message(let title, let message):
+            self.init(title: title, message: message, copyable: false, 
onDismiss: onDismiss)
             return
         case .error(let error):
             self.init(error: error, devMode: devMode, onDismiss: onDismiss)
             return
         }
 
-        self.init(message: unknownError, copyable: false, onDismiss: onDismiss)
+        self.init(title: unknownError, copyable: false, onDismiss: onDismiss)
     }
 
     var body: some View {
-        NavigationView {
-            GeometryReader { geometry in
-                ScrollView(.vertical) {
-                    VStack {
-                        Image(systemName: "exclamationmark.circle.fill")
-                            .resizable()
-                            .frame(width: 100, height: 100)
-                            .aspectRatio(contentMode: .fit)
-                            .foregroundStyle(.red)
-                            .padding(.bottom)
-
-                        Text("There was an error!")
-                            .talerFont(.title)
-                            .padding(.bottom)
+        ScrollView {
+            VStack {
+                Image(systemName: "exclamationmark.circle")
+                    .resizable()
+                    .frame(width: 50, height: 50)
+                    .aspectRatio(contentMode: .fit)
+                    .foregroundStyle(.red)
+                    .padding()
 
-                        if copyable {
-                            if #available(iOS 16.4, *) {
-                                Text(message).monospaced()
-                            } else {
-                                Text(message).font(.system(.body, design: 
.monospaced))
-                            }
+                Text(title)
+                    .talerFont(.title)
+                    .padding(.bottom)
 
-                            CopyButton(textToCopy: message, vertical: false)
-                                .accessibilityLabel("Copy the error JSON")
-                                .padding(.top)
+                if let message {
+                    if copyable {
+                        if #available(iOS 16.4, *) {
+                            Text(message).monospaced()
                         } else {
-                            Text(message)
-                                .multilineTextAlignment(.center)
+                            Text(message).font(.system(.body, design: 
.monospaced))
                         }
+
+                        CopyButton(textToCopy: message, vertical: false)
+                            .accessibilityLabel("Copy the error JSON")
+                            .padding()
+                    } else {
+                        Text(message)
+                            .multilineTextAlignment(.center)
                     }
-                    .padding()
-                    .frame(width: geometry.size.width)
-                    .frame(minHeight: geometry.size.height)
                 }
             }
-        }.safeAreaInset(edge: .bottom) {
+        }
+        .padding()
+        .safeAreaInset(edge: .bottom) {
             Button("Close", role: .cancel) {
                 onDismiss()
             }
diff --git a/TalerWallet1/Views/Sheets/Payment/PayTemplateV.swift 
b/TalerWallet1/Views/Sheets/Payment/PayTemplateV.swift
index 0f6158f..b60b267 100644
--- a/TalerWallet1/Views/Sheets/Payment/PayTemplateV.swift
+++ b/TalerWallet1/Views/Sheets/Payment/PayTemplateV.swift
@@ -109,6 +109,8 @@ struct PayTemplateV: View {
             preparePayResult = ppCheck
         } catch {    // TODO: error
             symLog.log(error.localizedDescription)
+            model.showError(.error(error))
+            controller.playSound(0)
         }
     }
 
diff --git a/TalerWallet1/Views/Sheets/Sheet.swift 
b/TalerWallet1/Views/Sheets/Sheet.swift
index 95da489..a0f2da6 100644
--- a/TalerWallet1/Views/Sheets/Sheet.swift
+++ b/TalerWallet1/Views/Sheets/Sheet.swift
@@ -41,9 +41,9 @@ struct Sheet: View {
                     }
                 } else {
                     sheetView
+                        .navigationBarItems(leading: cancelButton)
                 }
             }
-                .navigationBarItems(leading: cancelButton)
                 .navigationBarTitleDisplayMode(.automatic)
                 
.background(WalletColors().backgroundColor.edgesIgnoringSafeArea(.all))
         }

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]