Mercurial > public > simoleon
comparison Simoleon/Helpers/CurrencySelector.swift @ 152:2584fd74235a
Add new currencies
author | Dennis Concepcion Martin <dennisconcepcionmartin@gmail.com> |
---|---|
date | Mon, 23 Aug 2021 17:14:14 +0100 |
parents | 6eac99e99b96 |
children |
comparison
equal
deleted
inserted
replaced
151:bdedd0cc6cd1 | 152:2584fd74235a |
---|---|
23 If searched currency string is empty: | 23 If searched currency string is empty: |
24 * Show all currencies | 24 * Show all currencies |
25 else: | 25 else: |
26 * Show filtered list of currencies containing searched currency string | 26 * Show filtered list of currencies containing searched currency string |
27 */ | 27 */ |
28 var searchResults: [CurrencyPairModel] { | 28 var searchResults: [String] { |
29 let currencyPairs: [CurrencyPairModel] = try! read(json: "CurrencyPairs.json") | 29 let currencyPairsSupported: [String] = try! read(json: "CurrencyPairs.json") |
30 if searchCurrency.isEmpty { | 30 if searchCurrency.isEmpty { |
31 return currencyPairs.sorted { !$0.isLocked && $1.isLocked } | 31 return currencyPairsSupported.sorted() |
32 } else { | 32 } else { |
33 return currencyPairs.filter { $0.name.contains(searchCurrency.uppercased()) } | 33 return currencyPairsSupported.filter { $0.contains(searchCurrency.uppercased()) } |
34 } | 34 } |
35 } | 35 } |
36 | 36 |
37 var body: some View { | 37 var body: some View { |
38 NavigationView { | 38 NavigationView { |
41 .padding() | 41 .padding() |
42 .accessibilityIdentifier("CurrencySearchBar") | 42 .accessibilityIdentifier("CurrencySearchBar") |
43 | 43 |
44 List { | 44 List { |
45 if entitlementIsActive { | 45 if entitlementIsActive { |
46 ForEach(searchResults, id: \.self) { currencyPair in | 46 ForEach(searchResults, id: \.self) { currencyPairsSupported in |
47 Button(action: { | 47 Button(action: { |
48 self.currencyPair = currencyPair.name | 48 self.currencyPair = currencyPairsSupported |
49 showingCurrencySelector = false | 49 showingCurrencySelector = false |
50 }) { | 50 }) { |
51 CurrencyRow(currencyPairName: currencyPair.name) | 51 CurrencyRow(currencyPairName: currencyPairsSupported) |
52 } | 52 } |
53 } | 53 } |
54 } else { | 54 } else { |
55 ForEach(searchResults, id: \.self) { currencyPair in | 55 ForEach(searchResults, id: \.self) { currencyPairsSupported in |
56 Button(action: { select(currencyPair) }) { | 56 Button(action: { select(currencyPairsSupported) }) { |
57 CurrencyRow(currencyPairName: currencyPair.name, isLocked: currencyPair.isLocked) | 57 CurrencyRow(currencyPairName: currencyPairsSupported, isLocked: false) |
58 } | 58 } |
59 } | 59 } |
60 } | 60 } |
61 } | 61 } |
62 .id(UUID()) | 62 .id(UUID()) |
84 If user is subscribed: | 84 If user is subscribed: |
85 * Select currency and dismiss currency selector | 85 * Select currency and dismiss currency selector |
86 else: | 86 else: |
87 * Show subscription paywall | 87 * Show subscription paywall |
88 */ | 88 */ |
89 private func select(_ currencyPair: CurrencyPairModel) { | 89 private func select(_ currencyPair: String) { |
90 if currencyPair.isLocked { | 90 // if currencyPair.isLocked { |
91 showingSubscriptionPaywall = true | 91 // showingSubscriptionPaywall = true |
92 } else { | 92 // } else { |
93 self.currencyPair = currencyPair.name | 93 // self.currencyPair = currencyPair.name |
94 showingCurrencySelector = false | 94 // showingCurrencySelector = false |
95 } | 95 // } |
96 } | 96 } |
97 | 97 |
98 // Check if user subscription is active | 98 // Check if user subscription is active |
99 private func checkEntitlement() { | 99 private func checkEntitlement() { |
100 #if SCREENSHOTS | 100 #if SCREENSHOTS |