# HG changeset patch # User Dennis Concepción Martín # Date 1626202593 -3600 # Node ID cdc5f728b105fb7453a2402a43d35c4214a3f40c # Parent 81f4e0a3b1eb99bc5dd26052abc5637f67cb7fc3 Minor UI updates diff -r 81f4e0a3b1eb -r cdc5f728b105 Simoleon.xcodeproj/project.pbxproj --- 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 = ""; }; 95C5B24B2697752700941585 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 95DD4ABA269B33810027CA1F /* CurrencyPairs.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = CurrencyPairs.json; sourceTree = ""; }; - 95E137CC269C9A0600D2C5DC /* SearchCurrencyRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchCurrencyRow.swift; sourceTree = ""; }; 95E137CE269C9D8B00D2C5DC /* CurrencyConversion.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CurrencyConversion.swift; sourceTree = ""; }; 95E137D0269C9F0D00D2C5DC /* SingleFlag.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingleFlag.swift; sourceTree = ""; }; 95E76431269DF531008E9F31 /* PopularCurrencyPairs.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = PopularCurrencyPairs.json; sourceTree = ""; }; @@ -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 */, diff -r 81f4e0a3b1eb -r cdc5f728b105 Simoleon.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate Binary file Simoleon.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate has changed diff -r 81f4e0a3b1eb -r cdc5f728b105 Simoleon/Assets.xcassets/Flags/BTC.imageset/BTC.png Binary file Simoleon/Assets.xcassets/Flags/BTC.imageset/BTC.png has changed diff -r 81f4e0a3b1eb -r cdc5f728b105 Simoleon/Assets.xcassets/Flags/DASH.imageset/DASH.png Binary file Simoleon/Assets.xcassets/Flags/DASH.imageset/DASH.png has changed diff -r 81f4e0a3b1eb -r cdc5f728b105 Simoleon/Assets.xcassets/Flags/ETH.imageset/ETH.png Binary file Simoleon/Assets.xcassets/Flags/ETH.imageset/ETH.png has changed diff -r 81f4e0a3b1eb -r cdc5f728b105 Simoleon/Assets.xcassets/Flags/LTC.imageset/LTC.png Binary file Simoleon/Assets.xcassets/Flags/LTC.imageset/LTC.png has changed diff -r 81f4e0a3b1eb -r cdc5f728b105 Simoleon/Assets.xcassets/Flags/XAG.imageset/XAG.png Binary file Simoleon/Assets.xcassets/Flags/XAG.imageset/XAG.png has changed diff -r 81f4e0a3b1eb -r cdc5f728b105 Simoleon/Assets.xcassets/Flags/XAU.imageset/XAU.png Binary file Simoleon/Assets.xcassets/Flags/XAU.imageset/XAU.png has changed diff -r 81f4e0a3b1eb -r cdc5f728b105 Simoleon/Assets.xcassets/Flags/XPD.imageset/XPD.png Binary file Simoleon/Assets.xcassets/Flags/XPD.imageset/XPD.png has changed diff -r 81f4e0a3b1eb -r cdc5f728b105 Simoleon/Assets.xcassets/Flags/XPT.imageset/XPT.png Binary file Simoleon/Assets.xcassets/Flags/XPT.imageset/XPT.png has changed diff -r 81f4e0a3b1eb -r cdc5f728b105 Simoleon/Assets.xcassets/Flags/XRP.imageset/XRP.png Binary file Simoleon/Assets.xcassets/Flags/XRP.imageset/XRP.png has changed diff -r 81f4e0a3b1eb -r cdc5f728b105 Simoleon/ContentView.swift --- 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 diff -r 81f4e0a3b1eb -r cdc5f728b105 Simoleon/CurrencyConversion.swift --- 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) { diff -r 81f4e0a3b1eb -r cdc5f728b105 Simoleon/Helpers/CurrencyRow.swift --- 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 { diff -r 81f4e0a3b1eb -r cdc5f728b105 Simoleon/Helpers/SearchBar.swift --- 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) diff -r 81f4e0a3b1eb -r cdc5f728b105 Simoleon/Helpers/SearchCurrencyRow.swift --- 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") - } -} diff -r 81f4e0a3b1eb -r cdc5f728b105 Simoleon/Helpers/SearchedCurrencyList.swift --- 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 + } } } }