purple: notify main DamusPurpleView when user gets a subsscription

Previously, if the user had the DamusPurpleView open and bought the
subscription, the DamusPurpleView would not change. It would stay in the
marketing pitch screen.

This commit makes sure that this view is automatically updated as soon
as the user sees the welcome screen, so that they can see their account
info in case they have DamusPurpleView open.

Testing
--------

PASS

iOS: 17.2
Damus: This commit
damus-api: Varying versions around `9a6af62`
Coverage:
1. Checked the entire LN flow through the local test environment using the simulator
2. Checked all LN flow views on both light and dark mode to ensure it looks good
3. Checked the entire LN flow using the staging environment using a physical iOS device

Closes: https://github.com/damus-io/damus/issues/1899
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
Reviewed-by: William Casarin <jb55@jb55.com>
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
Daniel D’Aquino authored and William Casarin committed 2024-01-30 10:29:49 -08:00
1 parent 1421c34aeb
commit 5f9477d55b
4 files changed
+39 -11

No files matched your search

+4
View File
@@ -450,6 +450,7 @@
D7315A2C2ACDF4DA0036E30A /* DamusCacheManagerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7315A2B2ACDF4DA0036E30A /* DamusCacheManagerTests.swift */; };
D7373BA62B688EA300F7783D /* DamusPurpleTranslationSetupView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7373BA52B688EA200F7783D /* DamusPurpleTranslationSetupView.swift */; };
D7373BA82B68974500F7783D /* DamusPurpleNewUserOnboardingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7373BA72B68974500F7783D /* DamusPurpleNewUserOnboardingView.swift */; };
D7373BAA2B68A65A00F7783D /* PurpleAccountUpdateNotify.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7373BA92B68A65A00F7783D /* PurpleAccountUpdateNotify.swift */; };
D74AAFC22B153395006CF0F4 /* HeadlessDamusState.swift in Sources */ = {isa = PBXBuildFile; fileRef = D74AAFC12B153395006CF0F4 /* HeadlessDamusState.swift */; };
D74AAFC32B153395006CF0F4 /* HeadlessDamusState.swift in Sources */ = {isa = PBXBuildFile; fileRef = D74AAFC12B153395006CF0F4 /* HeadlessDamusState.swift */; };
D74AAFC52B1538DF006CF0F4 /* NotificationExtensionState.swift in Sources */ = {isa = PBXBuildFile; fileRef = D74AAFC42B1538DE006CF0F4 /* NotificationExtensionState.swift */; };
@@ -1346,6 +1347,7 @@
D7315A2B2ACDF4DA0036E30A /* DamusCacheManagerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DamusCacheManagerTests.swift; sourceTree = "<group>"; };
D7373BA52B688EA200F7783D /* DamusPurpleTranslationSetupView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DamusPurpleTranslationSetupView.swift; sourceTree = "<group>"; };
D7373BA72B68974500F7783D /* DamusPurpleNewUserOnboardingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DamusPurpleNewUserOnboardingView.swift; sourceTree = "<group>"; };
D7373BA92B68A65A00F7783D /* PurpleAccountUpdateNotify.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PurpleAccountUpdateNotify.swift; sourceTree = "<group>"; };
D74AAFC12B153395006CF0F4 /* HeadlessDamusState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HeadlessDamusState.swift; sourceTree = "<group>"; };
D74AAFC42B1538DE006CF0F4 /* NotificationExtensionState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationExtensionState.swift; sourceTree = "<group>"; };
D74AAFCB2B155D07006CF0F4 /* MakeZapRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MakeZapRequest.swift; sourceTree = "<group>"; };
@@ -2209,6 +2211,7 @@
4C4E137A2A76D5FB00BDD832 /* MuteThreadNotify.swift */,
4C4E137C2A76D63600BDD832 /* UnmuteThreadNotify.swift */,
B57B4C612B312BD700A232C0 /* ReconnectRelaysNotify.swift */,
D7373BA92B68A65A00F7783D /* PurpleAccountUpdateNotify.swift */,
);
path = Notify;
sourceTree = "<group>";
@@ -3238,6 +3241,7 @@
F71694EA2A662232001F4053 /* OnboardingSuggestionsView.swift in Sources */,
4C12536A2A76D3850004F4B8 /* RelaysChangedNotify.swift in Sources */,
4C30AC8029A6A53F00E2BD5A /* ProfilePicturesView.swift in Sources */,
D7373BAA2B68A65A00F7783D /* PurpleAccountUpdateNotify.swift in Sources */,
5C6E1DAD2A193EC2008FC15A /* GradientButtonStyle.swift in Sources */,
3CCD1E6A2A874C4E0099A953 /* Nip98HTTPAuth.swift in Sources */,
4C8EC52529D1FA6C0085D9A8 /* DamusColors.swift in Sources */,
@@ -0,0 +1,25 @@
//
// PurpleAccountUpdateNotify.swift
// damus
//
// Created by Daniel D’Aquino on 2024-01-29.
//
import Foundation
struct PurpleAccountUpdateNotify: Notify {
typealias Payload = DamusPurple.Account
var payload: DamusPurple.Account
}
extension NotifyHandler {
static var purple_account_update: NotifyHandler<PurpleAccountUpdateNotify> {
.init()
}
}
extension Notifications {
static func purple_account_update(_ result: DamusPurple.Account) -> Notifications<PurpleAccountUpdateNotify> {
.init(.init(payload: result))
}
}
@@ -31,6 +31,13 @@ struct DamusPurpleNewUserOnboardingView: View {
}
.ignoresSafeArea() // Necessary to avoid weird white edges
}
.task {
guard let account = try? await damus_state.purple.get_account(pubkey: damus_state.pubkey), account.active else {
return
}
// Let's notify other views across SwiftUI to update our user's Purple status.
notify(.purple_account_update(account))
}
}
}
+3 -11
View File
@@ -58,7 +58,6 @@ struct DamusPurpleView: View {
@State var selection: DamusPurpleType = .yearly
@State var show_welcome_sheet: Bool = false
@State var show_manage_subscriptions = false
@State var show_settings_change_confirmation_dialog = false
@State private var shouldDismissView = false
@Environment(\.dismiss) var dismiss
@@ -101,6 +100,9 @@ struct DamusPurpleView: View {
.onDisappear {
notify(.display_tabbar(true))
}
.onReceive(handle_notify(.purple_account_update), perform: { account in
self.my_account_info_state = .loaded(account: account)
})
.task {
await load_products()
}
@@ -110,16 +112,6 @@ struct DamusPurpleView: View {
}, content: {
DamusPurpleNewUserOnboardingView(damus_state: damus_state)
})
.onChange(of: shouldDismissView) { shouldDismissView in
if shouldDismissView && !show_settings_change_confirmation_dialog {
dismiss()
}
}
.onChange(of: show_settings_change_confirmation_dialog) { show_settings_change_confirmation_dialog in
if shouldDismissView && !show_settings_change_confirmation_dialog {
dismiss()
}
}
.manageSubscriptionsSheet(isPresented: $show_manage_subscriptions)
}