DomainDig/PaywallView.swift
143 lines · 6113 bytes
3 symbols in this file
1import StoreKit
2import SwiftUI
3
4struct PaywallView: View {
5 @Environment(\.dismiss) private var dismiss
6 @Environment(\.appDensity) private var appDensity
7 @State private var purchaseService = PurchaseService.shared
8
9 var body: some View {
10 NavigationStack {
11 List {
12 Section {
13 Text("Pro unlocks scale, background monitoring, alerts, exports, and extended subdomain discovery. Pro+ adds shared portfolios, unlimited audits, and the full intelligence breakdown.")
14 .font(appDensity.font(.body, design: .default))
15 .foregroundStyle(ThemeToken.textSecondary)
16 .fixedSize(horizontal: false, vertical: true)
17 }
18
19 Section("What Pro Unlocks") {
20 featureRow("Unlimited tracked domains")
21 featureRow("Workflows")
22 featureRow("Larger batch sizes")
23 featureRow("Background monitoring")
24 featureRow("Local alerts")
25 featureRow("Advanced exports")
26 featureRow("Extended subdomain discovery")
27 }
28
29 Section("What Pro+ Unlocks") {
30 featureRow("Shared portfolios")
31 featureRow("Unlimited audit sessions")
32 featureRow("Intelligence detail")
33 }
34
35 Section("Subscription") {
36 if purchaseService.isLoadingProducts {
37 ProgressView("Loading pricing…")
38 } else if purchaseService.products.isEmpty {
39 Text("Pricing is unavailable right now.")
40 .font(appDensity.font(.caption, design: .default))
41 .foregroundStyle(ThemeToken.textSecondary)
42
43 Button("Retry") {
44 Task {
45 await purchaseService.refreshProducts()
46 }
47 }
48 } else {
49 ForEach(purchaseService.products, id: \.id) { product in
50 Button {
51 Task {
52 await purchaseService.purchase(product)
53 }
54 } label: {
55 VStack(alignment: .leading, spacing: 6) {
56 Text(subscriptionTitle(for: product))
57 .font(appDensity.font(.headline, design: .default, weight: .semibold))
58 .foregroundStyle(.primary)
59 Text(product.displayPrice)
60 .font(appDensity.font(.callout, design: .default))
61 .foregroundStyle(ThemeToken.textSecondary)
62 }
63 .frame(maxWidth: .infinity, alignment: .leading)
64 }
65 .disabled(purchaseService.isPurchasing || purchaseService.isRestoring)
66 }
67 }
68
69 if let statusMessage = purchaseService.statusMessage {
70 Text(statusMessage)
71 .font(appDensity.font(.caption, design: .default))
72 .foregroundStyle(ThemeToken.textSecondary)
73 }
74
75 if let errorMessage = purchaseService.errorMessage {
76 Text(errorMessage)
77 .font(appDensity.font(.caption, design: .default))
78 .foregroundStyle(ThemeToken.critical)
79 }
80 }
81
82 Section("Account") {
83 Button(purchaseService.isRestoring ? "Restoring…" : "Restore Purchases") {
84 Task {
85 await purchaseService.restorePurchases()
86 }
87 }
88 .disabled(purchaseService.isPurchasing || purchaseService.isRestoring)
89
90 if purchaseService.hasProAccess {
91 Button("Manage Subscription") {
92 Task {
93 await purchaseService.manageSubscription()
94 }
95 }
96 }
97 }
98
99 Section {
100 Link("Terms of Use", destination: AppLinks.termsOfUse)
101 Link("Privacy Policy", destination: AppLinks.privacyPolicy)
102 } footer: {
103 Text("Subscriptions renew automatically unless cancelled at least 24 hours before the end of the current period. Manage or cancel them in your App Store account settings.")
104 }
105 }
106 .navigationTitle("DomainDig Pro")
107 .toolbar {
108 ToolbarItem(placement: .topBarTrailing) {
109 Button("Done") {
110 dismiss()
111 }
112 }
113 }
114 }
115 .task {
116 await purchaseService.refreshProducts()
117 await purchaseService.refreshEntitlements()
118 }
119 .onDisappear {
120 purchaseService.clearMessages()
121 }
122 }
123
124 private func featureRow(_ title: String) -> some View {
125 Text(title)
126 .font(appDensity.font(.body, design: .default))
127 }
128
129 private func subscriptionTitle(for product: Product) -> String {
130 switch product.id {
131 case PurchaseService.monthlyProductID:
132 return "Pro Monthly"
133 case PurchaseService.yearlyProductID:
134 return "Pro Yearly"
135 case PurchaseService.proPlusMonthlyProductID:
136 return "Pro+ Monthly"
137 case PurchaseService.proPlusYearlyProductID:
138 return "Pro+ Yearly"
139 default:
140 return product.displayName
141 }
142 }
143}