[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-taler-ios] 110/204: deposit
From: |
gnunet |
Subject: |
[taler-taler-ios] 110/204: deposit |
Date: |
Thu, 05 Dec 2024 23:51:18 +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 0fa2a78a863e04b79c2fd24423ea5b6669884b6d
Author: Marc Stibane <marc@taler.net>
AuthorDate: Fri Nov 8 18:55:48 2024 +0100
deposit
---
TalerWallet1/Model/Model+Deposit.swift | 24 ++++-----
.../Views/Actions/Banking/DepositAmountV.swift | 63 ++++++++++++----------
.../Views/Actions/Banking/DepositIbanV.swift | 19 ++++---
3 files changed, 55 insertions(+), 51 deletions(-)
diff --git a/TalerWallet1/Model/Model+Deposit.swift
b/TalerWallet1/Model/Model+Deposit.swift
index 7894d33..640ca84 100644
--- a/TalerWallet1/Model/Model+Deposit.swift
+++ b/TalerWallet1/Model/Model+Deposit.swift
@@ -28,9 +28,8 @@ fileprivate struct ValidateIban:
WalletBackendFormattedRequest {
}
extension WalletModel {
/// validate IBAN. No Networking
- @MainActor // M for MainActor
- func validateIbanM(_ iban: String, viewHandles: Bool = false)
- async throws -> Bool {
+ nonisolated func validateIban(_ iban: String, viewHandles: Bool = false)
+ async throws -> Bool {
let request = ValidateIban(iban: iban)
let response = try await sendRequest(request, ASYNCDELAY, viewHandles:
viewHandles)
return response.valid
@@ -56,8 +55,7 @@ fileprivate struct DepositWireTypesForCurrency:
WalletBackendFormattedRequest {
}
extension WalletModel {
/// Get wire types that can be used for a deposit operation
- @MainActor // M for MainActor
- func depositWireTypesForCurrencyM(_ currency: String, scopeInfo:
ScopeInfo? = nil, viewHandles: Bool = false)
+ nonisolated func depositWireTypesForCurrency(_ currency: String,
scopeInfo: ScopeInfo? = nil, viewHandles: Bool = false)
async throws -> [String] {
let request = DepositWireTypesForCurrency(currency: currency,
scopeInfo: scopeInfo)
let response = try await sendRequest(request, ASYNCDELAY, viewHandles:
viewHandles)
@@ -73,9 +71,8 @@ fileprivate struct AmountResponse: Codable {
fileprivate struct GetMaxDepositAmount: WalletBackendFormattedRequest {
typealias Response = AmountResponse
func operation() -> String { "getMaxDepositAmount" }
- func args() -> Args { Args(currency: currency, restrictScope: scope) }
+ func args() -> Args { Args(currency: scope.currency, restrictScope: scope)
}
- var currency: String
var scope: ScopeInfo
struct Args: Encodable {
var currency: String
@@ -84,14 +81,13 @@ fileprivate struct GetMaxDepositAmount:
WalletBackendFormattedRequest {
}
}
extension WalletModel {
- @MainActor // M for MainActor
- func getMaxDepositAmountM(_ currency: String, scope: ScopeInfo,
viewHandles: Bool = false)
+ nonisolated func getMaxDepositAmount(_ scope: ScopeInfo, viewHandles: Bool
= false)
async throws -> Amount {
- let request = GetMaxDepositAmount(currency: currency, scope: scope)
+ let request = GetMaxDepositAmount(scope: scope)
let response = try await sendRequest(request, ASYNCDELAY, viewHandles:
viewHandles)
return response.rawAmount
}
-} // getMaxDepositAmountM
+} // getMaxDepositAmount
// MARK: - Deposit
struct DepositFees: Codable {
let coin: Amount
@@ -139,8 +135,7 @@ fileprivate struct CreateDepositGroup:
WalletBackendFormattedRequest {
// MARK: -
extension WalletModel {
/// check fees for deposit. No Networking
- @MainActor // M for MainActor
- func checkDepositM(_ depositPaytoUri: String, amount: Amount, viewHandles:
Bool = false)
+ nonisolated func checkDeposit(_ depositPaytoUri: String, amount: Amount,
viewHandles: Bool = false)
async throws -> CheckDepositResponse {
let request = CheckDeposit(depositPaytoUri: depositPaytoUri, amount:
amount)
let response = try await sendRequest(request, ASYNCDELAY,
viewHandles: viewHandles)
@@ -148,8 +143,7 @@ extension WalletModel {
}
/// deposit coins. Networking involved
- @MainActor // M for MainActor
- func createDepositGroupM(_ depositPaytoUri: String, amount: Amount,
viewHandles: Bool = false)
+ nonisolated func createDepositGroup(_ depositPaytoUri: String, amount:
Amount, viewHandles: Bool = false)
async throws -> DepositGroupResult {
let request = CreateDepositGroup(depositPaytoUri: depositPaytoUri,
amount: amount)
let response = try await sendRequest(request, ASYNCDELAY,
viewHandles: viewHandles)
diff --git a/TalerWallet1/Views/Actions/Banking/DepositAmountV.swift
b/TalerWallet1/Views/Actions/Banking/DepositAmountV.swift
index 4263762..71ba9eb 100644
--- a/TalerWallet1/Views/Actions/Banking/DepositAmountV.swift
+++ b/TalerWallet1/Views/Actions/Banking/DepositAmountV.swift
@@ -25,6 +25,7 @@ struct DepositAmountV: 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 {
let balances = controller.balances
if let selectedBalance {
@@ -45,6 +46,21 @@ struct DepositAmountV: View {
}
}
+ @MainActor
+ private func newBalance() async {
+ symLog.log("❗️ task \(balanceIndex)")
+ if let balance {
+ let scopeInfo = balance.scopeInfo
+ amountToTransfer.setCurrency(scopeInfo.currency)
+ do {
+ amountAvailable = try await
model.getMaxDepositAmount(scopeInfo)
+ } catch {
+ // TODO: Error
+ amountAvailable = balance.available
+ }
+ }
+ }
+
var body: some View {
#if PRINT_CHANGES
let _ = Self._printChanges()
@@ -84,19 +100,7 @@ struct DepositAmountV: View {
symLog.log("❗️ \(navTitle) onDisappear")
}
.task { await viewDidLoad() }
- .task(id: balanceIndex + (1000 * controller.currencyTicker)) {
- symLog.log("❗️ task \(balanceIndex)")
- if let balance {
- let scopeInfo = balance.scopeInfo
- amountToTransfer.setCurrency(scopeInfo.currency)
- do {
- amountAvailable = try await
model.getMaxPeerPushDebitAmountM(scopeInfo)
- } catch {
- // TODO: Error
- amountAvailable = balance.available
- }
- }
- }
+ .task(id: balanceIndex + (1000 * controller.currencyTicker)) {
await newBalance() }
if #available(iOS 16.0, *) {
if #available(iOS 16.4, *) {
@@ -185,6 +189,23 @@ struct DepositAmountContent: View {
// defaultValue: "Deposit \(amountStr)", comment:
"NavTitle: Deposit 'amountStr'")
}
+ @MainActor
+ private func startDeposit() {
+ if let paytoUri {
+ depositStarted = true // don't run twice
+ Task {
+ symLog.log("Deposit")
+ if let result = try? await model.createDepositGroup(paytoUri,
amount: amountToTransfer) {
+ symLog.log(result.transactionId)
+ ViewState2.shared.popToRootView(stack.push())
+ NotificationCenter.default.post(name: .TransactionDone,
object: nil, userInfo: nil)
+ } else {
+ depositStarted = false
+ }
+ }
+ }
+ }
+
var body: some View {
#if PRINT_CHANGES
let _ = Self._printChanges()
@@ -224,21 +245,7 @@ struct DepositAmountContent: View {
: (feeAmount?.isZero ??
true) ? WalletColors().secondary(colorScheme, colorSchemeContrast)
: .red)
.padding(4)
- Button(buttonTitle(amountToTransfer)) {
- if let paytoUri {
- depositStarted = true // don't run twice
- Task { // runs on MainActor
- symLog.log("Deposit")
- if let result = try? await
model.createDepositGroupM(paytoUri, amount: amountToTransfer) {
- symLog.log(result.transactionId)
- ViewState2.shared.popToRootView(stack.push())
- NotificationCenter.default.post(name:
.TransactionDone, object: nil, userInfo: nil)
- } else {
- depositStarted = false
- }
- }
- }
- }
+ Button(buttonTitle(amountToTransfer)) { startDeposit() }
.buttonStyle(TalerButtonStyle(type: .prominent, disabled:
disabled || depositStarted))
.disabled(disabled || depositStarted)
.accessibilityHint(disabled ? String(localized: "enabled when
amount is non-zero, but not higher than your available amount") : EMPTYSTRING)
diff --git a/TalerWallet1/Views/Actions/Banking/DepositIbanV.swift
b/TalerWallet1/Views/Actions/Banking/DepositIbanV.swift
index 916069c..9029f19 100644
--- a/TalerWallet1/Views/Actions/Banking/DepositIbanV.swift
+++ b/TalerWallet1/Views/Actions/Banking/DepositIbanV.swift
@@ -50,6 +50,16 @@ struct DepositIbanV: View {
comment: "NavTitle: Deposit")
}
+ @MainActor
+ private func validateIban() async {
+ if (try? await model.validateIban(depositIBAN)) == true {
+ let payto =
"payto://iban/\(depositIBAN)?receiver-name=\(accountHolder)"
+ paytoUri = payto.addingPercentEncoding(withAllowedCharacters:
.urlQueryAllowed)!
+ } else {
+ paytoUri = nil
+ }
+ }
+
var body: some View {
#if PRINT_CHANGES
let _ = Self._printChanges()
@@ -116,14 +126,7 @@ struct DepositIbanV: View {
.onDisappear {
// print("❗️ P2PSubjectV onDisappear")
}
- .task(id: depositIBAN) {
- if (try? await model.validateIbanM(depositIBAN)) == true {
- let payto =
"payto://iban/\(depositIBAN)?receiver-name=\(accountHolder)"
- paytoUri = payto.addingPercentEncoding(withAllowedCharacters:
.urlQueryAllowed)!
- } else {
- paytoUri = nil
- }
- }
+ .task(id: depositIBAN) { await validateIban() }
}
}
// MARK: -
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [taler-taler-ios] 97/204: TransactionCommon, row, (continued)
- [taler-taler-ios] 97/204: TransactionCommon, row, gnunet, 2024/12/05
- [taler-taler-ios] 101/204: CheckDepositResponse, gnunet, 2024/12/05
- [taler-taler-ios] 104/204: split, gnunet, 2024/12/05
- [taler-taler-ios] 107/204: debug, fix wrong comparison, gnunet, 2024/12/05
- [taler-taler-ios] 102/204: task viewDidLoad, gnunet, 2024/12/05
- [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 <=
- [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, 2024/12/05
- [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