commit ec81f4be1f9ba9ffc9c0a9b808459d3f8c6ac01a
parent d86282eaf0f8155832f9c47b6147256fa61fdadf
Author: Marc Stibane <marc@taler.net>
Date: Sat, 14 Sep 2024 15:26:00 +0200
CheckPeerPushDebit gets scope
Diffstat:
3 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/TalerWallet1/Model/Model+P2P.swift b/TalerWallet1/Model/Model+P2P.swift
@@ -52,19 +52,21 @@ struct CheckPeerPushDebitResponse: Codable {
fileprivate struct CheckPeerPushDebit: WalletBackendFormattedRequest {
typealias Response = CheckPeerPushDebitResponse
func operation() -> String { "checkPeerPushDebit" }
- func args() -> Args { Args(amount: amount, clientCancellationId: "cancel") }
+ func args() -> Args { Args(amount: amount, restrictScope: scope, clientCancellationId: "cancel") }
var amount: Amount
+ var scope: ScopeInfo
struct Args: Encodable {
var amount: Amount
+ var restrictScope: ScopeInfo
var clientCancellationId: String?
}
}
extension WalletModel {
@MainActor // M for MainActor
- func checkPeerPushDebitM(_ amount: Amount, viewHandles: Bool = false)
+ func checkPeerPushDebitM(_ amount: Amount, scope: ScopeInfo, viewHandles: Bool = false)
async throws -> CheckPeerPushDebitResponse {
- let request = CheckPeerPushDebit(amount: amount)
+ let request = CheckPeerPushDebit(amount: amount, scope: scope)
let response = try await sendRequest(request, ASYNCDELAY, viewHandles: viewHandles)
return response
}
diff --git a/TalerWallet1/Views/Peer2peer/P2PSubjectV.swift b/TalerWallet1/Views/Peer2peer/P2PSubjectV.swift
@@ -21,6 +21,7 @@ func p2pFee(ppCheck: CheckPeerPushDebitResponse) -> Amount? {
struct P2PSubjectV: View {
private let symLog = SymLogV(0)
let stack: CallStack
+ let scope: ScopeInfo
@Binding var currencyInfo: CurrencyInfo
let feeLabel: String?
let feeIsNotZero: Bool? // nil = no fees at all, false = no fee for this tx
@@ -138,7 +139,7 @@ struct P2PSubjectV: View {
}
.task(id: amountToTransfer.value) {
if outgoing && feeLabel == nil {
- if let ppCheck = try? await model.checkPeerPushDebitM(amountToTransfer) {
+ if let ppCheck = try? await model.checkPeerPushDebitM(amountToTransfer, scope: scope) {
if let feeAmount = p2pFee(ppCheck: ppCheck) {
let feeStr = feeAmount.formatted(currencyInfo, isNegative: false)
myFeeLabel = String(localized: "+ \(feeStr) fee")
diff --git a/TalerWallet1/Views/Peer2peer/SendAmount.swift b/TalerWallet1/Views/Peer2peer/SendAmount.swift
@@ -75,7 +75,7 @@ struct SendAmount: View {
return ComputeFeeResult.insufficient()
}
do {
- let ppCheck = try await model.checkPeerPushDebitM(amount, viewHandles: true)
+ let ppCheck = try await model.checkPeerPushDebitM(amount, scope: scopeInfo, viewHandles: true)
let raw = ppCheck.amountRaw
let effective = ppCheck.amountEffective
if let fee = fee(raw: raw, effective: effective) {
@@ -117,6 +117,7 @@ struct SendAmount: View {
let inputDestination = LazyView {
P2PSubjectV(stack: stack.push(),
+ scope: scopeInfo,
currencyInfo: $currencyInfo,
feeLabel: feeLabel(feeStr),
feeIsNotZero: feeIsNotZero(),
@@ -127,6 +128,7 @@ struct SendAmount: View {
}
let shortcutDestination = LazyView {
P2PSubjectV(stack: stack.push(),
+ scope: scopeInfo,
currencyInfo: $currencyInfo,
feeLabel: nil,
feeIsNotZero: feeIsNotZero(),