changeset 13:cdc5f728b105

Minor UI updates
author Dennis Concepción Martín <dennisconcepcionmartin@gmail.com>
date Tue, 13 Jul 2021 19:56:33 +0100
parents 81f4e0a3b1eb
children 03ce7421c6f4
files Simoleon.xcodeproj/project.pbxproj Simoleon.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate Simoleon/Assets.xcassets/Flags/BTC.imageset/BTC.png Simoleon/Assets.xcassets/Flags/DASH.imageset/DASH.png Simoleon/Assets.xcassets/Flags/ETH.imageset/ETH.png Simoleon/Assets.xcassets/Flags/LTC.imageset/LTC.png Simoleon/Assets.xcassets/Flags/XAG.imageset/XAG.png Simoleon/Assets.xcassets/Flags/XAU.imageset/XAU.png Simoleon/Assets.xcassets/Flags/XPD.imageset/XPD.png Simoleon/Assets.xcassets/Flags/XPT.imageset/XPT.png Simoleon/Assets.xcassets/Flags/XRP.imageset/XRP.png Simoleon/ContentView.swift Simoleon/CurrencyConversion.swift Simoleon/Helpers/CurrencyRow.swift Simoleon/Helpers/SearchBar.swift Simoleon/Helpers/SearchCurrencyRow.swift Simoleon/Helpers/SearchedCurrencyList.swift
diffstat 17 files changed, 38 insertions(+), 83 deletions(-) [+]
line wrap: on
line diff
--- a/Simoleon.xcodeproj/project.pbxproj	Tue Jul 13 18:16:07 2021 +0100
+++ b/Simoleon.xcodeproj/project.pbxproj	Tue Jul 13 19:56:33 2021 +0100
@@ -24,7 +24,6 @@
 		95C5B23F2697752700941585 /* SimoleonTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95C5B23E2697752700941585 /* SimoleonTests.swift */; };
 		95C5B24A2697752700941585 /* SimoleonUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95C5B2492697752700941585 /* SimoleonUITests.swift */; };
 		95DD4ABB269B33810027CA1F /* CurrencyPairs.json in Resources */ = {isa = PBXBuildFile; fileRef = 95DD4ABA269B33810027CA1F /* CurrencyPairs.json */; };
-		95E137CD269C9A0600D2C5DC /* SearchCurrencyRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95E137CC269C9A0600D2C5DC /* SearchCurrencyRow.swift */; };
 		95E137CF269C9D8B00D2C5DC /* CurrencyConversion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95E137CE269C9D8B00D2C5DC /* CurrencyConversion.swift */; };
 		95E137D1269C9F0D00D2C5DC /* SingleFlag.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95E137D0269C9F0D00D2C5DC /* SingleFlag.swift */; };
 		95E76432269DF531008E9F31 /* PopularCurrencyPairs.json in Resources */ = {isa = PBXBuildFile; fileRef = 95E76431269DF531008E9F31 /* PopularCurrencyPairs.json */; };
@@ -74,7 +73,6 @@
 		95C5B2492697752700941585 /* SimoleonUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimoleonUITests.swift; sourceTree = "<group>"; };
 		95C5B24B2697752700941585 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
 		95DD4ABA269B33810027CA1F /* CurrencyPairs.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = CurrencyPairs.json; sourceTree = "<group>"; };
-		95E137CC269C9A0600D2C5DC /* SearchCurrencyRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchCurrencyRow.swift; sourceTree = "<group>"; };
 		95E137CE269C9D8B00D2C5DC /* CurrencyConversion.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CurrencyConversion.swift; sourceTree = "<group>"; };
 		95E137D0269C9F0D00D2C5DC /* SingleFlag.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingleFlag.swift; sourceTree = "<group>"; };
 		95E76431269DF531008E9F31 /* PopularCurrencyPairs.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = PopularCurrencyPairs.json; sourceTree = "<group>"; };
@@ -223,7 +221,6 @@
 				956C28CB269B58A0005A4595 /* FlagPair.swift */,
 				95E137D0269C9F0D00D2C5DC /* SingleFlag.swift */,
 				956C28C9269B5893005A4595 /* CurrencyRow.swift */,
-				95E137CC269C9A0600D2C5DC /* SearchCurrencyRow.swift */,
 				95E76433269DF63D008E9F31 /* SearchedCurrencyList.swift */,
 			);
 			path = Helpers;
@@ -374,7 +371,6 @@
 				9555933F269B0E47000FD726 /* CurrencyMetadataModel.swift in Sources */,
 				95C5B2312697752700941585 /* Persistence.swift in Sources */,
 				9555933A269B0AB8000FD726 /* ParseJson.swift in Sources */,
