Skip to content

Commit

Permalink
fix state checks
Browse files Browse the repository at this point in the history
  • Loading branch information
vegaro committed Dec 11, 2024
1 parent ef78151 commit cc42021
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ import RevenueCat
}
}

var isLoaded: Bool {
return state != .notLoaded && configuration != nil
}

private let currentVersionFetcher: CurrentVersionFetcher
internal let customerCenterActionHandler: CustomerCenterActionHandler?

Expand Down Expand Up @@ -97,8 +93,17 @@ import RevenueCat

#endif

func loadPurchaseInformation() async {
func loadScreen() async {
do {
try await self.loadPurchaseInformation()
try await self.loadCustomerCenterConfig()
self.state = .success
} catch {
self.state = .error(error)
}
}

func loadPurchaseInformation() async throws {
let customerInfo = try await purchasesProvider.customerInfo()
let hasActiveProducts =
!customerInfo.activeSubscriptions.isEmpty || !customerInfo.nonSubscriptions.isEmpty
Expand All @@ -120,19 +125,10 @@ import RevenueCat

self.purchaseInformation = try await createPurchaseInformation(for: activeTransaction,
entitlement: entitlement)

self.state = .success
} catch {
self.state = .error(error)
}
}

func loadCustomerCenterConfig() async {
do {
self.configuration = try await Purchases.shared.loadCustomerCenter()
} catch {
self.state = .error(error)
}
func loadCustomerCenterConfig() async throws {
self.configuration = try await Purchases.shared.loadCustomerCenter()
}

func performRestore() async -> RestorePurchasesAlert.AlertType {
Expand Down
8 changes: 5 additions & 3 deletions RevenueCatUI/CustomerCenter/Views/CustomerCenterView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,18 @@ public struct CustomerCenterView: View {
switch self.viewModel.state {
case .error:
ErrorView()
case .loaded:
case .notLoaded:
TintedProgressView()
case .success:
if let configuration = self.viewModel.configuration {
destinationView(configuration: configuration)
.environment(\.localization, configuration.localization)
.environment(\.appearance, configuration.appearance)
.environment(\.supportInformation, configuration.support)
.environment(\.customerCenterPresentationMode, self.mode)
} else {
TintedProgressView()
}
default:
TintedProgressView()
}
}
.task {
Expand Down
3 changes: 3 additions & 0 deletions RevenueCatUI/CustomerCenter/Views/ErrorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import SwiftUI
@available(watchOS, unavailable)
struct ErrorView: View {

@Environment(\.locale)
private var locale

var body: some View {
VStack(spacing: 20) {
let errorMessage: String = Localization.localizedBundle(self.locale)
Expand Down

0 comments on commit cc42021

Please sign in to comment.