commit 728792cb1c65bdf910b429872252e05c5ff46ed6
parent e7dfcd59b5ad3453f0e5c772224f6eff1a91e899
Author: Marc Stibane <marc@taler.net>
Date: Wed, 25 Sep 2024 13:54:13 +0200
GetMaxPeerPushAmount
Diffstat:
6 files changed, 34 insertions(+), 22 deletions(-)
diff --git a/TalerWallet1/Views/Balances/SendRequestV.swift b/TalerWallet1/Views/Balances/SendRequestV.swift
@@ -61,7 +61,7 @@ struct SendRequestV: View {
let sendDest = LazyView {
SendAmount(stack: stack.push("\(Self.className())()"),
currencyInfo: $currencyInfo,
- amountAvailable: amountAvailable,
+ available: amountAvailable,
amountToTransfer: $amountToTransfer, // with correct currency
summary: $summary,
scopeInfo: scope,
diff --git a/TalerWallet1/Views/HelperViews/AmountInputV.swift b/TalerWallet1/Views/HelperViews/AmountInputV.swift
@@ -34,11 +34,10 @@ struct AmountInputV: View {
let stack: CallStack
@Binding var currencyInfo: CurrencyInfo
- let amountAvailable: Amount? // TODO: GetMaxPeerPushAmount
+ @Binding var amountAvailable: Amount
let amountLabel: String
@Binding var amountToTransfer: Amount
let wireFee: Amount?
-// let summaryIsEditable: Bool // if true we call SubjectInputV next
@Binding var summary: String
// @Binding var insufficient: Bool
// @Binding var feeAmount: Amount?
@@ -62,18 +61,18 @@ struct AmountInputV: View {
func checkAvailable(_ coinData: CoinData) -> Flags {
let isZero = amountToTransfer.isZero
- if let amountAvailable {
+ if !amountAvailable.isZero {
do {
let insufficient: Bool
- if let feeAmount {
- if feeIsNegative {
- insufficient = try amountToTransfer > amountAvailable
- } else {
- insufficient = try (amountToTransfer + feeAmount) > amountAvailable
- }
- } else {
+// if let feeAmount {
+// if feeIsNegative {
+// insufficient = try amountToTransfer > amountAvailable
+// } else {
+// insufficient = try (amountToTransfer + feeAmount) > amountAvailable
+// }
+// } else {
insufficient = try amountToTransfer > amountAvailable
- }
+// }
let disabled = insufficient || isZero || coinData.invalid || coinData.tooMany
return Flags(insufficient: insufficient, disabled: disabled)
} catch {
@@ -86,7 +85,8 @@ struct AmountInputV: View {
var body: some View {
let currency = amountToTransfer.currencyStr
// let insufficientLabel = String(localized: "You don't have enough \(currency).")
- let available = amountAvailable?.formatted(currencyInfo, isNegative: false) ?? nil
+ let available = amountAvailable.isZero ? nil
+ : amountAvailable.formatted(currencyInfo, isNegative: false)
VStack(alignment: .trailing) {
if summary.count > 0 {
Text(summary)
diff --git a/TalerWallet1/Views/Peer2peer/RequestPayment.swift b/TalerWallet1/Views/Peer2peer/RequestPayment.swift
@@ -28,6 +28,7 @@ struct RequestPayment: View {
@State private var buttonSelected = false
@State private var shortcutSelected = false
@State private var amountShortcut = Amount.zero(currency: EMPTYSTRING) // Update currency when used
+ @State private var amountZero = Amount.zero(currency: EMPTYSTRING) // needed for isZero
@State private var exchange: Exchange? = nil // wg. noFees
private func shortcutAction(_ shortcut: Amount) {
@@ -136,7 +137,7 @@ struct RequestPayment: View {
: String(localized: "Amount to request:")
AmountInputV(stack: stack.push(),
currencyInfo: $currencyInfo,
- amountAvailable: nil,
+ amountAvailable: $amountZero,
amountLabel: amountLabel,
amountToTransfer: $amountToTransfer,
wireFee: nil,
diff --git a/TalerWallet1/Views/Peer2peer/SendAmount.swift b/TalerWallet1/Views/Peer2peer/SendAmount.swift
@@ -15,7 +15,7 @@ struct SendAmount: View {
let stack: CallStack
@Binding var currencyInfo: CurrencyInfo
- let amountAvailable: Amount // TODO: GetMaxPeerPushAmount
+ let available: Amount
@Binding var amountToTransfer: Amount
@Binding var summary: String
let scopeInfo: ScopeInfo
@@ -35,6 +35,7 @@ struct SendAmount: View {
@State private var buttonSelected = false
@State private var shortcutSelected = false
@State private var amountShortcut = Amount.zero(currency: EMPTYSTRING) // Update currency when used
+ @State private var amountAvailable = Amount.zero(currency: EMPTYSTRING) // GetMaxPeerPushAmount
@State private var exchange: Exchange? = nil // wg. noFees
private func shortcutAction(_ shortcut: Amount) {
@@ -109,11 +110,11 @@ struct SendAmount: View {
let navTitle = String(localized: "NavTitle_Send_Currency",
defaultValue: "Send \(currencySymbol)",
comment: "NavTitle: Send 'currencySymbol'")
- let available = amountAvailable.formatted(currencyInfo, isNegative: false)
+ let availableStr = amountAvailable.formatted(currencyInfo, isNegative: false)
// let _ = print("available: \(available)")
let _ = symLog.log("currency: \(currencyInfo.specs.name), available: \(available)")
let amountVoiceOver = amountToTransfer.formatted(currencyInfo, isNegative: false)
- let insufficientLabel2 = String(localized: "but you only have \(available) to send.")
+ let insufficientLabel2 = String(localized: "but you only have \(availableStr) to send.")
let inputDestination = LazyView {
P2PSubjectV(stack: stack.push(),
@@ -143,7 +144,7 @@ struct SendAmount: View {
: String(localized: "Amount to send:")
AmountInputV(stack: stack.push(),
currencyInfo: $currencyInfo,
- amountAvailable: amountAvailable,
+ amountAvailable: $amountAvailable,
amountLabel: amountLabel,
amountToTransfer: $amountToTransfer,
wireFee: nil,
@@ -163,6 +164,15 @@ struct SendAmount: View {
// .scrollBounceBehavior(.basedOnSize) needs iOS 16.4
.background(WalletColors().backgroundColor.edgesIgnoringSafeArea(.all))
.navigationTitle(navTitle)
+ .task {
+ do {
+ let amount = try await model.getMaxPeerPushDebitAmountM(amountToTransfer.currencyStr,
+ scope: scopeInfo, viewHandles: true)
+ amountAvailable = amount
+ } catch {
+ amountAvailable = available
+ }
+ }
.onAppear {
DebugViewC.shared.setViewID(VIEW_P2P_SEND, stack: stack.push())
// if we set >> controller.frontendState = -1 << here, then becomeFirstResponder won't work!
@@ -232,7 +242,7 @@ fileprivate struct Preview_Content: View {
ageRestrictionOptions: [])
SendAmount(stack: CallStack("Preview"),
currencyInfo: $currencyInfoL,
- amountAvailable: amount,
+ available: amount,
amountToTransfer: $amountToPreview,
summary: $summary,
scopeInfo: currencyInfo.scope,
diff --git a/TalerWallet1/Views/Sheets/Payment/PayTemplateV.swift b/TalerWallet1/Views/Sheets/Payment/PayTemplateV.swift
@@ -33,6 +33,7 @@ struct PayTemplateV: View {
@State private var amountIsEditable = false
@State private var amountToTransfer = Amount.zero(currency: EMPTYSTRING) // Update currency when used
@State private var amountShortcut = Amount.zero(currency: EMPTYSTRING) // Update currency when used
+ @State private var amountZero = Amount.zero(currency: EMPTYSTRING) // needed for isZero
@State private var shortcutSelected = false
@State private var buttonSelected1 = false
@State private var buttonSelected2 = false
@@ -134,8 +135,7 @@ struct PayTemplateV: View {
if amountIsEditable { // template contract amount is not fixed => let the user input an amount first
let amountInput = AmountInputV(stack: stack.push(),
currencyInfo: $currencyInfo,
-// url: url,
- amountAvailable: nil,
+ amountAvailable: $amountZero,
amountLabel: amountLabel,
amountToTransfer: $amountToTransfer,
wireFee: nil,
diff --git a/TalerWallet1/Views/Sheets/WithdrawBankIntegrated/WithdrawURIView.swift b/TalerWallet1/Views/Sheets/WithdrawBankIntegrated/WithdrawURIView.swift
@@ -29,6 +29,7 @@ struct WithdrawURIView: View {
@State private var amountIsEditable = false
@State private var amountToTransfer = Amount.zero(currency: EMPTYSTRING) // Update currency when used
@State private var amountShortcut = Amount.zero(currency: EMPTYSTRING) // Update currency when used
+ @State private var amountZero = Amount.zero(currency: EMPTYSTRING) // needed for isZero
@State private var buttonSelected = false
@State private var shortcutSelected = false
@State private var amountAvailable: Amount? = nil
@@ -143,7 +144,7 @@ struct WithdrawURIView: View {
: String(localized: "Amount to withdraw:")
AmountInputV(stack: stack.push(),
currencyInfo: $currencyInfo,
- amountAvailable: amountAvailable,
+ amountAvailable: $amountZero,
amountLabel: amountLabel,
amountToTransfer: $amountToTransfer,
wireFee: wireFee,