-				95E137CD269C9A0600D2C5DC /* SearchCurrencyRow.swift in Sources */,
 				95E137CF269C9D8B00D2C5DC /* CurrencyConversion.swift in Sources */,
 				95C5B22A2697752600941585 /* ContentView.swift in Sources */,
 				95FE659C269AFB54008745DE /* SearchBar.swift in Sources */,
Binary file Simoleon.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate has changed
Binary file Simoleon/Assets.xcassets/Flags/BTC.imageset/BTC.png has changed
Binary file Simoleon/Assets.xcassets/Flags/DASH.imageset/DASH.png has changed
Binary file Simoleon/Assets.xcassets/Flags/ETH.imageset/ETH.png has changed
Binary file Simoleon/Assets.xcassets/Flags/LTC.imageset/LTC.png has changed
Binary file Simoleon/Assets.xcassets/Flags/XAG.imageset/XAG.png has changed
Binary file Simoleon/Assets.xcassets/Flags/XAU.imageset/XAU.png has changed
Binary file Simoleon/Assets.xcassets/Flags/XPD.imageset/XPD.png has changed
Binary file Simoleon/Assets.xcassets/Flags/XPT.imageset/XPT.png has changed
Binary file Simoleon/Assets.xcassets/Flags/XRP.imageset/XRP.png has changed
--- a/Simoleon/ContentView.swift	Tue Jul 13 18:16:07 2021 +0100
+++ b/Simoleon/ContentView.swift	Tue Jul 13 19:56:33 2021 +0100
@@ -10,10 +10,8 @@
 
 struct ContentView: View {
     @State private var showingView = false
-    
     @State private var text = ""
     @State private var isEditing = false
-    
     @State private var popularCurrencyPairsQuote = [CurrencyQuoteModel()]
     @State private var popularSelectedCurrencyPairQuote: CurrencyQuoteModel? = nil
     
@@ -26,6 +24,7 @@
                     VStack(spacing: 20) {
                         SearchBar(text: $text, isEditing: $isEditing)
                             .padding(.vertical)
+                            .padding(.top)
                         
                         if text.isEmpty {
                             ForEach(popularCurrencyPairsQuote, id: \.self) { currencyQuote in
--- a/Simoleon/CurrencyConversion.swift	Tue Jul 13 18:16:07 2021 +0100
+++ b/Simoleon/CurrencyConversion.swift	Tue Jul 13 19:56:33 2021 +0100
@@ -73,6 +73,7 @@
                 }
                 .padding(.vertical)
             }
+            .padding(.top)
             .navigationTitle("Conversion")
             .toolbar {
                 ToolbarItem(placement: .cancellationAction) {
--- a/Simoleon/Helpers/CurrencyRow.swift	Tue Jul 13 18:16:07 2021 +0100
+++ b/Simoleon/Helpers/CurrencyRow.swift	Tue Jul 13 19:56:33 2021 +0100
@@ -37,16 +37,20 @@
                         
                         VStack(alignment: .leading) {
                             Text("Bid")
-                            Text("\(currencyQuote.bid!, specifier: "%.4f")")
+                            let bid = currencyQuote.bid!
+                            Text("\(bid, specifier: createSpecifier(bid))")
                                 .fontWeight(.semibold)
+                                .lineLimit(1)
                                 
                         }
                         .padding(.trailing)
                         
                         VStack(alignment: .leading) {
                             Text("Ask")
-                            Text("\(currencyQuote.ask!, specifier: "%.4f")")
+                            let ask = currencyQuote.ask!
+                            Text("\(ask, specifier: createSpecifier(ask))")
                                 .fontWeight(.semibold)
+                                .lineLimit(1)
                                 
                         }
                         
@@ -60,6 +64,18 @@
         .padding(.leading, 10)
         .padding(.horizontal)
     }
+    
+    /*
+     Choose how many decimals depending on whether the price is hundreds, thousands, etc
+     */
+    
+    private func createSpecifier(_ amount: Float) -> String {
+        if amount >= 10 {
+            return "%.2f"
+        } else {
+            return "%.4f"
+        }
+    }
 }
 extension RoundedRectangle {
     func rectangleModifier(_ colour: Color, _ height: CGFloat) -> some View {
--- a/Simoleon/Helpers/SearchBar.swift	Tue Jul 13 18:16:07 2021 +0100
+++ b/Simoleon/Helpers/SearchBar.swift	Tue Jul 13 19:56:33 2021 +0100
@@ -33,7 +33,7 @@
                             .padding(.leading)
                     }
                 )
-                .offset(x: -5, y: -77)
+                .offset(x: -5, y: -78)
                 .padding(.bottom, -78)
         }
         .padding(.leading, 5)
--- a/Simoleon/Helpers/SearchCurrencyRow.swift	Tue Jul 13 18:16:07 2021 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,59 +0,0 @@
-//
-//  SearchCurrencyRow.swift
-//  Simoleon
-//
-//  Created by Dennis Concepción Martín on 12/07/2021.
-//
-
-import SwiftUI
-
-struct SearchCurrencyRow: View {
-    var currencyPair: String
-    let currenciesMetadata: [String: CurrencyMetadataModel] = parseJson("CurrencyMetadata.json")
-    
-    var body: some View {
-        VStack {
-            RoundedRectangle(cornerRadius: 10)
-                .rectangleModifier(Color("Shadow"), 100)
-            
-            RoundedRectangle(cornerRadius: 10)
-                .rectangleModifier(Color(.systemBackground), 100)
-                .overlay(
-                    HStack {
-                        let symbols = currencyPair.split(separator: "/")
-                        let mainCurrencyFlag = currenciesMetadata[String(symbols[0])]!.flag
-                        let secondaryCurrencyFlag = currenciesMetadata[String(symbols[1])]!.flag
-                        
-                        FlagPair(mainCurrencyFlag: mainCurrencyFlag, secondaryCurrencyFlag: secondaryCurrencyFlag)
-                        
-                        VStack(alignment: .leading) {
-                            Text("\(currencyPair)")
-                                .fontWeight(.semibold)
-                            
-                            Group {
-                                Text("\(currenciesMetadata[String(symbols[0])]!.name)")
-                                Text("\(currenciesMetadata[String(symbols[1])]!.name)")
-                            }
-                            .font(.callout)
-                            .opacity(0.7)
-                            .lineLimit(1)
-                        }
-                        .padding(.horizontal)
-                        
-                        Spacer()
-                    }
-                    .padding(.horizontal)
-                )
-                .offset(x: -10.0, y: -120.0)
-                .padding(.bottom, -120)
-        }
-        .padding(.leading, 10)
-        .padding(.horizontal)
-    }
-}
-
-struct SearchCurrencyRow_Previews: PreviewProvider {
-    static var previews: some View {
-        SearchCurrencyRow(currencyPair: "USD/GBP")
-    }
-}
--- a/Simoleon/Helpers/SearchedCurrencyList.swift	Tue Jul 13 18:16:07 2021 +0100
+++ b/Simoleon/Helpers/SearchedCurrencyList.swift	Tue Jul 13 19:56:33 2021 +0100
@@ -39,21 +39,23 @@
      Request API
      */
     private func requestCurrencyPairsQuote() {
-        let searchedCurrencyPairsArray: [String] = parseJson("CurrencyPairs.json")
-        let filteredSearchedCurrencyPairsArray = searchedCurrencyPairsArray.filter { $0.contains(text.uppercased()) }
-        
-        if filteredSearchedCurrencyPairsArray.count <= 327 {
-            let searchedCurrencyPairsString = filteredSearchedCurrencyPairsArray.joined(separator: ",")
-            let quotes = searchedCurrencyPairsString.replacingOccurrences(of: "/", with: "-")
-            let url = "https://api.simoleon.app/quotes=\(quotes)"
-        
-            // Request popular currencies
-            AF.request(url).responseDecodable(of: [CurrencyQuoteModel].self) { response in
-                if let searchedCurrencyPairsQuote = response.value {
-                    self.searchedCurrencyPairsQuote = searchedCurrencyPairsQuote
-                    self.showingView = true
-                } else {
-                    // Handle error
+        if !text.isEmpty {
+            let searchedCurrencyPairsArray: [String] = parseJson("CurrencyPairs.json")
+            let filteredSearchedCurrencyPairsArray = searchedCurrencyPairsArray.filter { $0.contains(text.uppercased()) }
+            
+            if filteredSearchedCurrencyPairsArray.count <= 327 {
+                let searchedCurrencyPairsString = filteredSearchedCurrencyPairsArray.joined(separator: ",")
+                let quotes = searchedCurrencyPairsString.replacingOccurrences(of: "/", with: "-")
+                let url = "https://api.simoleon.app/quotes=\(quotes)"
+            
+                // Request popular currencies
+                AF.request(url).responseDecodable(of: [CurrencyQuoteModel].self) { response in
+                    if let searchedCurrencyPairsQuote = response.value {
+                        self.searchedCurrencyPairsQuote = searchedCurrencyPairsQuote
+                        self.showingView = true
+                    } else {
+                        // Handle error
+                    }
                 }
             }
         }