summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Stibane <marc@taler.net>2023-11-19 13:40:21 +0100
committerMarc Stibane <marc@taler.net>2023-11-19 13:42:44 +0100
commitdedf6a3e6ec2d6e087c69d3aff9b54305d624af4 (patch)
tree3a54a4fed46605987d8059049cf4b0cb411e83c6
parenta1a5c84611d67dc4818944c223106cb1c76a0e2e (diff)
downloadtaler-ios-dedf6a3e6ec2d6e087c69d3aff9b54305d624af4.tar.gz
taler-ios-dedf6a3e6ec2d6e087c69d3aff9b54305d624af4.tar.bz2
taler-ios-dedf6a3e6ec2d6e087c69d3aff9b54305d624af4.zip
fix shortcuts
-rw-r--r--TalerWallet1/Views/Exchange/ManualWithdraw.swift1
-rw-r--r--TalerWallet1/Views/HelperViews/CurrencyInputView.swift28
-rw-r--r--TalerWallet1/Views/Peer2peer/RequestPayment.swift1
-rw-r--r--TalerWallet1/Views/Peer2peer/SendAmount.swift3
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