[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-taler-ios] 112/204: P2P
From: |
gnunet |
Subject: |
[taler-taler-ios] 112/204: P2P |
Date: |
Thu, 05 Dec 2024 23:51:20 +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 d8d3a330160552c5e30b8612df53cfd7bd533480
Author: Marc Stibane <marc@taler.net>
AuthorDate: Fri Nov 8 21:02:21 2024 +0100
P2P
---
TalerWallet1/Model/Model+P2P.swift | 80 +++++++++++-----------
.../Views/Actions/Peer2peer/P2PReadyV.swift | 60 ++++++++--------
.../Views/Actions/Peer2peer/P2PSubjectV.swift | 29 ++++----
.../Views/Actions/Peer2peer/RequestPayment.swift | 50 +++++++-------
.../Views/Actions/Peer2peer/SendAmountV.swift | 34 +++++----
.../Views/Actions/Peer2peer/SendAmountView.swift | 28 ++++----
.../Views/Sheets/P2P_Sheets/P2pAcceptDone.swift | 5 +-
.../Views/Sheets/P2P_Sheets/P2pPayURIView.swift | 13 ++--
.../Sheets/P2P_Sheets/P2pReceiveURIView.swift | 16 +++--
9 files changed, 168 insertions(+), 147 deletions(-)
diff --git a/TalerWallet1/Model/Model+P2P.swift
b/TalerWallet1/Model/Model+P2P.swift
index 92aa023..1234747 100644
--- a/TalerWallet1/Model/Model+P2P.swift
+++ b/TalerWallet1/Model/Model+P2P.swift
@@ -26,8 +26,8 @@ fileprivate struct AmountResponse: Codable {
fileprivate struct GetMaxPeerPushDebitAmount: WalletBackendFormattedRequest {
typealias Response = AmountResponse
func operation() -> String { "getMaxPeerPushDebitAmount" }
- func args() -> Args { Args(currency: scope.currency, restrictScope: scope)
}
-
+ func args() -> Args { Args(currency: scope.currency,
+ restrictScope: scope) }
var scope: ScopeInfo
struct Args: Encodable {
var currency: String
@@ -35,14 +35,14 @@ fileprivate struct GetMaxPeerPushDebitAmount:
WalletBackendFormattedRequest {
}
}
extension WalletModel {
- @MainActor // M for MainActor
- func getMaxPeerPushDebitAmountM(_ scope: ScopeInfo, viewHandles: Bool =
false)
+ nonisolated func getMaxPeerPushDebitAmount(_ scope: ScopeInfo,
+ viewHandles: Bool = false)
async throws -> Amount {
let request = GetMaxPeerPushDebitAmount(scope: scope)
let response = try await sendRequest(request, ASYNCDELAY, viewHandles:
viewHandles)
return response.rawAmount
}
-} // getMaxPeerPushAmountM
+} // getMaxPeerPushAmount
// MARK: - check PeerPushDebit
struct CheckPeerPushDebitResponse: Codable {
let exchangeBaseUrl: String? // API "2:0:1"
@@ -53,8 +53,9 @@ struct CheckPeerPushDebitResponse: Codable {
fileprivate struct CheckPeerPushDebit: WalletBackendFormattedRequest {
typealias Response = CheckPeerPushDebitResponse
func operation() -> String { "checkPeerPushDebit" }
- func args() -> Args { Args(amount: amount, restrictScope: scope,
clientCancellationId: "cancel") }
-
+ func args() -> Args { Args(amount: amount,
+ restrictScope: scope,
+ clientCancellationId: "cancel") }
var amount: Amount
var scope: ScopeInfo
struct Args: Encodable {
@@ -64,16 +65,15 @@ fileprivate struct CheckPeerPushDebit:
WalletBackendFormattedRequest {
}
}
extension WalletModel {
- @MainActor // M for MainActor
- func checkPeerPushDebitM(_ amount: Amount,
- scope: ScopeInfo,
- viewHandles: Bool = false)
+ nonisolated func checkPeerPushDebit(_ amount: Amount,
+ scope: ScopeInfo,
+ viewHandles: Bool = false)
async throws -> CheckPeerPushDebitResponse {
let request = CheckPeerPushDebit(amount: amount, scope: scope)
let response = try await sendRequest(request, ASYNCDELAY, viewHandles:
viewHandles)
return response
}
-} // checkPeerPushDebitM
+} // checkPeerPushDebit
// MARK: - Initiate PeerPushDebit
/// Initiate an outgoing peer push payment, send coins
struct InitiatePeerPushDebitResponse: Codable {
@@ -90,7 +90,6 @@ fileprivate struct InitiatePeerPushDebit:
WalletBackendFormattedRequest {
func args() -> Args { Args(//exchangeBaseUrl: baseURL,
restrictScope: scope,
partialContractTerms: terms) }
-
var scope: ScopeInfo
// var baseURL: String?
var terms: PeerContractTerms
@@ -101,16 +100,15 @@ fileprivate struct InitiatePeerPushDebit:
WalletBackendFormattedRequest {
}
}
extension WalletModel {
- @MainActor // M for MainActor
- func initiatePeerPushDebitM(/*_ baseURL: String?,*/ scope: ScopeInfo,
terms: PeerContractTerms, viewHandles: Bool = false)
- async throws -> InitiatePeerPushDebitResponse {
- let request = InitiatePeerPushDebit(//exchangeBaseUrl: baseURL,
- scope: scope,
- terms: terms)
+ nonisolated func initiatePeerPushDebit(scope: ScopeInfo,
+ terms: PeerContractTerms,
+ viewHandles: Bool = false)
+ async throws -> InitiatePeerPushDebitResponse {
+ let request = InitiatePeerPushDebit(scope: scope, terms: terms)
let response = try await sendRequest(request, ASYNCDELAY, viewHandles:
viewHandles)
return response
}
-} // initiatePeerPushDebitM
+} // initiatePeerPushDebit
// MARK: - PeerPullCredit
/// Check fees before sending a request(invoice) to another wallet
struct CheckPeerPullCreditResponse: Codable {
@@ -137,16 +135,15 @@ fileprivate struct CheckPeerPullCredit:
WalletBackendFormattedRequest {
}
}
extension WalletModel {
- @MainActor // M for MainActor
- func checkPeerPullCreditM(_ amount: Amount,
- scope: ScopeInfo,
- viewHandles: Bool = false)
+ nonisolated func checkPeerPullCredit(_ amount: Amount,
+ scope: ScopeInfo,
+ viewHandles: Bool = false)
async throws -> CheckPeerPullCreditResponse {
let request = CheckPeerPullCredit(amount: amount, scope: scope)
let response = try await sendRequest(request, ASYNCDELAY, viewHandles:
viewHandles)
return response
}
-} // checkPeerPullCreditM
+} // checkPeerPullCredit
// - - - - - -
/// Initiate an outgoing peer pull payment, send a request(invoice)
struct InitiatePeerPullCreditResponse: Codable {
@@ -157,7 +154,7 @@ fileprivate struct InitiatePeerPullCredit:
WalletBackendFormattedRequest {
typealias Response = InitiatePeerPullCreditResponse
func operation() -> String { "initiatePeerPullCredit" }
func args() -> Args { Args(exchangeBaseUrl: exchangeBaseUrl,
- partialContractTerms: partialContractTerms) }
+ partialContractTerms: partialContractTerms) }
var exchangeBaseUrl: String?
var partialContractTerms: PeerContractTerms
@@ -167,15 +164,16 @@ fileprivate struct InitiatePeerPullCredit:
WalletBackendFormattedRequest {
}
}
extension WalletModel {
- @MainActor
- func initiatePeerPullCreditM(_ baseURL: String?, terms: PeerContractTerms,
viewHandles: Bool = false) // M for MainActor
+ nonisolated func initiatePeerPullCredit(_ baseURL: String?,
+ terms: PeerContractTerms,
+ viewHandles: Bool = false)
async throws -> InitiatePeerPullCreditResponse {
let request = InitiatePeerPullCredit(exchangeBaseUrl: baseURL,
partialContractTerms: terms)
let response = try await sendRequest(request, ASYNCDELAY, viewHandles:
viewHandles)
return response
}
-} // initiatePeerPullCreditM
+} // initiatePeerPullCredit
// MARK: - PeerPushCredit
/// Prepare an incoming peer push payment, receive coins
struct PreparePeerPushCreditResponse: Codable {
@@ -198,14 +196,14 @@ fileprivate struct PreparePeerPushCredit:
WalletBackendFormattedRequest {
}
}
extension WalletModel {
- @MainActor
- func preparePeerPushCreditM(_ talerUri: String, viewHandles: Bool = false)
// M for MainActor
+ nonisolated func preparePeerPushCredit(_ talerUri: String,
+ viewHandles: Bool = false)
async throws -> PreparePeerPushCreditResponse {
let request = PreparePeerPushCredit(talerUri: talerUri)
let response = try await sendRequest(request, ASYNCDELAY, viewHandles:
viewHandles)
return response
}
-} // preparePeerPushCreditM
+} // preparePeerPushCredit
// - - - - - -
/// Accept an incoming peer push payment
fileprivate struct AcceptPeerPushCredit: WalletBackendFormattedRequest {
@@ -219,14 +217,14 @@ fileprivate struct AcceptPeerPushCredit:
WalletBackendFormattedRequest {
}
}
extension WalletModel {
- @MainActor
- func acceptPeerPushCreditM(_ transactionId: String, viewHandles: Bool =
false) // M for MainActor
+ nonisolated func acceptPeerPushCredit(_ transactionId: String,
+ viewHandles: Bool = false)
async throws -> Decodable {
let request = AcceptPeerPushCredit(transactionId: transactionId)
let response = try await sendRequest(request, ASYNCDELAY, viewHandles:
viewHandles)
return response
}
-} // acceptPeerPushCreditM
+} // acceptPeerPushCredit
// MARK: - PeerPullDebit
/// Prepare an incoming peer push request(invoice), pay coins
struct PreparePeerPullDebitResponse: Codable {
@@ -249,14 +247,14 @@ fileprivate struct PreparePeerPullDebit:
WalletBackendFormattedRequest {
}
}
extension WalletModel {
- @MainActor
- func preparePeerPullDebitM(_ talerUri: String, viewHandles: Bool = false)
// M for MainActor
+ nonisolated func preparePeerPullDebit(_ talerUri: String,
+ viewHandles: Bool = false)
async throws -> PreparePeerPullDebitResponse {
let request = PreparePeerPullDebit(talerUri: talerUri)
let response = try await sendRequest(request, ASYNCDELAY, viewHandles:
viewHandles)
return response
}
-} // preparePeerPullDebitM
+} // preparePeerPullDebit
// - - - - - -
/// Confirm incoming peer push request(invoice) and pay
fileprivate struct ConfirmPeerPullDebit: WalletBackendFormattedRequest {
@@ -270,11 +268,11 @@ fileprivate struct ConfirmPeerPullDebit:
WalletBackendFormattedRequest {
}
}
extension WalletModel {
- @MainActor
- func confirmPeerPullDebitM(_ transactionId: String, viewHandles: Bool =
false) // M for MainActor
+ nonisolated func confirmPeerPullDebit(_ transactionId: String,
+ viewHandles: Bool = false)
async throws -> Decodable {
let request = ConfirmPeerPullDebit(transactionId: transactionId)
let response = try await sendRequest(request, ASYNCDELAY, viewHandles:
viewHandles)
return response
}
-} // confirmPeerPullDebitM
+} // confirmPeerPullDebit
diff --git a/TalerWallet1/Views/Actions/Peer2peer/P2PReadyV.swift
b/TalerWallet1/Views/Actions/Peer2peer/P2PReadyV.swift
index 46c24ba..09e4461 100644
--- a/TalerWallet1/Views/Actions/Peer2peer/P2PReadyV.swift
+++ b/TalerWallet1/Views/Actions/Peer2peer/P2PReadyV.swift
@@ -35,6 +35,37 @@ struct P2PReadyV: View {
return try await model.getTransactionByIdT(transactionId, viewHandles:
viewHandles)
}
+ @MainActor
+ private func initiateP2P() async {
+ symLog.log(".task")
+ guard transactionStarted == false else {
+// TODO: logger.warning("Trying to start P2P a second time")
+ symLog.log("Yikes❗️ Trying to start P2P a second time")
+ return
+ }
+ transactionStarted = true
+ let timestamp = developerMode ? Timestamp.inSomeMinutes(expireDays >
20 ? (24*60) // 24h
+ : expireDays > 5
? 60 // 1h
+
: 3) // 3m
+ : Timestamp.inSomeDays(expireDays)
+ let terms = PeerContractTerms(amount: amountToTransfer,
+ summary: summary,
+ purse_expiration: timestamp)
+ if outgoing {
+ // TODO: let user choose baseURL
+ if let response = try? await model.initiatePeerPushDebit(scope:
scope, terms: terms) {
+ // will switch from WithdrawProgressView to TransactionSummaryV
+ transactionId = response.transactionId
+ }
+ } else {
+ // TODO: let user choose baseURL
+ if let response = try? await model.initiatePeerPullCredit(nil,
terms: terms) {
+ // will switch from WithdrawProgressView to TransactionSummaryV
+ transactionId = response.transactionId
+ }
+ }
+ }
+
var body: some View {
#if PRINT_CHANGES
let _ = Self._printChanges()
@@ -70,6 +101,7 @@ struct P2PReadyV: View {
}
}
.navigationTitle(navTitle)
+ .task { await initiateP2P() }
.onAppear {
DebugViewC.shared.setViewID(VIEW_P2P_READY, stack: stack.push())
// print("❗️ P2PReadyV onAppear")
@@ -77,34 +109,6 @@ struct P2PReadyV: View {
.onDisappear {
// print("❗️ P2PReadyV onDisappear")
}
- .task(id: amountToTransfer.value) {
- symLog.log(".task")
- guard transactionStarted == false else {
-// TODO: logger.warning("Try to start P2P a second time")
- symLog.log("Yikes❗️ Try to start P2P a second time")
- return
- }
- transactionStarted = true
- let timestamp = developerMode ? Timestamp.inSomeMinutes(expireDays
> 20 ? (24*60)
- : expireDays
> 5 ? 60 : 3)
- : Timestamp.inSomeDays(expireDays)
- let terms = PeerContractTerms(amount: amountToTransfer,
- summary: summary,
- purse_expiration: timestamp)
- if outgoing {
- // TODO: let user choose baseURL
- if let response = try? await
model.initiatePeerPushDebitM(scope: scope, terms: terms) {
- // will switch from WithdrawProgressView to
TransactionSummaryV
- transactionId = response.transactionId
- }
- } else {
- // TODO: let user choose baseURL
- if let response = try? await
model.initiatePeerPullCreditM(nil, terms: terms) {
- // will switch from WithdrawProgressView to
TransactionSummaryV
- transactionId = response.transactionId
- }
- }
- } // task
}
}
// MARK: -
diff --git a/TalerWallet1/Views/Actions/Peer2peer/P2PSubjectV.swift
b/TalerWallet1/Views/Actions/Peer2peer/P2PSubjectV.swift
index 25a722c..fd15c05 100644
--- a/TalerWallet1/Views/Actions/Peer2peer/P2PSubjectV.swift
+++ b/TalerWallet1/Views/Actions/Peer2peer/P2PSubjectV.swift
@@ -56,6 +56,21 @@ struct P2PSubjectV: View {
comment: "NavTitle: Request 'amountStr'")
}
+ @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) fee")
+ } else { myFeeLabel = EMPTYSTRING }
+ } else {
+ print("❗️ checkPeerPushDebitM failed")
+
+ }
+ }
+ }
+
var body: some View {
#if PRINT_CHANGES
let _ = Self._printChanges()
@@ -140,6 +155,7 @@ struct P2PSubjectV: View {
// .scrollBounceBehavior(.basedOnSize) needs iOS 16.4
.navigationTitle(subjectTitle(amountToTransfer))
.background(WalletColors().backgroundColor.edgesIgnoringSafeArea(.all))
+ .task(id: amountToTransfer.value) { await checkPeerPushDebit() }
.onAppear {
DebugViewC.shared.setViewID(VIEW_P2P_SUBJECT, stack: stack.push())
// print("❗️ P2PSubjectV onAppear")
@@ -147,19 +163,6 @@ struct P2PSubjectV: View {
.onDisappear {
// print("❗️ P2PSubjectV onDisappear")
}
- .task(id: amountToTransfer.value) {
- if outgoing && feeLabel == nil {
- if let ppCheck = try? await
model.checkPeerPushDebitM(amountToTransfer, scope: scope) {
- if let feeAmount = p2pFee(ppCheck: ppCheck) {
- let feeStr = feeAmount.formatted(scope, isNegative:
false)
- myFeeLabel = String(localized: "+ \(feeStr) fee")
- } else { myFeeLabel = EMPTYSTRING }
- } else {
- print("❗️ checkPeerPushDebitM failed")
-
- }
- }
- }
}
}
// MARK: -
diff --git a/TalerWallet1/Views/Actions/Peer2peer/RequestPayment.swift
b/TalerWallet1/Views/Actions/Peer2peer/RequestPayment.swift
index ede03f7..a788338 100644
--- a/TalerWallet1/Views/Actions/Peer2peer/RequestPayment.swift
+++ b/TalerWallet1/Views/Actions/Peer2peer/RequestPayment.swift
@@ -22,6 +22,7 @@ struct RequestPayment: View {
@State private var balanceIndex = 0
@State private var balance: Balance? = nil // nil only when balances
== []
@State private var currencyInfo: CurrencyInfo = CurrencyInfo.zero(UNKNOWN)
+ @State private var amountToTransfer = Amount.zero(currency: EMPTYSTRING)
// Update currency when used
private func viewDidLoad() async {
if let selectedBalance {
@@ -41,19 +42,30 @@ struct RequestPayment: View {
comment: "NavTitle: Request")
}
+ @MainActor
+ private func newBalance() async {
+ // runs whenever the user changes the exchange via ScopePicker, or on
new currencyInfo
+ symLog.log("❗️ task \(balanceIndex)")
+ if let balance {
+ let scopeInfo = balance.scopeInfo
+ amountToTransfer.setCurrency(scopeInfo.currency)
+ currencyInfo = controller.info(for: scopeInfo,
controller.currencyTicker)
+ }
+ }
+
var body: some View {
#if PRINT_CHANGES
let _ = Self._printChanges()
#endif
let currencySymbol = currencyInfo.symbol
- let navA11y = navTitle(currencyInfo.name)
+ let navA11y = navTitle(currencyInfo.name)
// always include currency for a11y
let navTitle = navTitle(currencySymbol, currencyInfo.hasSymbol)
let count = controller.balances.count
let _ = symLog.log("count = \(count)")
let scrollView = ScrollView {
if count > 0 {
- ScopePicker(value: $balanceIndex,
- onlyNonZero: false) { index in
+ ScopePicker(value: $balanceIndex, onlyNonZero: false)
+ { index in
balanceIndex = index
balance = controller.balances[index]
}
@@ -64,6 +76,7 @@ struct RequestPayment: View {
balance: $balance,
balanceIndex: $balanceIndex,
amountLastUsed: $amountLastUsed,
+ amountToTransfer: $amountToTransfer,
summary: $summary)
} // ScrollView
.navigationTitle(navTitle)
@@ -77,6 +90,7 @@ struct RequestPayment: View {
symLog.log("❗️ \(navTitle) onDisappear")
}
.task { await viewDidLoad() }
+ .task(id: balanceIndex + (1000 * controller.currencyTicker)) {
await newBalance() }
if #available(iOS 16.0, *) {
if #available(iOS 16.4, *) {
@@ -92,11 +106,12 @@ struct RequestPayment: View {
}
// MARK: -
struct RequestPaymentContent: View {
- private let symLog = SymLogV()
+ private let symLog = SymLogV(0)
let stack: CallStack
@Binding var balance: Balance?
@Binding var balanceIndex: Int
@Binding var amountLastUsed: Amount
+ @Binding var amountToTransfer: Amount
@Binding var summary: String
@EnvironmentObject private var controller: Controller
@@ -109,7 +124,6 @@ struct RequestPaymentContent: View {
@State private var feeStr: String = EMPTYSTRING
@State private var buttonSelected = false
@State private var shortcutSelected = 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 exchange: Exchange? = nil
// wg. noFees
@@ -156,7 +170,7 @@ struct RequestPaymentContent: View {
}
do {
let baseURL = exchange?.exchangeBaseUrl
- let ppCheck = try await model.checkPeerPullCreditM(amount, scope:
scopeInfo, viewHandles: true)
+ let ppCheck = try await model.checkPeerPullCredit(amount, scope:
scopeInfo, viewHandles: true)
let raw = ppCheck.amountRaw
let effective = ppCheck.amountEffective
if let fee = fee(raw: raw, effective: effective) {
@@ -236,32 +250,14 @@ struct RequestPaymentContent: View {
feeIsNegative: true,
computeFee: computeFee)
.background(actions)
- }
- } // Group
- .task(id: balanceIndex + (1000 * controller.currencyTicker)) {
- // runs whenever the user changes the exchange via ScopePicker, or
on new currencyInfo
- symLog.log("❗️ task \(balanceIndex)")
+ } } // if, Group
+ .task {
scopeInfo = balance.scopeInfo
- amountToTransfer.setCurrency(scopeInfo.currency)
}
} else { // no balance - Yikes
Text("No balance. There seems to be a problem with the
database...")
}
-// .task(id: amountToTransfer.value) {
-// if exchange == nil {
-// if let url = scopeInfo.url {
-// exchange = try? await model.getExchangeByUrl(url: url)
-// }
-// }
-// if amountToTransfer.isZero {
-// // fee = EMPTYSTRING
-// } else {
-// let baseURL = exchange?.exchangeBaseUrl
-// // peerPullCheck = try? await
model.checkPeerPullCreditM(amountToTransfer, exchangeBaseUrl: nil)
-// peerPullCheck = try? await
model.checkPeerPullCreditM(baseURL, amount: amountToTransfer)
-// }
-// }
- }
+ } // body
}
// MARK: -
#if DEBUG
diff --git a/TalerWallet1/Views/Actions/Peer2peer/SendAmountV.swift
b/TalerWallet1/Views/Actions/Peer2peer/SendAmountV.swift
index d9c5156..15bea7e 100644
--- a/TalerWallet1/Views/Actions/Peer2peer/SendAmountV.swift
+++ b/TalerWallet1/Views/Actions/Peer2peer/SendAmountV.swift
@@ -26,6 +26,7 @@ struct SendAmountV: View {
@State private var amountToTransfer = Amount.zero(currency: EMPTYSTRING)
// Update currency when used
@State private var amountAvailable = Amount.zero(currency: EMPTYSTRING)
// GetMaxPeerPushAmount
+ @MainActor
private func viewDidLoad() async {
if let selectedBalance {
if selectedBalance.available.isZero {
@@ -45,6 +46,23 @@ struct SendAmountV: View {
}
}
+ @MainActor
+ private func newBalance() async {
+ // runs whenever the user changes the exchange via ScopePicker, or on
new currencyInfo
+ symLog.log("❗️ task \(balanceIndex)")
+ if let balance {
+ let scope = balance.scopeInfo
+ amountToTransfer.setCurrency(scope.currency)
+ currencyInfo = controller.info(for: scope,
controller.currencyTicker)
+ do {
+ amountAvailable = try await
model.getMaxPeerPushDebitAmount(scope)
+ } catch {
+ // TODO: Error
+ amountAvailable = balance.available
+ }
+ }
+ }
+
var body: some View {
#if PRINT_CHANGES
let _ = Self._printChanges()
@@ -87,21 +105,7 @@ struct SendAmountV: View {
// symLog.log("❗️ \(navTitle) onDisappear")
// }
.task { await viewDidLoad() }
- .task(id: balanceIndex + (1000 * controller.currencyTicker)) {
- // runs whenever the user changes the exchange via
ScopePicker, or on new currencyInfo
- symLog.log("❗️ task \(balanceIndex)")
- if let balance {
- let scope = balance.scopeInfo
- amountToTransfer.setCurrency(scope.currency)
- currencyInfo = controller.info(for: scope,
controller.currencyTicker)
- do {
- amountAvailable = try await
model.getMaxPeerPushDebitAmountM(scope)
- } catch {
- // TODO: Error
- amountAvailable = balance.available
- }
- }
- }
+ .task(id: balanceIndex + (1000 * controller.currencyTicker)) {
await newBalance() }
if #available(iOS 16.0, *) {
if #available(iOS 16.4, *) {
diff --git a/TalerWallet1/Views/Actions/Peer2peer/SendAmountView.swift
b/TalerWallet1/Views/Actions/Peer2peer/SendAmountView.swift
index aae8563..37a64ae 100644
--- a/TalerWallet1/Views/Actions/Peer2peer/SendAmountView.swift
+++ b/TalerWallet1/Views/Actions/Peer2peer/SendAmountView.swift
@@ -73,6 +73,7 @@ struct SendAmountView: View {
: true // TODO: !(feeAmount?.isZero ??
false)
}
+ @MainActor
private func computeFee(_ amount: Amount) async -> ComputeFeeResult? {
if amount.isZero {
return ComputeFeeResult.zero()
@@ -83,7 +84,7 @@ struct SendAmountView: View {
}
if let scopeInfo {
do {
- let ppCheck = try await model.checkPeerPushDebitM(amount,
scope: scopeInfo, viewHandles: true)
+ let ppCheck = try await model.checkPeerPushDebit(amount,
scope: scopeInfo, viewHandles: true)
let raw = ppCheck.amountRaw
let effective = ppCheck.amountEffective
if let fee = fee(raw: raw, effective: effective) {
@@ -120,6 +121,19 @@ struct SendAmountView: View {
return nil
}
+ @MainActor
+ private func newBalance() async {
+ let scope = balance.scopeInfo
+ symLog.log("❗️ task \(scope.currency)")
+
+ if let available = try? await model.getMaxPeerPushDebitAmount(scope,
viewHandles: true) {
+ amountAvailable = available
+ } else {
+ amountAvailable = Amount.zero(currency: scope.currency)
+ }
+ scopeInfo = scope
+ }
+
var body: some View {
#if PRINT_CHANGES
let _ = Self._printChanges()
@@ -169,6 +183,7 @@ struct SendAmountView: View {
Text(" ")
}
} // Group
+ .task(id: balance) { await newBalance() }
.onAppear {
DebugViewC.shared.setViewID(VIEW_P2P_SEND, stack: stack.push())
symLog.log("❗️ onAppear")
@@ -176,17 +191,6 @@ struct SendAmountView: View {
.onDisappear {
symLog.log("❗️ onDisappear")
}
- .task(id: balance) { // getMaxPeerPushDebit on first appearance
- let scope = balance.scopeInfo
- symLog.log("❗️ task \(scope.currency)")
-
- if let available = try? await
model.getMaxPeerPushDebitAmountM(scope, viewHandles: true) {
- amountAvailable = available
- } else {
- amountAvailable = Amount.zero(currency: scope.currency)
- }
- scopeInfo = scope
- }
// .task(id: amountToTransfer.value) {
// if exchange == nil {
// if let url = scopeInfo.url {
diff --git a/TalerWallet1/Views/Sheets/P2P_Sheets/P2pAcceptDone.swift
b/TalerWallet1/Views/Sheets/P2P_Sheets/P2pAcceptDone.swift
index 997166a..1986f07 100644
--- a/TalerWallet1/Views/Sheets/P2P_Sheets/P2pAcceptDone.swift
+++ b/TalerWallet1/Views/Sheets/P2P_Sheets/P2pAcceptDone.swift
@@ -17,13 +17,14 @@ struct P2pAcceptDone: View {
@EnvironmentObject private var controller: Controller
@EnvironmentObject private var model: WalletModel
+ @MainActor
private func viewDidLoad() async {
if incoming {
- if let _ = try? await model.acceptPeerPushCreditM(transactionId) {
+ if let _ = try? await model.acceptPeerPushCredit(transactionId) {
dismissTop(stack.push())
}
} else {
- if let _ = try? await model.confirmPeerPullDebitM(transactionId) {
+ if let _ = try? await model.confirmPeerPullDebit(transactionId) {
dismissTop(stack.push())
}
}
diff --git a/TalerWallet1/Views/Sheets/P2P_Sheets/P2pPayURIView.swift
b/TalerWallet1/Views/Sheets/P2P_Sheets/P2pPayURIView.swift
index ee9cfdf..5f0909b 100644
--- a/TalerWallet1/Views/Sheets/P2P_Sheets/P2pPayURIView.swift
+++ b/TalerWallet1/Views/Sheets/P2P_Sheets/P2pPayURIView.swift
@@ -26,6 +26,14 @@ struct P2pPayURIView: View {
let navTitle = String(localized: "Pay P2P", comment: "Nav Title")
+ @MainActor
+ private func viewDidLoad() async {
+ do {
+ symLog.log(".task")
+ peerPullDebitResponse = try? await
model.preparePeerPullDebit(url.absoluteString)
+ }
+ }
+
var body: some View {
VStack {
if let peerPullDebitResponse {
@@ -82,10 +90,7 @@ struct P2pPayURIView: View {
let message: String? = nil
#endif
LoadingView(scopeInfo: nil, message: message)
- .task { do {
- symLog.log(".task")
- peerPullDebitResponse = try? await
model.preparePeerPullDebitM(url.absoluteString)
- } }
+ .task { await viewDidLoad() }
}
}
.onAppear() {
diff --git a/TalerWallet1/Views/Sheets/P2P_Sheets/P2pReceiveURIView.swift
b/TalerWallet1/Views/Sheets/P2P_Sheets/P2pReceiveURIView.swift
index 8e3a32e..9915495 100644
--- a/TalerWallet1/Views/Sheets/P2P_Sheets/P2pReceiveURIView.swift
+++ b/TalerWallet1/Views/Sheets/P2P_Sheets/P2pReceiveURIView.swift
@@ -1,7 +1,10 @@
/*
- * This file is part of GNU Taler, ©2022-23 Taler Systems S.A.
+ * This file is part of GNU Taler, ©2022-24 Taler Systems S.A.
* See LICENSE.md
*/
+/**
+ * @author Marc Stibane
+ */
import SwiftUI
import taler_swift
import SymLog
@@ -31,7 +34,7 @@ struct P2pReceiveURIView: View {
@MainActor
private func viewDidLoad() async {
symLog.log(".task")
- if let ppResponse = try? await
model.preparePeerPushCreditM(url.absoluteString) {
+ if let ppResponse = try? await
model.preparePeerPushCredit(url.absoluteString) {
let baseUrl = ppResponse.exchangeBaseUrl
exchange = try? await model.getExchangeByUrl(url: baseUrl)
await controller.checkCurrencyInfo(for: baseUrl, model: model)
@@ -42,6 +45,10 @@ struct P2pReceiveURIView: View {
}
var body: some View {
+#if PRINT_CHANGES
+ let _ = Self._printChanges()
+ let _ = symLog.vlog() // just to get the # to compare it with
.onAppear & onDisappear
+#endif
VStack {
if let peerPushCreditResponse {
let tosAccepted = exchange?.tosStatus == .accepted
@@ -106,12 +113,11 @@ struct P2pReceiveURIView: View {
LoadingView(scopeInfo: nil, message: message)
}
}
+ // must be here and not at LoadingView(), because this needs to run a
2nd time after ToS was accepted
+ .task { await viewDidLoad() }
.onAppear() {
symLog.log("onAppear")
DebugViewC.shared.setSheetID(SHEET_RCV_P2P)
}
- .task { // must be here and not at LoadingView(), because this needs
to run a 2nd time after ToS was accepted
- await viewDidLoad()
- }
}
}
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [taler-taler-ios] 105/204: NavLink, (continued)
- [taler-taler-ios] 105/204: NavLink, gnunet, 2024/12/05
- [taler-taler-ios] 109/204: loadBalances, gnunet, 2024/12/05
- [taler-taler-ios] 106/204: Use NavLink, gnunet, 2024/12/05
- [taler-taler-ios] 113/204: PendingOperations (unused), gnunet, 2024/12/05
- [taler-taler-ios] 114/204: Pay, gnunet, 2024/12/05
- [taler-taler-ios] 110/204: deposit, gnunet, 2024/12/05
- [taler-taler-ios] 122/204: Yellow for confirm, gnunet, 2024/12/05
- [taler-taler-ios] 119/204: cleanup, gnunet, 2024/12/05
- [taler-taler-ios] 120/204: Withdraw, gnunet, 2024/12/05
- [taler-taler-ios] 116/204: Settings, gnunet, 2024/12/05
- [taler-taler-ios] 112/204: P2P,
gnunet <=
- [taler-taler-ios] 121/204: TransactionById, gnunet, 2024/12/05
- [taler-taler-ios] 123/204: fake currency, gnunet, 2024/12/05
- [taler-taler-ios] 108/204: inputAccessory 'return', gnunet, 2024/12/05
- [taler-taler-ios] 124/204: move DB to AppSupport, gnunet, 2024/12/05
- [taler-taler-ios] 111/204: exchange, gnunet, 2024/12/05
- [taler-taler-ios] 118/204: demoHints, gnunet, 2024/12/05
- [taler-taler-ios] 126/204: cleanup, gnunet, 2024/12/05
- [taler-taler-ios] 128/204: less logging, gnunet, 2024/12/05
- [taler-taler-ios] 129/204: currencyInfo, gnunet, 2024/12/05
- [taler-taler-ios] 131/204: wire fee, gnunet, 2024/12/05