|
|
|
|
@ -36,8 +36,7 @@ class SubscriptionModel: ObservableObject, StoreDelegate { |
|
|
|
|
func purchase() { |
|
|
|
|
if let product = self.selectedProduct { |
|
|
|
|
Task { |
|
|
|
|
let quantity: Int? = (product.id == StoreItem.tournament.rawValue) ? self.quantity : nil |
|
|
|
|
let _ = try await self.storeManager?.purchase(product, quantity: quantity) |
|
|
|
|
let _ = try await self.storeManager?.purchase(product) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -48,28 +47,16 @@ struct SubscriptionView: View { |
|
|
|
|
|
|
|
|
|
@ObservedObject var model: SubscriptionModel = SubscriptionModel() |
|
|
|
|
|
|
|
|
|
@State var test = 5 |
|
|
|
|
|
|
|
|
|
var body: some View { |
|
|
|
|
Form { |
|
|
|
|
|
|
|
|
|
Section { |
|
|
|
|
Text(test.formatted()) |
|
|
|
|
StepperView(count: self.$test) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List { |
|
|
|
|
ForEach(self.model.products) { product in |
|
|
|
|
if let item = StoreItem(rawValue: product.id) { |
|
|
|
|
ProductView(product: product, |
|
|
|
|
item: item, |
|
|
|
|
quantity: self.$model.quantity) |
|
|
|
|
.onTapGesture { |
|
|
|
|
self.model.selectedProduct = product |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
Text("Missing item") |
|
|
|
|
} |
|
|
|
|
ProductView(product: product, |
|
|
|
|
quantity: self.$model.quantity) |
|
|
|
|
.onTapGesture { |
|
|
|
|
self.model.selectedProduct = product |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -107,7 +94,6 @@ struct SubscriptionView: View { |
|
|
|
|
struct ProductView: View { |
|
|
|
|
|
|
|
|
|
var product: Product |
|
|
|
|
var item: StoreItem |
|
|
|
|
@Binding var quantity: Int |
|
|
|
|
|
|
|
|
|
var body: some View { |
|
|
|
|
@ -116,17 +102,8 @@ struct ProductView: View { |
|
|
|
|
.font(.title) |
|
|
|
|
.foregroundColor(.blue) |
|
|
|
|
VStack(alignment: .leading) { |
|
|
|
|
if item.isUnit == true { |
|
|
|
|
Text("\(self.quantity) \(item.title)") |
|
|
|
|
let total = item.price * Double(self.quantity) |
|
|
|
|
|
|
|
|
|
Text(total.formatted()).foregroundColor(.blue) |
|
|
|
|
|
|
|
|
|
StepperView(count: self.$quantity, minimum: 1) |
|
|
|
|
} else { |
|
|
|
|
Text(item.title) |
|
|
|
|
Text(item.formattedPrice).foregroundColor(.blue) |
|
|
|
|
} |
|
|
|
|
Text(product.displayName) |
|
|
|
|
Text(product.displayPrice).foregroundColor(.blue) |
|
|
|
|
} |
|
|
|
|
Spacer() |
|
|
|
|
Image(systemName: "checkmark").foregroundColor(.blue) |
|
|
|
|
|