diff 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
line wrap: on
line diff
--- a/Simoleon/Conversion.swift	Mon Jul 19 19:27:12 2021 +0100
+++ b/Simoleon/Conversion.swift	Tue Jul 20 09:02:51 2021 +0100
@@ -25,7 +25,7 @@
                     Button(action: { showingCurrencySelector = true }) {
                         RoundedRectangle(cornerRadius: 25)
                             .foregroundColor(Color(.secondarySystemBackground))
-                            .frame(height: 75)
+                            .frame(height: 65)
                             .overlay(CurrencyRow(currencyPair: currencyPair).padding(.horizontal))
                     }
                     
@@ -52,39 +52,32 @@
                 CurrencySelector(currencyPair: $currencyPair, showingCurrencySelector: $showingCurrencySelector)
             }
         }
+        .navigationTitle("Conversion")
+        .toolbar {
+            ToolbarItem(placement: .cancellationAction) {
+                if isEditing {
+                    Button("Cancel", action: {
+                        UIApplication.shared.dismissKeyboard()
+                        isEditing = false
+                    })
+                }
+            }
+        }
         .if(UIDevice.current.userInterfaceIdiom == .phone) { content in
-            NavigationView {
-                content
-                    .navigationTitle("Conversion")
-                    .toolbar {
-                        ToolbarItem(placement: .cancellationAction) {
-                            if isEditing {
-                                Button("Cancel", action: {
-                                    UIApplication.shared.dismissKeyboard()
-                                    isEditing = false
-                                })
-                            }
-                        }
-                    }
-            }
+            NavigationView { content }
         }
     }
     
     private func request(_ currencyPair: String) {
-        let url = "https://api.1forge.com/quotes?pairs=\(currencyPair)&api_key=BFWeJQ3jJtqqpDv5ArNis59pAlFcQ4KF"
+        let url = "\(readConfig("API_URL")!)quotes?pairs=\(currencyPair)&api_key=\(readConfig("API_KEY")!)"
         
-        AF.request(url).responseDecodable(of: [CurrencyQuoteModel].self) { response in
+        Simoleon.request(url: url, model: [CurrencyQuoteModel].self) { response in
             self.showingConversion = false
-            
-            if let currencyQuotes = response.value {
-                if let price = currencyQuotes.first?.price {
-                    self.price = price
-                    self.showingConversion =  true
-                } else {
-//                    Handle error
-                }
+            if let price = response.first?.price {
+                self.price = price
+                self.showingConversion =  true
             } else {
-//               Handle error
+                // Handle error
             }
         }
     }