Mercurial > public > simoleon
comparison Simoleon/Conversion.swift @ 22:3596690dda73
Add Config files and implementing Settings
author | Dennis Concepción Martín <dennisconcepcionmartin@gmail.com> |
---|---|
date | Tue, 20 Jul 2021 09:02:51 +0100 |
parents | c3dda63f50ed |
children | 699b5bb619db |
comparison
equal
deleted
inserted
replaced
21:c3dda63f50ed | 22:3596690dda73 |
---|---|
23 VStack(alignment: .leading) { | 23 VStack(alignment: .leading) { |
24 HStack { | 24 HStack { |
25 Button(action: { showingCurrencySelector = true }) { | 25 Button(action: { showingCurrencySelector = true }) { |
26 RoundedRectangle(cornerRadius: 25) | 26 RoundedRectangle(cornerRadius: 25) |
27 .foregroundColor(Color(.secondarySystemBackground)) | 27 .foregroundColor(Color(.secondarySystemBackground)) |
28 .frame(height: 75) | 28 .frame(height: 65) |
29 .overlay(CurrencyRow(currencyPair: currencyPair).padding(.horizontal)) | 29 .overlay(CurrencyRow(currencyPair: currencyPair).padding(.horizontal)) |
30 } | 30 } |
31 | 31 |
32 FavouriteButton(currencyPair: currencyPair) | 32 FavouriteButton(currencyPair: currencyPair) |
33 } | 33 } |
50 }) | 50 }) |
51 .sheet(isPresented: $showingCurrencySelector) { | 51 .sheet(isPresented: $showingCurrencySelector) { |
52 CurrencySelector(currencyPair: $currencyPair, showingCurrencySelector: $showingCurrencySelector) | 52 CurrencySelector(currencyPair: $currencyPair, showingCurrencySelector: $showingCurrencySelector) |
53 } | 53 } |
54 } | 54 } |
55 .navigationTitle("Conversion") | |
56 .toolbar { | |
57 ToolbarItem(placement: .cancellationAction) { | |
58 if isEditing { | |
59 Button("Cancel", action: { | |
60 UIApplication.shared.dismissKeyboard() | |
61 isEditing = false | |
62 }) | |
63 } | |
64 } | |
65 } | |
55 .if(UIDevice.current.userInterfaceIdiom == .phone) { content in | 66 .if(UIDevice.current.userInterfaceIdiom == .phone) { content in |
56 NavigationView { | 67 NavigationView { content } |
57 content | |
58 .navigationTitle("Conversion") | |
59 .toolbar { | |
60 ToolbarItem(placement: .cancellationAction) { | |
61 if isEditing { | |
62 Button("Cancel", action: { | |
63 UIApplication.shared.dismissKeyboard() | |
64 isEditing = false | |
65 }) | |
66 } | |
67 } | |
68 } | |
69 } | |
70 } | 68 } |
71 } | 69 } |
72 | 70 |
73 private func request(_ currencyPair: String) { | 71 private func request(_ currencyPair: String) { |
74 let url = "https://api.1forge.com/quotes?pairs=\(currencyPair)&api_key=BFWeJQ3jJtqqpDv5ArNis59pAlFcQ4KF" | 72 let url = "\(readConfig("API_URL")!)quotes?pairs=\(currencyPair)&api_key=\(readConfig("API_KEY")!)" |
75 | 73 |
76 AF.request(url).responseDecodable(of: [CurrencyQuoteModel].self) { response in | 74 Simoleon.request(url: url, model: [CurrencyQuoteModel].self) { response in |
77 self.showingConversion = false | 75 self.showingConversion = false |
78 | 76 if let price = response.first?.price { |
79 if let currencyQuotes = response.value { | 77 self.price = price |
80 if let price = currencyQuotes.first?.price { | 78 self.showingConversion = true |
81 self.price = price | |
82 self.showingConversion = true | |
83 } else { | |
84 // Handle error | |
85 } | |
86 } else { | 79 } else { |
87 // Handle error | 80 // Handle error |
88 } | 81 } |
89 } | 82 } |
90 } | 83 } |
91 } | 84 } |
92 | 85 |