commit 4686a2250daac353084fbbf043c13b7a00389810
parent cc82ae347fe26c22669c00c28394ddd71c136278
Author: Marc Stibane <marc@taler.net>
Date: Sat, 10 Oct 2026 19:03:26 +0200
AI: default expiration for P2P - wallet-core 7 days
Diffstat:
3 files changed, 25 insertions(+), 13 deletions(-)
diff --git a/TalerWallet1/Controllers/PublicConstants.swift b/TalerWallet1/Controllers/PublicConstants.swift
@@ -48,6 +48,7 @@ public let BANNERDURATION: Double = 0.5
public let ONEDAY: UInt = 1 // 1..3
public let SEVENDAYS: UInt = 7 // 3..9
public let THIRTYDAYS: UInt = 30 // 10..30
+public let DEFAULTEXPIRATION = 7*24 // for P2P Send - that's what wallet-core uses
public let EMPTYSTRING = "" // avoid automatic translation of empty "" textLiterals in Text()
public let SPACE = " "
diff --git a/TalerWallet1/Views/Actions/Peer2peer/P2PSubjectV.swift b/TalerWallet1/Views/Actions/Peer2peer/P2PSubjectV.swift
@@ -81,13 +81,19 @@ struct P2PSubjectV: View {
@MainActor
private func checkPeerPushDebit() async {
- if outgoing && feeLabel == nil {
- if let ppCheck = try? await model.checkPeerPushDebit(amountToTransfer, scope: scope) {
- if let feeAmount = p2pFee(ppCheck: ppCheck) {
- let feeStr = feeAmount.formatted(scope, isNegative: false)
- myFeeLabel = (String(localized: "+ \(feeStr.0) fee"),
- String(localized: "+ \(feeStr.1) fee"))
- } else { myFeeLabel = (EMPTYSTRING, EMPTYSTRING) }
+ // Needed even when the caller already computed the fee (feeLabel != nil): SelectDays
+ // tells the user defaultExpiration, and that is what wallet-core applies when P2PReadyV
+ // sends purse_expiration nil. The caller has already shown errors of this check.
+ if outgoing {
+ if let ppCheck = try? await model.checkPeerPushDebit(amountToTransfer, scope: scope,
+ viewHandles: feeLabel != nil) {
+ if feeLabel == nil {
+ if let feeAmount = p2pFee(ppCheck: ppCheck) {
+ let feeStr = feeAmount.formatted(scope, isNegative: false)
+ myFeeLabel = (String(localized: "+ \(feeStr.0) fee"),
+ String(localized: "+ \(feeStr.1) fee"))
+ } else { myFeeLabel = (EMPTYSTRING, EMPTYSTRING) }
+ }
defaultExpiration = ppCheck.defaultExpiration
maxExpirationDate = ppCheck.maxExpirationDate
} else {
@@ -96,13 +102,18 @@ struct P2PSubjectV: View {
}
}
- var maxExpirationHours: UInt64 {
+ var maxExpirationHours: UInt {
if let duration = try? maxExpirationDate?.duration() {
- return duration.toHours()
+ return UInt(duration.toHours())
}
return 0
}
-
+ var defaultExpirationHours: UInt {
+ if let defaultExpiration {
+ return UInt(defaultExpiration.toHours())
+ }
+ return UInt(DEFAULTEXPIRATION)
+ }
var body: some View {
#if PRINT_CHANGES
let _ = Self._printChanges()
@@ -154,7 +165,7 @@ struct P2PSubjectV: View {
// TODO: compute max Expiration day from peerPushCheck to disable 30 (and even 7)
SelectDays(selected: $expireDays, maxExpirationHours: maxExpirationHours,
- defaultExpirationHours: defaultExpiration?.toHours() ?? 28*24, outgoing: outgoing)
+ defaultExpirationHours: defaultExpirationHours, outgoing: outgoing)
.padding(.bottom)
let disabled = (expireDays == 0) // || (numChars < 1) // TODO: check amountAvailable
diff --git a/TalerWallet1/Views/HelperViews/SelectDays.swift b/TalerWallet1/Views/HelperViews/SelectDays.swift
@@ -19,8 +19,8 @@ struct SelectDays: View {
#endif
@Binding var selected: UInt
- let maxExpirationHours: UInt64
- let defaultExpirationHours: UInt64
+ let maxExpirationHours: UInt
+ let defaultExpirationHours: UInt
let outgoing: Bool
func oneDayAction() -> Void {