comparison Simoleon/Helpers/CurrencySelector.swift @ 42:d25b02d439d4

Minor updates subscription and legal requirements
author Dennis Concepción Martín <dennisconcepcionmartin@gmail.com>
date Mon, 26 Jul 2021 15:35:06 +0100
parents e521236028e0
children 2eb05f396fcd
comparison
equal deleted inserted replaced
41:7703c122ce96 42:d25b02d439d4
9 import Purchases 9 import Purchases
10 10
11 struct CurrencySelector: View { 11 struct CurrencySelector: View {
12 @Binding var currencyPair: String 12 @Binding var currencyPair: String
13 @Binding var showingCurrencySelector: Bool 13 @Binding var showingCurrencySelector: Bool
14 @EnvironmentObject var subscriptionController: SubscriptionController
15 14
16 @State private var searchCurrency = "" 15 @State private var searchCurrency = ""
17 @State private var showingSubscriptionPaywall = false 16 @State private var showingSubscriptionPaywall = false
18 17
19 var body: some View { 18 var body: some View {
32 .gesture(DragGesture() 31 .gesture(DragGesture()
33 .onChanged({ _ in 32 .onChanged({ _ in
34 UIApplication.shared.dismissKeyboard() 33 UIApplication.shared.dismissKeyboard()
35 }) 34 })
36 ) 35 )
36 .sheet(isPresented: $showingSubscriptionPaywall) {
37 SubscriptionPaywall(showingSubscriptionPaywall: $showingSubscriptionPaywall)
38 }
37 .navigationTitle(Text("Currencies", comment: "Navigation title")) 39 .navigationTitle(Text("Currencies", comment: "Navigation title"))
38 .navigationBarTitleDisplayMode(.inline) 40 .navigationBarTitleDisplayMode(.inline)
39 .toolbar { 41 .toolbar {
40 ToolbarItem(placement: .cancellationAction) { 42 ToolbarItem(placement: .cancellationAction) {
41 Button(action: { showingCurrencySelector = false }) { 43 Button(action: { showingCurrencySelector = false }) {
42 Text("Cancel", comment: "Button to dismiss currency selector") 44 Text("Cancel", comment: "Button to dismiss currency selector")
43 } 45 }
44 } 46 }
45 } 47 }
46 } 48 }
47 .sheet(isPresented: $showingSubscriptionPaywall) {
48 Subscription(showingSubscriptionPaywall: $showingSubscriptionPaywall)
49 }
50 } 49 }
51 50
51 /*
52 If searched currency string is empty -> show all currencies
53 else -> show filtered list of currencies containing searched currency string
54 */
52 private func currencyPairs() -> [String] { 55 private func currencyPairs() -> [String] {
53 let currencyPairs: [String] = parseJson("CurrencyPairs.json") 56 let currencyPairs: [String] = parseJson("CurrencyPairs.json")
54 57
55 if searchCurrency.isEmpty { 58 if searchCurrency.isEmpty {
56 return currencyPairs 59 return currencyPairs
58 return currencyPairs.filter { $0.contains(searchCurrency.uppercased()) } 61 return currencyPairs.filter { $0.contains(searchCurrency.uppercased()) }
59 } 62 }
60 } 63 }
61 64
62 65
66 /*
67 If user is subscribed -> select currency and dismiss currency selector
68 else -> show subscription paywall
69 */
63 private func select(_ currencyPair: String) { 70 private func select(_ currencyPair: String) {
64 if subscriptionController.isActive { 71 Purchases.shared.purchaserInfo { (purchaserInfo, error) in
65 self.currencyPair = currencyPair 72 if purchaserInfo?.entitlements["all"]?.isActive == true {
66 showingCurrencySelector = false 73 self.currencyPair = currencyPair
67 } else { 74 showingCurrencySelector = false
68 showingSubscriptionPaywall = true 75 } else {
76 showingSubscriptionPaywall = true
77 }
69 } 78 }
70 } 79 }
71 } 80 }
72 81
73 82
74 struct CurrencySelector_Previews: PreviewProvider { 83 struct CurrencySelector_Previews: PreviewProvider {
75 static var previews: some View { 84 static var previews: some View {
76 CurrencySelector(currencyPair: .constant("USD/GBP"), showingCurrencySelector: .constant(false)) 85 CurrencySelector(currencyPair: .constant("USD/GBP"), showingCurrencySelector: .constant(false))
77 .environmentObject(SubscriptionController())
78 } 86 }
79 } 87 }