Skip to content

Commit

Permalink
cleanup viewModel
Browse files Browse the repository at this point in the history
  • Loading branch information
vegaro committed Jul 18, 2024
1 parent f462b7f commit 8caebf1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ class PromotionalOfferViewModel: ObservableObject {
@Published
private(set) var promotionalOfferData: PromotionalOfferData?
@Published
private(set) var transaction: StoreTransaction?
@Published
private(set) var error: Error?

private var purchasesProvider: CustomerCenterPurchasesType
Expand All @@ -58,8 +56,7 @@ class PromotionalOfferViewModel: ObservableObject {
}

do {
let purchase = try await Purchases.shared.purchase(product: product, promotionalOffer: promotionalOffer)
self.transaction = purchase.transaction
try await Purchases.shared.purchase(product: product, promotionalOffer: promotionalOffer)
} catch {
self.error = error
}
Expand Down
8 changes: 7 additions & 1 deletion RevenueCatUI/CustomerCenter/Views/PromotionalOfferView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ struct PromotionalOfferView: View {
var body: some View {
VStack {
if let details = self.viewModel.promotionalOfferData?.promoOfferDetails,
let localization = self.viewModel.localization {
let localization = self.viewModel.localization,
self.viewModel.error == nil {
Text(details.title)
.font(.title)
.padding()
Expand All @@ -63,6 +64,11 @@ struct PromotionalOfferView: View {
Button(dismissButtonTitle) {
dismiss()
}
} else {
EmptyView()
.onAppear {
dismiss()
}
}
}
}
Expand Down

0 comments on commit 8caebf1

Please sign in to comment.