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

Add localisation
author Dennis Concepción Martín <dennisconcepcionmartin@gmail.com>
date Fri, 23 Jul 2021 13:19:28 +0100
parents 4f862c618b44
children d25b02d439d4
comparison
equal deleted inserted replaced
29:c52966834f83 30:f76d0e26c178
10 10
11 struct SubscribeButton: View { 11 struct SubscribeButton: 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 subscribeButtonText = "" 15 @State private var price = ""
16 @State private var showingPrice = false
17 @State private var alertTitle = "" 16 @State private var alertTitle = ""
18 @State private var alertMessage = "" 17 @State private var alertMessage = ""
19 @State private var showingAlert = false 18 @State private var showingAlert = false
19 @State private var showingPrice = false
20 20
21 var body: some View { 21 var body: some View {
22 Button(action: purchaseMonthlySubscription) { 22 Button(action: purchaseMonthlySubscription) {
23 RoundedRectangle(cornerRadius: 15) 23 RoundedRectangle(cornerRadius: 15)
24 .frame(height: 60) 24 .frame(height: 60)
25 .overlay( 25 .overlay(
26 VStack { 26 VStack {
27 if showingPrice { 27 if showingPrice {
28 Text(subscribeButtonText) 28 Text("Subscribe for \(price) / month", comment: "Subscribe button")
29 .foregroundColor(.white) 29 .foregroundColor(.white)
30 .fontWeight(.semibold) 30 .fontWeight(.semibold)
31 } else { 31 } else {
32 ProgressView() 32 ProgressView()
33 } 33 }
41 } 41 }
42 42
43 private func fetchMonthlySubscription() { 43 private func fetchMonthlySubscription() {
44 Purchases.shared.offerings { (offerings, error) in 44 Purchases.shared.offerings { (offerings, error) in
45 if let product = offerings?.current?.monthly?.product { 45 if let product = offerings?.current?.monthly?.product {
46 let price = formatCurrency(product.priceLocale, product.price) 46 self.price = formatCurrency(product.priceLocale, product.price)
47 subscribeButtonText = "Subscribe for \(price) / month"
48 showingPrice = true 47 showingPrice = true
49 } 48 }
50 49
51 if let error = error as NSError? { 50 if let error = error as NSError? {
52 alertTitle = error.localizedDescription 51 alertTitle = error.localizedDescription
53 alertMessage = error.localizedFailureReason ?? "If the problem persists send an email to dmartin@dennistech.io" 52 alertMessage = error.localizedFailureReason ?? ""
54 subscribeButtonText = "-" 53 price = "-"
55 showingPrice = true 54 showingPrice = true
56 showingAlert = true 55 showingAlert = true
57 } 56 }
58 } 57 }
59 } 58 }
71 showingSubscriptionPaywall = false 70 showingSubscriptionPaywall = false
72 } 71 }
73 72
74 if let error = error as NSError? { 73 if let error = error as NSError? {
75 alertTitle = error.localizedDescription 74 alertTitle = error.localizedDescription
76 alertMessage = error.localizedFailureReason ?? "If the problem persists send an email to dmartin@dennistech.io" 75 alertMessage = error.localizedFailureReason ?? ""
77 showingPrice = true 76 showingPrice = true
78 showingAlert = true 77 showingAlert = true
79 } 78 }
80 } 79 }
81 80
82 if let error = error as NSError? { 81 if let error = error as NSError? {
83 alertTitle = error.localizedDescription 82 alertTitle = error.localizedDescription
84 alertMessage = error.localizedFailureReason ?? "If the problem persists send an email to dmartin@dennistech.io" 83 alertMessage = error.localizedFailureReason ?? ""
85 showingPrice = true 84 showingPrice = true
86 showingAlert = true 85 showingAlert = true
87 } 86 }
88 } 87 }
89 } 88 }