diff GeoQuiz/BuyPremiumModalView.swift @ 12:ce7ea84f67f5

display product prices
author Dennis C. M. <dennis@denniscm.com>
date Sun, 09 Oct 2022 19:46:44 +0200
parents 039b26a99a48
children bdfff35dd43c
line wrap: on
line diff
--- a/GeoQuiz/BuyPremiumModalView.swift	Sun Oct 09 17:02:34 2022 +0200
+++ b/GeoQuiz/BuyPremiumModalView.swift	Sun Oct 09 19:46:44 2022 +0200
@@ -9,6 +9,7 @@
 
 struct BuyPremiumModalView: View {
     @Environment(\.dismiss) var dismiss
+    @StateObject var storeKitRC = StoreKitRC()
     
     var body: some View {
         NavigationView {
@@ -54,15 +55,20 @@
                             .fontWeight(.semibold)
                             .foregroundColor(.secondary)
                         
-                        Button {
-                            // Buy
-                        } label: {
-                            Text("Buy for $2.99")
-                                .font(.headline)
-                                .padding()
+                        if let productPrice = storeKitRC.productPrice {
+                            Button {
+                                // Buy
+                            } label: {
+                                Text("Buy for \(productPrice)")
+                                    .font(.headline)
+                                    .padding()
+                            }
+                            .buttonStyle(.borderedProminent)
+                            .padding(.top)
+                        } else {
+                            ProgressView()
+                                .padding(.top)
                         }
-                        .buttonStyle(.borderedProminent)
-                        .padding(.top)
                     }
                     .padding()
                     
@@ -72,6 +78,7 @@
                     }
                     .font(.callout)
                     .foregroundColor(.secondary)
+                    .padding()
                 }
             }
             .navigationBarTitleDisplayMode(.inline)
@@ -84,6 +91,11 @@
                     }
                 }
             }
+            .alert("Something went wrong 🤕", isPresented: $storeKitRC.showingErrorAlert) {
+                Button("OK", role: .cancel) { dismiss() }
+            } message: {
+                Text(storeKitRC.errorMessage)
+            }
         }
     }
 }