From 9e5c19281133cf2a90e6dd7b19ad8c745f90f8f4 Mon Sep 17 00:00:00 2001 From: danvleju-rdx <163979791+danvleju-rdx@users.noreply.github.com> Date: Thu, 20 Jun 2024 18:01:18 +0300 Subject: [PATCH] Display an abstracted message for Sargon errors (#1179) --- .../ContactSupportClient+Live.swift | 8 +++--- .../ContactSupportClient.swift | 2 +- .../OverlayWindowClient+Interface.swift | 3 ++- .../OverlayWindowClient+Live.swift | 27 ++++++++++++++++--- .../AppFeature/Overlay/Overlay+Reducer.swift | 7 +++++ .../Troubleshooting/Troubleshooting.swift | 2 +- 6 files changed, 38 insertions(+), 11 deletions(-) diff --git a/RadixWallet/Clients/ContactSupportClient/ContactSupportClient+Live.swift b/RadixWallet/Clients/ContactSupportClient/ContactSupportClient+Live.swift index 97418972db..d9a54c807f 100644 --- a/RadixWallet/Clients/ContactSupportClient/ContactSupportClient+Live.swift +++ b/RadixWallet/Clients/ContactSupportClient/ContactSupportClient+Live.swift @@ -8,18 +8,18 @@ extension ContactSupportClient: DependencyKey { @Dependency(\.bundleInfo) var bundleInfo @Sendable - func buildBody() async -> String { + func buildBody(additionalInfo: String?) async -> String { let version = bundleInfo.shortVersion let model = await device.localizedModel let systemVersion = await device.systemVersion - return "\n\nApp version: \(version)\nDevice: \(model)\nSystem version: \(systemVersion)" + return "\n\nApp version: \(version)\nDevice: \(model)\nSystem version: \(systemVersion)\n\(additionalInfo ?? "")" } return .init( - openEmail: { + openEmail: { additionalBodyInfo in let uiApplicaition = await UIApplication.shared - let body = await buildBody() + let body = await buildBody(additionalInfo: additionalBodyInfo) for app in EmailApp.allCases { if let url = app.build(body: body), await uiApplicaition.canOpenURL(url) { diff --git a/RadixWallet/Clients/ContactSupportClient/ContactSupportClient.swift b/RadixWallet/Clients/ContactSupportClient/ContactSupportClient.swift index eb1425514d..3641e2b136 100644 --- a/RadixWallet/Clients/ContactSupportClient/ContactSupportClient.swift +++ b/RadixWallet/Clients/ContactSupportClient/ContactSupportClient.swift @@ -11,7 +11,7 @@ struct ContactSupportClient: Sendable { // MARK: ContactSupportClient.OpenEmail extension ContactSupportClient { - typealias OpenEmail = @Sendable () async -> Void + typealias OpenEmail = @Sendable (_ additionalBodyInfo: String?) async -> Void } extension DependencyValues { diff --git a/RadixWallet/Clients/OverlayWindowClient/OverlayWindowClient+Interface.swift b/RadixWallet/Clients/OverlayWindowClient/OverlayWindowClient+Interface.swift index 89da18b1ac..54e8c9b649 100644 --- a/RadixWallet/Clients/OverlayWindowClient/OverlayWindowClient+Interface.swift +++ b/RadixWallet/Clients/OverlayWindowClient/OverlayWindowClient+Interface.swift @@ -71,10 +71,11 @@ extension OverlayWindowClient { extension OverlayWindowClient { public enum Item: Sendable, Hashable { public typealias AlertState = ComposableArchitecture.AlertState - public enum AlertAction: Sendable, Equatable { + public enum AlertAction: Sendable, Hashable { case primaryButtonTapped case secondaryButtonTapped case dismissed + case emailSupport(additionalInfo: String) } public struct HUD: Sendable, Hashable, Identifiable { diff --git a/RadixWallet/Clients/OverlayWindowClient/OverlayWindowClient+Live.swift b/RadixWallet/Clients/OverlayWindowClient/OverlayWindowClient+Live.swift index 2202bd829e..0b06b921a9 100644 --- a/RadixWallet/Clients/OverlayWindowClient/OverlayWindowClient+Live.swift +++ b/RadixWallet/Clients/OverlayWindowClient/OverlayWindowClient+Live.swift @@ -10,10 +10,29 @@ extension OverlayWindowClient: DependencyKey { @Dependency(\.pasteboardClient) var pasteBoardClient errorQueue.errors().map { error in - Item.alert(.init( - title: { TextState(L10n.Common.errorAlertTitle) }, - message: { TextState(error.localizedDescription) } - )) + if let sargonError = error as? SargonError { + #if DEBUG + let message = error.localizedDescription + #else + let message = L10n.Error.emailSupportMessage(sargonError.errorCode) + #endif + return Item.alert(.init( + title: { TextState(L10n.Common.errorAlertTitle) }, + actions: { + let buttons: [ButtonState] = [ + .init(role: .cancel, action: .dismissed, label: { TextState(L10n.Common.cancel) }), + .init(action: .emailSupport(additionalInfo: error.localizedDescription), label: { TextState(L10n.Error.emailSupportButtonTitle) }), + ] + return buttons + }, + message: { TextState(message) } + )) + } else { + return Item.alert(.init( + title: { TextState(L10n.Common.errorAlertTitle) }, + message: { TextState(error.localizedDescription) } + )) + } } .subscribe(items) diff --git a/RadixWallet/Features/AppFeature/Overlay/Overlay+Reducer.swift b/RadixWallet/Features/AppFeature/Overlay/Overlay+Reducer.swift index 99aa270184..f6e18bd1cf 100644 --- a/RadixWallet/Features/AppFeature/Overlay/Overlay+Reducer.swift +++ b/RadixWallet/Features/AppFeature/Overlay/Overlay+Reducer.swift @@ -49,6 +49,7 @@ struct OverlayReducer: Sendable, FeatureReducer { @Dependency(\.overlayWindowClient) var overlayWindowClient @Dependency(\.continuousClock) var clock + @Dependency(\.contactSupportClient) var contactSupport var body: some ReducerOf { Reduce(core) @@ -86,6 +87,12 @@ struct OverlayReducer: Sendable, FeatureReducer { if case let .alert(state) = state.itemsQueue.first { overlayWindowClient.sendAlertAction(action, state.id) } + if case let .emailSupport(additionalInfo) = action { + return .run { _ in + await contactSupport.openEmail(additionalInfo) + } + .concatenate(with: dismiss(&state)) + } return dismiss(&state) case .hud(.delegate(.dismiss)): diff --git a/RadixWallet/Features/SettingsFeature/Troubleshooting/Troubleshooting.swift b/RadixWallet/Features/SettingsFeature/Troubleshooting/Troubleshooting.swift index d5039e754e..dfc0039242 100644 --- a/RadixWallet/Features/SettingsFeature/Troubleshooting/Troubleshooting.swift +++ b/RadixWallet/Features/SettingsFeature/Troubleshooting/Troubleshooting.swift @@ -83,7 +83,7 @@ public struct Troubleshooting: Sendable, FeatureReducer { case .contactSupportButtonTapped: return .run { _ in - await contactSupport.openEmail() + await contactSupport.openEmail(nil) } case .discordButtonTapped: