comparison Simoleon/Helpers/RestoreButton.swift @ 30:f76d0e26c178

Add localisation
author Dennis Concepción Martín <dennisconcepcionmartin@gmail.com>
date Fri, 23 Jul 2021 13:19:28 +0100
parents c52966834f83
children d25b02d439d4
comparison
equal deleted inserted replaced
29:c52966834f83 30:f76d0e26c178
10 10
11 struct RestoreButton: View { 11 struct RestoreButton: View {
12 @Binding var showingSubscriptionPaywall: Bool 12 @Binding var showingSubscriptionPaywall: Bool
13 @EnvironmentObject var subscriptionController: SubscriptionController 13 @EnvironmentObject var subscriptionController: SubscriptionController
14 14
15 @State private var alertTitle: LocalizedStringKey = ""
16 @State private var alertMessage: LocalizedStringKey = ""
15 @State private var restoringPurchases = false 17 @State private var restoringPurchases = false
16 @State private var alertTitle = Text("")
17 @State private var alertMessage = Text("")
18 @State private var showingAlert = false 18 @State private var showingAlert = false
19 19
20 var body: some View { 20 var body: some View {
21 Button(action: restorePurchases) { 21 Button(action: restorePurchases) {
22 if restoringPurchases { 22 if restoringPurchases {
24 } else { 24 } else {
25 Text("Restore purchases", comment: "Button to restore in-App purchases") 25 Text("Restore purchases", comment: "Button to restore in-App purchases")
26 } 26 }
27 } 27 }
28 .alert(isPresented: $showingAlert) { 28 .alert(isPresented: $showingAlert) {
29 Alert(title: alertTitle, message: alertMessage, dismissButton: .default(Text("Ok", comment: "Button to dismiss alert"))) 29 Alert(title: Text(alertTitle), message: Text(alertMessage), dismissButton: .default(Text("Ok", comment: "Button to dismiss alert")))
30 } 30 }
31 } 31 }
32 32
33 private func restorePurchases() { 33 private func restorePurchases() {
34 restoringPurchases = true 34 restoringPurchases = true
36 Purchases.shared.restoreTransactions { purchaserInfo, error in 36 Purchases.shared.restoreTransactions { purchaserInfo, error in
37 if purchaserInfo?.entitlements["all"]?.isActive == true { 37 if purchaserInfo?.entitlements["all"]?.isActive == true {
38 subscriptionController.isActive = true 38 subscriptionController.isActive = true
39 showingSubscriptionPaywall = false 39 showingSubscriptionPaywall = false
40 } else { 40 } else {
41 alertTitle = Text("No subscriptions found", comment: "Alert title") 41 alertTitle = LocalizedStringKey("No subscriptions found")
42 alertMessage = Text("You are not subscripted to Simoleon yet.", comment: "Alert message") 42 alertMessage = LocalizedStringKey("You are not subscripted to Simoleon yet.")
43 restoringPurchases = false 43 restoringPurchases = false
44 showingAlert = true 44 showingAlert = true
45 } 45 }
46 46
47 if let error = error as NSError? { 47 if let error = error as NSError? {
48 alertTitle = Text(error.localizedDescription) 48 alertTitle = LocalizedStringKey(error.localizedDescription)
49 alertMessage = Text(error.localizedFailureReason ?? "If the problem persists send an email to dmartin@dennistech.io") 49 alertMessage = LocalizedStringKey(error.localizedFailureReason ?? "")
50 showingAlert = true 50 showingAlert = true
51 } 51 }
52 } 52 }
53 } 53 }
54 } 54 }