diff --git a/damus/ContentView.swift b/damus/ContentView.swift index fa1fa395..ddbc36fb 100644 --- a/damus/ContentView.swift +++ b/damus/ContentView.swift @@ -490,13 +490,17 @@ struct ContentView: View { // For extra assurance, run this after one second, to avoid race conditions if the app is also handling a damus purple welcome url. DispatchQueue.main.asyncAfter(deadline: .now() + 1) { Task { - // TODO: Improve UX for renewals (#2013) let freshly_completed_checkout_ids = try? await damus_state.purple.check_status_of_checkouts_in_progress() let there_is_a_completed_checkout: Bool = (freshly_completed_checkout_ids?.count ?? 0) > 0 let account_info = try await damus_state.purple.fetch_account(pubkey: self.keypair.pubkey) if there_is_a_completed_checkout == true && account_info?.active == true { - // Show welcome sheet - self.active_sheet = .purple_onboarding + if damus_state.purple.onboarding_status.user_has_never_seen_the_onboarding_before() { + // Show welcome sheet + self.active_sheet = .purple_onboarding + } + else { + self.active_sheet = .purple(DamusPurpleURL.init(is_staging: damus_state.purple.environment == .staging, variant: .landing)) + } } } } diff --git a/damus/Models/Purple/DamusPurple.swift b/damus/Models/Purple/DamusPurple.swift index 2ffddd54..c5a2ba9c 100644 --- a/damus/Models/Purple/DamusPurple.swift +++ b/damus/Models/Purple/DamusPurple.swift @@ -13,6 +13,7 @@ class DamusPurple: StoreObserverDelegate { let keypair: Keypair var storekit_manager: StoreKitManager var checkout_ids_in_progress: Set = [] + var onboarding_status: OnboardingStatus @MainActor var account_cache: [Pubkey: Account] @@ -25,6 +26,16 @@ class DamusPurple: StoreObserverDelegate { self.account_cache = [:] self.account_uuid_cache = [:] self.storekit_manager = StoreKitManager.standard // Use singleton to avoid losing local purchase data + self.onboarding_status = OnboardingStatus() + Task { + let account: Account? = try await self.fetch_account(pubkey: self.keypair.pubkey) + if account == nil { + self.onboarding_status.account_existed_at_the_start = false + } + else { + self.onboarding_status.account_existed_at_the_start = true + } + } } // MARK: Functions @@ -449,4 +460,22 @@ extension DamusPurple { struct TranslationResult: Codable { let text: String } + + struct OnboardingStatus { + var account_existed_at_the_start: Bool? = nil + var onboarding_was_shown: Bool = false + + init() { + + } + + init(account_active_at_the_start: Bool, onboarding_was_shown: Bool) { + self.account_existed_at_the_start = account_active_at_the_start + self.onboarding_was_shown = onboarding_was_shown + } + + func user_has_never_seen_the_onboarding_before() -> Bool { + return onboarding_was_shown == false && account_existed_at_the_start == false + } + } } diff --git a/damus/Views/Purple/DamusPurpleNewUserOnboardingView.swift b/damus/Views/Purple/DamusPurpleNewUserOnboardingView.swift index a9435e1e..c478e271 100644 --- a/damus/Views/Purple/DamusPurpleNewUserOnboardingView.swift +++ b/damus/Views/Purple/DamusPurpleNewUserOnboardingView.swift @@ -35,6 +35,8 @@ struct DamusPurpleNewUserOnboardingView: View { guard let account = try? await damus_state.purple.fetch_account(pubkey: damus_state.pubkey), account.active else { return } + // Let's mark onboarding as "shown" + damus_state.purple.onboarding_status.onboarding_was_shown = true // Let's notify other views across SwiftUI to update our user's Purple status. notify(.purple_account_update(account)) }