purple: adapt to integrate better with the LN flow
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:
committed by
William Casarin
parent
a6b430284f
commit
e649c49981
158
damus/Views/Purple/DamusPurpleAccountView.swift
Normal file
158
damus/Views/Purple/DamusPurpleAccountView.swift
Normal file
@@ -0,0 +1,158 @@
|
||||
//
|
||||
// DamusPurpleAccountView.swift
|
||||
// damus
|
||||
//
|
||||
// Created by Daniel D’Aquino on 2024-01-26.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct DamusPurpleAccountView: View {
|
||||
var colorScheme: ColorScheme = .dark
|
||||
let damus_state: DamusState
|
||||
let account: DamusPurple.Account
|
||||
let pfp_size: CGFloat = 90.0
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
ProfilePicView(pubkey: account.pubkey, size: pfp_size, highlight: .custom(Color.black.opacity(0.4), 1.0), profiles: damus_state.profiles, disable_animation: damus_state.settings.disable_animation)
|
||||
.background(Color.black.opacity(0.4).clipShape(Circle()))
|
||||
.shadow(color: .black, radius: 10, x: 0.0, y: 5)
|
||||
|
||||
profile_name
|
||||
|
||||
if account.active {
|
||||
active_account_badge
|
||||
}
|
||||
else {
|
||||
inactive_account_badge
|
||||
}
|
||||
|
||||
// TODO: Generalize this view instead of setting up dividers and paddings manually
|
||||
VStack {
|
||||
HStack {
|
||||
Text(NSLocalizedString("Expiry date", comment: "Label for Purple subscription expiry date"))
|
||||
Spacer()
|
||||
Text(DateFormatter.localizedString(from: account.expiry, dateStyle: .short, timeStyle: .none))
|
||||
}
|
||||
.padding(.horizontal)
|
||||
.padding(.top, 20)
|
||||
|
||||
Divider()
|
||||
.padding(.horizontal)
|
||||
.padding(.vertical, 10)
|
||||
|
||||
HStack {
|
||||
Text(NSLocalizedString("Account creation", comment: "Label for Purple account creation date"))
|
||||
Spacer()
|
||||
Text(DateFormatter.localizedString(from: account.created_at, dateStyle: .short, timeStyle: .none))
|
||||
}
|
||||
.padding(.horizontal)
|
||||
|
||||
Divider()
|
||||
.padding(.horizontal)
|
||||
.padding(.vertical, 10)
|
||||
|
||||
HStack {
|
||||
Text(NSLocalizedString("Subscriber number", comment: "Label for Purple account subscriber number"))
|
||||
Spacer()
|
||||
Text("#\(account.subscriber_number)")
|
||||
}
|
||||
.padding(.horizontal)
|
||||
.padding(.bottom, 20)
|
||||
}
|
||||
.foregroundColor(.white.opacity(0.8))
|
||||
.preferredColorScheme(.dark)
|
||||
.background(.ultraThinMaterial, in: RoundedRectangle(cornerRadius: 12, style: .continuous))
|
||||
.padding()
|
||||
|
||||
Text(NSLocalizedString("Visit the Damus website on a web browser to manage billing", comment: "Instruction on how to manage billing externally"))
|
||||
.font(.caption)
|
||||
.foregroundColor(.white.opacity(0.6))
|
||||
.multilineTextAlignment(.center)
|
||||
}
|
||||
}
|
||||
|
||||
var profile_name: some View {
|
||||
let display_name = self.profile_display_name()
|
||||
return HStack(alignment: .center, spacing: 5) {
|
||||
Text(display_name)
|
||||
.font(.title)
|
||||
.bold()
|
||||
.foregroundStyle(.white)
|
||||
|
||||
SupporterBadge(
|
||||
percent: nil,
|
||||
purple_badge_info: DamusPurple.UserBadgeInfo.from(account: account),
|
||||
style: .full
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
var active_account_badge: some View {
|
||||
HStack(spacing: 3) {
|
||||
Image("check-circle.fill")
|
||||
.resizable()
|
||||
.frame(width: 15, height: 15)
|
||||
|
||||
Text(NSLocalizedString("Active account", comment: "Badge indicating user has an active Damus Purple account"))
|
||||
.font(.caption)
|
||||
.bold()
|
||||
}
|
||||
.foregroundColor(Color.white)
|
||||
.padding(.vertical, 3)
|
||||
.padding(.horizontal, 8)
|
||||
.background(PinkGradient)
|
||||
.cornerRadius(30.0)
|
||||
}
|
||||
|
||||
var inactive_account_badge: some View {
|
||||
HStack(spacing: 3) {
|
||||
Image("warning")
|
||||
.resizable()
|
||||
.frame(width: 15, height: 15)
|
||||
|
||||
Text(NSLocalizedString("Expired account", comment: "Badge indicating user has an expired Damus Purple account"))
|
||||
.font(.caption)
|
||||
.bold()
|
||||
}
|
||||
.foregroundColor(DamusColors.danger)
|
||||
.padding(.vertical, 3)
|
||||
.padding(.horizontal, 8)
|
||||
.background(DamusColors.dangerTertiary)
|
||||
.cornerRadius(30.0)
|
||||
}
|
||||
|
||||
func profile_display_name() -> String {
|
||||
let profile_txn: NdbTxn<ProfileRecord?>? = damus_state.profiles.lookup_with_timestamp(account.pubkey)
|
||||
let profile: NdbProfile? = profile_txn?.unsafeUnownedValue?.profile
|
||||
let display_name = parse_display_name(profile: profile, pubkey: account.pubkey).displayName
|
||||
return display_name
|
||||
}
|
||||
}
|
||||
|
||||
#Preview("Active") {
|
||||
DamusPurpleAccountView(
|
||||
damus_state: test_damus_state,
|
||||
account: DamusPurple.Account(
|
||||
pubkey: test_pubkey,
|
||||
created_at: Date.now,
|
||||
expiry: Date.init(timeIntervalSinceNow: 60 * 60 * 24 * 30),
|
||||
subscriber_number: 7,
|
||||
active: true
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
#Preview("Expired") {
|
||||
DamusPurpleAccountView(
|
||||
damus_state: test_damus_state,
|
||||
account: DamusPurple.Account(
|
||||
pubkey: test_pubkey,
|
||||
created_at: Date.init(timeIntervalSinceNow: -60 * 60 * 24 * 37),
|
||||
expiry: Date.init(timeIntervalSinceNow: -60 * 60 * 24 * 7),
|
||||
subscriber_number: 7,
|
||||
active: false
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -27,6 +27,13 @@ enum ProductState {
|
||||
}
|
||||
}
|
||||
|
||||
enum AccountInfoState {
|
||||
case loading
|
||||
case loaded(account: DamusPurple.Account)
|
||||
case no_account
|
||||
case error(message: String)
|
||||
}
|
||||
|
||||
func non_discounted_price(_ product: Product) -> String {
|
||||
return (product.price * 1.1984569224).formatted(product.priceFormatStyle)
|
||||
}
|
||||
@@ -45,6 +52,7 @@ struct DamusPurpleView: View {
|
||||
let damus_state: DamusState
|
||||
let keypair: Keypair
|
||||
|
||||
@State var my_account_info_state: AccountInfoState = .loading
|
||||
@State var products: ProductState
|
||||
@State var purchased: PurchasedProduct? = nil
|
||||
@State var selection: DamusPurpleType = .yearly
|
||||
@@ -86,6 +94,9 @@ struct DamusPurpleView: View {
|
||||
}
|
||||
.onAppear {
|
||||
notify(.display_tabbar(false))
|
||||
Task {
|
||||
await self.load_account()
|
||||
}
|
||||
}
|
||||
.onDisappear {
|
||||
notify(.display_tabbar(true))
|
||||
@@ -123,6 +134,20 @@ struct DamusPurpleView: View {
|
||||
.manageSubscriptionsSheet(isPresented: $show_manage_subscriptions)
|
||||
}
|
||||
|
||||
func load_account() async {
|
||||
do {
|
||||
if let account = try await damus_state.purple.get_account(pubkey: damus_state.keypair.pubkey) {
|
||||
self.my_account_info_state = .loaded(account: account)
|
||||
return
|
||||
}
|
||||
self.my_account_info_state = .no_account
|
||||
return
|
||||
}
|
||||
catch {
|
||||
self.my_account_info_state = .error(message: NSLocalizedString("There was an error loading your account. Please try again later. If problem persists, please contact us at support@damus.io", comment: "Error label when Purple account information fails to load"))
|
||||
}
|
||||
}
|
||||
|
||||
func update_user_settings_to_purple() {
|
||||
if damus_state.settings.translation_service == .none {
|
||||
set_translation_settings_to_purple()
|
||||
@@ -357,6 +382,27 @@ struct DamusPurpleView: View {
|
||||
VStack {
|
||||
DamusPurpleLogoView()
|
||||
|
||||
switch my_account_info_state {
|
||||
case .loading:
|
||||
ProgressView()
|
||||
.progressViewStyle(.circular)
|
||||
case .loaded(let account):
|
||||
DamusPurpleAccountView(damus_state: damus_state, account: account)
|
||||
case .no_account:
|
||||
MarketingContent
|
||||
case .error(let message):
|
||||
Text(message)
|
||||
.foregroundStyle(.red)
|
||||
.multilineTextAlignment(.center)
|
||||
.padding()
|
||||
}
|
||||
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
|
||||
var MarketingContent: some View {
|
||||
VStack {
|
||||
VStack(alignment: .leading, spacing: 30) {
|
||||
Subtitle(NSLocalizedString("Help us stay independent in our mission for Freedom tech with our Purple subscription, and look cool doing it!", comment: "Damus purple subscription pitch"))
|
||||
.multilineTextAlignment(.center)
|
||||
@@ -414,8 +460,8 @@ struct DamusPurpleView: View {
|
||||
NSLocalizedString("Learn more", comment: "Label for a link to the Damus Purple landing page"),
|
||||
destination: damus_state.purple.environment.purple_landing_page_url()
|
||||
)
|
||||
.foregroundColor(DamusColors.pink)
|
||||
.padding()
|
||||
.foregroundColor(DamusColors.pink)
|
||||
.padding()
|
||||
Spacer()
|
||||
}
|
||||
|
||||
@@ -427,9 +473,6 @@ struct DamusPurpleView: View {
|
||||
ProductStateView
|
||||
}
|
||||
.padding([.top], 20)
|
||||
|
||||
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user