diff Simoleon/Helpers/CurrencyRow.swift @ 13:cdc5f728b105

Minor UI updates
author Dennis Concepción Martín <dennisconcepcionmartin@gmail.com>
date Tue, 13 Jul 2021 19:56:33 +0100
parents a62e5e4a4f02
children 03ce7421c6f4
line wrap: on
line diff
--- 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 {