gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-taler-ios] 21/30: fix shortcuts


From: gnunet
Subject: [taler-taler-ios] 21/30: fix shortcuts
Date: Sun, 19 Nov 2023 23:53:45 +0100

This is an automated email from the git hooks/post-receive script.

marc-stibane pushed a commit to branch master
in repository taler-ios.

commit dedf6a3e6ec2d6e087c69d3aff9b54305d624af4
Author: Marc Stibane <marc@taler.net>
AuthorDate: Sun Nov 19 13:40:21 2023 +0100

    fix shortcuts
---
 TalerWallet1/Views/Exchange/ManualWithdraw.swift   |  1 +
 .../Views/HelperViews/CurrencyInputView.swift      | 28 ++++++++++++++++++++--
 TalerWallet1/Views/Peer2peer/RequestPayment.swift  |  1 +
 TalerWallet1/Views/Peer2peer/SendAmount.swift      |  3 ++-
 4 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/TalerWallet1/Views/Exchange/ManualWithdraw.swift 
b/TalerWallet1/Views/Exchange/ManualWithdraw.swift
index 36f0aaf..7071931 100644
--- a/TalerWallet1/Views/Exchange/ManualWithdraw.swift
+++ b/TalerWallet1/Views/Exchange/ManualWithdraw.swift
@@ -33,6 +33,7 @@ struct ManualWithdraw: View {
         ScrollView {
             VStack {
                 CurrencyInputView(amount: $amountToTransfer,
+                               available: nil,
                                    title: iconOnly ? String(localized: "How 
much:")
                                                    : String(localized: "Amount 
to withdraw:"))
                 let someCoins = SomeCoins(details: withdrawalAmountDetails)
diff --git a/TalerWallet1/Views/HelperViews/CurrencyInputView.swift 
b/TalerWallet1/Views/HelperViews/CurrencyInputView.swift
index 6155802..8c3f7c2 100644
--- a/TalerWallet1/Views/HelperViews/CurrencyInputView.swift
+++ b/TalerWallet1/Views/HelperViews/CurrencyInputView.swift
@@ -12,6 +12,7 @@ struct ShortcutButton: View {
     let currency: String
     let currencyInfo: CurrencyInfo
     let currencyField: CurrencyField
+    let available: Amount?
     let action: (Int, CurrencyField) -> Void
 
     func makeButton(with newShortcut: Int) -> ShortcutButton {
@@ -19,23 +20,40 @@ struct ShortcutButton: View {
                        currency: currency,
                    currencyInfo: currencyInfo,
                   currencyField: currencyField,
+                      available: available,
                          action: action)
     }
 
+    func isDisabled(shortie: Amount) -> Bool {
+        if let available {
+            do {
+                return try available < shortie
+            } catch {
+                return true
+            }
+        }
+        return false
+    }
+
     var body: some View {
         let shortie = Amount(currency: currency, cent: UInt64(shortcut))       
 // TODO: adapt for ¥
         let title = shortie.string(currencyInfo)
         let shortcutLabel = String(localized: "Shortcut", comment: "VoiceOver: 
$50,$25,$10,$5 shortcut buttons")
         Button(action: { action(shortcut, currencyField)} ) {
             Text(title)
+                .lineLimit(1)
                 .accessibilityFont(.callout)
-        }.buttonStyle(.bordered)
+        }
+//            .frame(maxWidth: .infinity)
+            .disabled(isDisabled(shortie: shortie))
+            .buttonStyle(.bordered)
             .accessibilityLabel("\(shortcutLabel) \(title)")
     }
 }
 // MARK: -
 struct CurrencyInputView: View {
     @Binding var amount: Amount         // the `value´
+    let available: Amount?
     let title: String
 
     @EnvironmentObject private var controller: Controller
@@ -56,7 +74,7 @@ struct CurrencyInputView: View {
         let currency = amount.currencyStr
         let currencyInfo = controller.info(for: currency, 
controller.currencyTicker)
         let currencyField = CurrencyField(amount: $amount, currencyInfo: 
currencyInfo)
-        VStack (alignment: .center) {
+        VStack (alignment: .center) {   // center shortcut buttons
             HStack {
                 Text(title)
                     .accessibilityFont(.title3)
@@ -82,6 +100,7 @@ struct CurrencyInputView: View {
                                                     currency: currency,
                                                 currencyInfo: currencyInfo,
                                                currencyField: currencyField,
+                                                   available: available,
                                                       action: action)
                 ViewThatFits(in: .horizontal) {
                     HStack {
@@ -94,17 +113,21 @@ struct CurrencyInputView: View {
                         let count = shortcuts.count
                         let half = count / 2
                         HStack {
+                            Spacer()
                             ForEach(0..<half, id: \.self) { index in
                                 let thisShortcut = shortcuts[index]
                                 shortcutButton.makeButton(with: thisShortcut)
                                     .accessibilityAddTraits(thisShortcut == 
useShortcut ? .isSelected : [])
+                                Spacer()
                             }
                         }
                         HStack {
+                            Spacer()
                             ForEach(half..<count, id: \.self) { index in
                                 let thisShortcut = shortcuts[index]
                                 shortcutButton.makeButton(with: thisShortcut)
                                     .accessibilityAddTraits(thisShortcut == 
useShortcut ? .isSelected : [])
+                                Spacer()
                             }
                         }
                     }
@@ -144,6 +167,7 @@ fileprivate struct Previews: PreviewProvider {
         var body: some View {
 //            Preview_Content()
             CurrencyInputView(amount: $amountToTransfer,
+                           available: nil,
                                title: "Amount to withdraw:")
                 .environmentObject(controller)
         }
diff --git a/TalerWallet1/Views/Peer2peer/RequestPayment.swift 
b/TalerWallet1/Views/Peer2peer/RequestPayment.swift
index 5192731..deed5dc 100644
--- a/TalerWallet1/Views/Peer2peer/RequestPayment.swift
+++ b/TalerWallet1/Views/Peer2peer/RequestPayment.swift
@@ -30,6 +30,7 @@ struct RequestPayment: View {
 
         ScrollView { VStack {
             CurrencyInputView(amount: $amountToTransfer,
+                           available: nil,
                                title: iconOnly ? String(localized: "How much:")
                                                : String(localized: "Amount to 
request:"))
 
diff --git a/TalerWallet1/Views/Peer2peer/SendAmount.swift 
b/TalerWallet1/Views/Peer2peer/SendAmount.swift
index 3088ff3..d833f64 100644
--- a/TalerWallet1/Views/Peer2peer/SendAmount.swift
+++ b/TalerWallet1/Views/Peer2peer/SendAmount.swift
@@ -45,7 +45,7 @@ struct SendAmount: View {
         let currency = amountAvailable.currencyStr
         let _ = symLog.log("currency: \(currency)")
         let currencyInfo = controller.info(for: currency, 
controller.currencyTicker)
-        let navTitle = String(localized: "Send \(currency)", comment: "Send 
currency, Dialog Title")
+        let navTitle = String(localized: "Send \(currency)", comment: "Dialog 
Title")
         let available = amountAvailable.string(currencyInfo)
         let _ = symLog.log("available: \(available)")
         let current = amountToTransfer.string(currencyInfo)
@@ -58,6 +58,7 @@ struct SendAmount: View {
                 .accessibilityFont(.title3)
                 .padding(.bottom, 2)
             CurrencyInputView(amount: $amountToTransfer,
+                           available: amountAvailable,
                                title: iconOnly ? String(localized: "How much:")
                                                : String(localized: "Amount to 
send:"))
             let disabled = insufficient || amountToTransfer.isZero

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]