Skip to content

Commit

Permalink
Display an abstracted message for Sargon errors (#1179)
Browse files Browse the repository at this point in the history
  • Loading branch information
danvleju-rdx committed Jun 20, 2024
1 parent 8ec9a2b commit 9e5c192
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,11 @@ extension OverlayWindowClient {
extension OverlayWindowClient {
public enum Item: Sendable, Hashable {
public typealias AlertState = ComposableArchitecture.AlertState<AlertAction>
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<OverlayWindowClient.Item.AlertAction>] = [
.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)

Expand Down
7 changes: 7 additions & 0 deletions RadixWallet/Features/AppFeature/Overlay/Overlay+Reducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ struct OverlayReducer: Sendable, FeatureReducer {

@Dependency(\.overlayWindowClient) var overlayWindowClient
@Dependency(\.continuousClock) var clock
@Dependency(\.contactSupportClient) var contactSupport

var body: some ReducerOf<Self> {
Reduce(core)
Expand Down Expand Up @@ -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)):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public struct Troubleshooting: Sendable, FeatureReducer {

case .contactSupportButtonTapped:
return .run { _ in
await contactSupport.openEmail()
await contactSupport.openEmail(nil)
}

case .discordButtonTapped:
Expand Down

0 comments on commit 9e5c192

Please sign in to comment.