Mercurial > public > simoleon
comparison Simoleon/ConversionView.swift @ 187:13d5a8deb6c2
add AboutView and FavoritesView
author | Dennis Concepcion Martin <dennisconcepcionmartin@gmail.com> |
---|---|
date | Thu, 23 Dec 2021 16:12:22 +0100 |
parents | 1ebd1c5dd302 |
children | e4f5dcf4d596 |
comparison
equal
deleted
inserted
replaced
186:1ebd1c5dd302 | 187:13d5a8deb6c2 |
---|---|
9 | 9 |
10 struct ConversionView: View { | 10 struct ConversionView: View { |
11 var showNavigationView: Bool? | 11 var showNavigationView: Bool? |
12 | 12 |
13 // CurrencySelector variables | 13 // CurrencySelector variables |
14 @State private var baseCurrency = SupportedCurrencyResult(code: "EUR", name: "Euro", isCrypto: 0) | 14 @State var baseCurrency: SupportedCurrencyResult |
15 @State private var quoteCurrency = SupportedCurrencyResult(code: "CHF", name: "Swiss Franc", isCrypto: 0) | 15 @State var quoteCurrency: SupportedCurrencyResult |
16 @State private var showingCurrencyList = false | 16 @State private var showingCurrencyList = false |
17 @State private var selecting: Selection = .baseCurrency | 17 @State private var selecting: Selection = .baseCurrency |
18 | 18 |
19 // CurrencyTextfield variables | 19 // CurrencyTextfield variables |
20 @State private var amount = "1" | 20 @State private var amount = "1" |
38 Button(action: { showCurrencyList(selecting: .quoteCurrency)}) { | 38 Button(action: { showCurrencyList(selecting: .quoteCurrency)}) { |
39 CurrencySelectorLabel(currency: quoteCurrency) | 39 CurrencySelectorLabel(currency: quoteCurrency) |
40 } | 40 } |
41 | 41 |
42 // MARK: - Favorite button | 42 // MARK: - Favorite button |
43 FavoriteButton() | 43 FavoriteButton(baseCurrency: $baseCurrency, quoteCurrency: $quoteCurrency) |
44 | 44 |
45 } | 45 } |
46 .padding(.bottom) | 46 .padding(.bottom) |
47 | 47 |
48 // MARK: - Conversion box | 48 // MARK: - Conversion box |
61 latestRate: latestRate, | 61 latestRate: latestRate, |
62 currencyCode: quoteCurrency.code, | 62 currencyCode: quoteCurrency.code, |
63 amount: $amount | 63 amount: $amount |
64 ) | 64 ) |
65 } | 65 } |
66 .padding() | 66 .padding(.horizontal) |
67 .sheet(isPresented: $showingCurrencyList) { | 67 .sheet(isPresented: $showingCurrencyList) { |
68 CurrencyList(baseCurrency: $baseCurrency, quoteCurrency: $quoteCurrency, selecting: selecting) | 68 CurrencyList(baseCurrency: $baseCurrency, quoteCurrency: $quoteCurrency, selecting: selecting) |
69 } | 69 } |
70 } | 70 } |
71 .onAppear { | 71 .onAppear { |
94 private func getConversion() { | 94 private func getConversion() { |
95 let currencyPair = "\(baseCurrency.code)\(quoteCurrency.code)" | 95 let currencyPair = "\(baseCurrency.code)\(quoteCurrency.code)" |
96 let url = "https://api.simoleon.app/fx/latest?symbols=\(currencyPair)" | 96 let url = "https://api.simoleon.app/fx/latest?symbols=\(currencyPair)" |
97 httpRequest(url: url, model: CurrencyLatestRateResponse.self) { response in | 97 httpRequest(url: url, model: CurrencyLatestRateResponse.self) { response in |
98 latestRate = response | 98 latestRate = response |
99 print(latestRate.message.first!.timestamp) | |
100 if latestRate.message.isEmpty { | 99 if latestRate.message.isEmpty { |
101 // Handle exception | 100 // Handle exception |
102 } else { | 101 } else { |
103 showConversion = true | 102 showConversion = true |
104 } | 103 } |
110 case baseCurrency, quoteCurrency | 109 case baseCurrency, quoteCurrency |
111 } | 110 } |
112 | 111 |
113 struct ConversionView_Previews: PreviewProvider { | 112 struct ConversionView_Previews: PreviewProvider { |
114 static var previews: some View { | 113 static var previews: some View { |
115 ConversionView(showNavigationView: true) | 114 ConversionView( |
115 baseCurrency: SupportedCurrencyResult(code: "EUR", name: "Euro", isCrypto: 0), | |
116 quoteCurrency: SupportedCurrencyResult(code: "USD", name: "U.S. Dollar", isCrypto: 0) | |
117 ) | |
116 } | 118 } |
117 } | 119 } |