From 82fb793e3b296b192f741785f32cffcf569693eb Mon Sep 17 00:00:00 2001 From: Josh Brown Date: Fri, 18 Oct 2024 15:34:16 -0400 Subject: [PATCH] show error alert if setting username fails --- Nos/Assets/Localization/Localizable.xcstrings | 24 +++++------ Nos/Views/Onboarding/DisplayNameView.swift | 2 +- Nos/Views/Onboarding/UsernameView.swift | 41 ++++++++----------- 3 files changed, 29 insertions(+), 38 deletions(-) diff --git a/Nos/Assets/Localization/Localizable.xcstrings b/Nos/Assets/Localization/Localizable.xcstrings index 66edf44a9..d12fd5ee2 100644 --- a/Nos/Assets/Localization/Localizable.xcstrings +++ b/Nos/Assets/Localization/Localizable.xcstrings @@ -5236,18 +5236,6 @@ } } }, - "displayNameError" : { - "comment" : "error message for when we can't set the display name in onboarding", - "extractionState" : "manual", - "localizations" : { - "en" : { - "stringUnit" : { - "state" : "translated", - "value" : "There is a problem connecting to the servers. You can skip for now and visit your Profile to update later." - } - } - } - }, "displayNameHeadline" : { "comment" : "headline for the display name screen in onboarding", "extractionState" : "manual", @@ -5782,6 +5770,18 @@ } } }, + "errorConnecting" : { + "comment" : "error message for when we can't set the display name or username in onboarding", + "extractionState" : "manual", + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "There is a problem connecting to the servers. You can skip for now and visit your Profile to update later." + } + } + } + }, "eventSource" : { "extractionState" : "manual", "localizations" : { diff --git a/Nos/Views/Onboarding/DisplayNameView.swift b/Nos/Views/Onboarding/DisplayNameView.swift index 45a67fe75..7d7a8d712 100644 --- a/Nos/Views/Onboarding/DisplayNameView.swift +++ b/Nos/Views/Onboarding/DisplayNameView.swift @@ -25,7 +25,7 @@ struct DisplayNameView: View { } } .navigationBarHidden(true) - .alert("displayNameError", isPresented: $showError) { + .alert("errorConnecting", isPresented: $showError) { Button { nextStep() } label: { diff --git a/Nos/Views/Onboarding/UsernameView.swift b/Nos/Views/Onboarding/UsernameView.swift index 881cee64e..e22b61996 100644 --- a/Nos/Views/Onboarding/UsernameView.swift +++ b/Nos/Views/Onboarding/UsernameView.swift @@ -8,7 +8,7 @@ fileprivate enum UsernameViewState { case loading case verificationFailed case claimed - case claimFailed + case errorAlert } /// The Username view in the onboarding. @@ -26,9 +26,9 @@ struct UsernameView: View { private var showAlert: Binding { Binding { - saveError != nil + usernameState == .errorAlert } set: { _ in - saveError = nil + usernameState = .idle } } @@ -57,19 +57,11 @@ struct UsernameView: View { } } .navigationBarHidden(true) - .alert(isPresented: showAlert, error: saveError) { + .alert("errorConnecting", isPresented: showAlert) { Button { - saveError = nil - Task { - await save() - } - } label: { - Text("retry") - } - Button { - saveError = nil + nextStep() } label: { - Text("cancel") + Text("skipForNow") } } } @@ -111,7 +103,7 @@ struct UsernameView: View { } Spacer() BigActionButton("next") { - await next() + await verifyAndSave() } .disabled(nextButtonDisabled) } @@ -126,12 +118,16 @@ struct UsernameView: View { .foregroundStyle(Color.error) } + func nextStep() { + state.step = .buildYourNetwork + } + /// Checks whether the username is available and saves it. Updates `usernameState` based on the result. - func next() async { + func verifyAndSave() async { usernameState = .loading guard !username.isEmpty, let keyPair = currentUser.keyPair else { - usernameState = .claimFailed + usernameState = .errorAlert return } @@ -157,8 +153,7 @@ struct UsernameView: View { guard let author = await currentUser.author, let keyPair = currentUser.keyPair else { - saveError = SaveProfileError.unexpectedError - usernameState = .claimFailed + usernameState = .errorAlert return } @@ -175,14 +170,10 @@ struct UsernameView: View { relays: relays ) usernameState = .claimed - state.step = .buildYourNetwork - } catch CurrentUserError.errorWhilePublishingToRelays { - saveError = SaveProfileError.unableToPublishChanges - usernameState = .claimFailed + nextStep() } catch { crashReporting.report(error) - saveError = SaveProfileError.unexpectedError - usernameState = .claimFailed + usernameState = .errorAlert } } }