diff Simoleon/Helpers/CurrencyRow.swift @ 11:a62e5e4a4f02

Implementing networking
author Dennis Concepción Martín <dennisconcepcionmartin@gmail.com>
date Tue, 13 Jul 2021 12:14:42 +0100
parents ed35ef4738b9
children cdc5f728b105
line wrap: on
line diff
--- a/Simoleon/Helpers/CurrencyRow.swift	Mon Jul 12 17:44:55 2021 +0100
+++ b/Simoleon/Helpers/CurrencyRow.swift	Tue Jul 13 12:14:42 2021 +0100
@@ -9,22 +9,22 @@
 
 struct CurrencyRow: View {
     var currencyQuote: CurrencyQuoteModel
-    let currencies: [String: CurrencyModel] = parseJson("Currencies.json")
+    let currenciesMetadata: [String: CurrencyMetadataModel] = parseJson("CurrencyMetadata.json")
     
     var body: some View {
-        VStack {
+        VStack(alignment: .leading) {
             RoundedRectangle(cornerRadius: 10)
-                .rectangleModifier(Color("Bone"), 100)
+                .rectangleModifier(Color("Shadow"), 100)
             
             RoundedRectangle(cornerRadius: 10)
                 .rectangleModifier(Color(.systemBackground), 100)
                 .overlay(
                     HStack {
-                        let symbols = currencyQuote.symbol.split(separator: "/")
-                        let mainCurrencyFlag = currencies[String(symbols[0])]!.flag
-                        let secondaryCurrencyFlag = currencies[String(symbols[1])]!.flag
+                        let symbols = currencyQuote.symbol!.split(separator: "/")
+                        let mainCurrencyFlag = currenciesMetadata[String(symbols[0])]!.flag
+                        let secondaryCurrencyFlag = currenciesMetadata[String(symbols[1])]!.flag
                         
-                        SmallFlagsPair(mainCurrencyFlag: mainCurrencyFlag, secondaryCurrencyFlag: secondaryCurrencyFlag)
+                        FlagPair(mainCurrencyFlag: mainCurrencyFlag, secondaryCurrencyFlag: secondaryCurrencyFlag)
                         
                         VStack(alignment: .leading) {
                             Text("\(String(symbols[0]))")
@@ -37,7 +37,7 @@
                         
                         VStack(alignment: .leading) {
                             Text("Bid")
-                            Text("\(currencyQuote.bid, specifier: "%.4f")")
+                            Text("\(currencyQuote.bid!, specifier: "%.4f")")
                                 .fontWeight(.semibold)
                                 
                         }
@@ -45,11 +45,14 @@
                         
                         VStack(alignment: .leading) {
                             Text("Ask")
-                            Text("\(currencyQuote.ask, specifier: "%.4f")")
+                            Text("\(currencyQuote.ask!, specifier: "%.4f")")
                                 .fontWeight(.semibold)
                                 
                         }
+                        
+                        Spacer()
                     }
+                    .padding(.horizontal)
                 )
                 .offset(x: -10.0, y: -120.0)
                 .padding(.bottom, -120)
@@ -58,6 +61,15 @@
         .padding(.horizontal)
     }
 }
+extension RoundedRectangle {
+    func rectangleModifier(_ colour: Color, _ height: CGFloat) -> some View {
+        self
+            .strokeBorder(Color("Border"), lineWidth: 2)
+            .background(RoundedRectangle(cornerRadius: 10).foregroundColor(colour))
+            .frame(height: height)
+            
+    }
+}
 
 struct CurrencyRow_Previews: PreviewProvider {
     static var previews: some View {