Mercurial > public > simoleon
comparison Simoleon/Helpers/FavoriteRow.swift @ 187:13d5a8deb6c2
add AboutView and FavoritesView
author | Dennis Concepcion Martin <dennisconcepcionmartin@gmail.com> |
---|---|
date | Thu, 23 Dec 2021 16:12:22 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
186:1ebd1c5dd302 | 187:13d5a8deb6c2 |
---|---|
1 // | |
2 // FavoriteRow.swift | |
3 // Simoleon | |
4 // | |
5 // Created by Dennis Concepción Martín on 23/12/21. | |
6 // | |
7 | |
8 import SwiftUI | |
9 | |
10 struct FavoriteRow: View { | |
11 var baseCurrency: String | |
12 var quoteCurrency: String | |
13 | |
14 var body: some View { | |
15 let baseCurrencyObject = getCurrencyObject(with: baseCurrency) | |
16 let quoteCurrencyObject = getCurrencyObject(with: quoteCurrency) | |
17 NavigationLink(destination: | |
18 ConversionView( | |
19 showNavigationView: false, | |
20 baseCurrency: baseCurrencyObject, | |
21 quoteCurrency: quoteCurrencyObject | |
22 ) | |
23 ) { | |
24 HStack { | |
25 Flag(currencyCode: baseCurrency) | |
26 Flag(currencyCode: quoteCurrency) | |
27 .offset(x: -25) | |
28 .padding(.trailing, -25) | |
29 | |
30 let pairObject = getPairObject() | |
31 VStack(alignment: .leading) { | |
32 Text(pairObject.symbol) | |
33 .font(.headline) | |
34 | |
35 Text(pairObject.name) | |
36 .font(.callout) | |
37 .opacity(0.6) | |
38 } | |
39 .padding(.leading) | |
40 } | |
41 } | |
42 } | |
43 | |
44 // Get pair object | |
45 private func getPairObject() -> SupportedPairResult { | |
46 let pairResponse: SupportedPairResponse = readJson(from: "SupportedCurrencies.json") | |
47 let pair = pairResponse.pairs.filter { $0.fromCurrency == baseCurrency && $0.toCurrency == quoteCurrency } | |
48 | |
49 return pair.first! | |
50 } | |
51 | |
52 // Get currency object | |
53 private func getCurrencyObject(with currencyCode: String) -> SupportedCurrencyResult { | |
54 let currencyResponse: SupportedCurrencyResponse = readJson(from: "SupportedCurrencies.json") | |
55 let currency = currencyResponse.currencies.filter { $0.code == currencyCode } | |
56 | |
57 return currency.first! | |
58 } | |
59 } | |
60 | |
61 struct FavoriteRow_Previews: PreviewProvider { | |
62 static var previews: some View { | |
63 FavoriteRow(baseCurrency: "EUR", quoteCurrency: "USD") | |
64 } | |
65 } |