changeset 159:35628bac01f5

Fix a bug that selected wrong symbol in pair
author Dennis Concepcion Martin <dennisconcepcionmartin@gmail.com>
date Sat, 28 Aug 2021 19:18:50 +0100
parents 82bd84c5973c
children 0c589138a6f3
files Simoleon/ConversionView.swift Simoleon/Helpers/Persistence.swift Simoleon/UI/CurrencySelector.swift
diffstat 3 files changed, 14 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/Simoleon/ConversionView.swift	Sat Aug 28 19:17:55 2021 +0100
+++ b/Simoleon/ConversionView.swift	Sat Aug 28 19:18:50 2021 +0100
@@ -21,7 +21,10 @@
     var body: some View {
         ScrollView(showsIndicators: false) {
             VStack(alignment: .leading) {
-                CurrencySelector(currencyPair: currencyPair)
+                HStack {
+                    CurrencySelector(currencyPair: currencyPair)
+                    FavoriteButton(currencyPair: currencyPair)
+                }
             }
             .padding()
         }
@@ -61,8 +64,8 @@
 }
 
 
-//struct ConversionView_Previews: PreviewProvider {
-//    static var previews: some View {
-//        ConversionView()
-//    }
-//}
+struct ConversionView_Previews: PreviewProvider {
+    static var previews: some View {
+        ConversionView(showNavigationView: true, currencyPair: CurrencyPairModel(baseSymbol: "USD", quoteSymbol: "EUR"))
+    }
+}
--- a/Simoleon/Helpers/Persistence.swift	Sat Aug 28 19:17:55 2021 +0100
+++ b/Simoleon/Helpers/Persistence.swift	Sat Aug 28 19:18:50 2021 +0100
@@ -15,8 +15,8 @@
         let viewContext = result.container.viewContext
         
         for _ in 0..<10 {
-            let favorite = Favorite(context: viewContext)
-            favorite.currencyPair = "GBP/USD"
+//            let favorite = Favorite(context: viewContext)
+//            favorite.currencyPair = "GBP/USD"
         }
         do {
             try viewContext.save()
--- a/Simoleon/UI/CurrencySelector.swift	Sat Aug 28 19:17:55 2021 +0100
+++ b/Simoleon/UI/CurrencySelector.swift	Sat Aug 28 19:18:50 2021 +0100
@@ -10,7 +10,7 @@
 struct CurrencySelector: View {
     @State var currencyPair: CurrencyPairModel
     @State private var showingList = false
-    @State private var modalSelection: ModalType? = nil
+    @State private var modalSelection: ModalType = .allCurrencies
     let currencyPairsSupported: [String] = try! read(json: "CurrencyPairsSupported.json")
     
     private enum ModalType {
@@ -20,15 +20,15 @@
     var body: some View {
         HStack {
             Button(action: {
+                modalSelection = .allCurrencies
                 showingList = true
-                modalSelection = .allCurrencies
             }) {
                 CurrencyButton(selectedCurrency: currencyPair.baseSymbol)
             }
             
             Button(action: {
+                modalSelection = .compatibleCurrencies
                 showingList = true
-                modalSelection = .compatibleCurrencies
             }) {
                 CurrencyButton(selectedCurrency: currencyPair.quoteSymbol)
             }