[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-taler-ios] 02/07: ported remaining sync wallet-core funcs to try
From: |
gnunet |
Subject: |
[taler-taler-ios] 02/07: ported remaining sync wallet-core funcs to try await |
Date: |
Wed, 22 Feb 2023 16:16:29 +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 3cb19f272b49399fd5283c0da6a5896e85ec220e
Author: Marc Stibane <marc@taler.net>
AuthorDate: Fri Feb 17 07:52:27 2023 +0100
ported remaining sync wallet-core funcs to try await
---
TalerWallet1/Backend/WalletCore.swift | 18 +-----
TalerWallet1/Model/ExchangeTestModel.swift | 77 +++++++++-----------------
TalerWallet1/Views/Settings/SettingsView.swift | 26 +++++++--
3 files changed, 48 insertions(+), 73 deletions(-)
diff --git a/TalerWallet1/Backend/WalletCore.swift
b/TalerWallet1/Backend/WalletCore.swift
index ff67b15..be7450d 100644
--- a/TalerWallet1/Backend/WalletCore.swift
+++ b/TalerWallet1/Backend/WalletCore.swift
@@ -116,6 +116,7 @@ extension WalletCore {
symLog.log(payload)
Task {
do {
+ // automatically fetch balances after receiving
these notifications
try await
Controller.shared.balancesModel.fetchBalances()
} catch {
// TODO: show error
@@ -210,23 +211,6 @@ extension WalletCore {
completionHandler(id, nil, WalletCore.serializeRequestError());
}
}
-
- /// call this to send requests to wallet-core
- func sendFormattedRequest<T: WalletBackendFormattedRequest>
- (request: T, completionHandler: @escaping (T.Response?,
WalletBackendResponseError?) -> Void)
- {
- let reqData = WalletBackendRequest(operation: request.operation(),
- args:
AnyEncodable(request.args()))
- sendRequest(request: reqData) { (id: UInt, result: Data?, err:
WalletBackendResponseError?) in
- guard let json = result else { completionHandler(nil, err); return
}
- do {
- let decoded = try JSONDecoder().decode(T.Response.self, from:
json)
- completionHandler(decoded, err)
- } catch {
- completionHandler(nil, WalletCore.parseResponseError())
- }
- }
- }
}
// MARK: - async / await function
extension WalletCore {
diff --git a/TalerWallet1/Model/ExchangeTestModel.swift
b/TalerWallet1/Model/ExchangeTestModel.swift
index f73592a..13a29b3 100644
--- a/TalerWallet1/Model/ExchangeTestModel.swift
+++ b/TalerWallet1/Model/ExchangeTestModel.swift
@@ -16,6 +16,7 @@
import Foundation
import taler_swift
import SymLog
+fileprivate let ASYNCDELAY: UInt = 0 //set e.g to 6 or 9 seconds for
debugging
fileprivate let EXCHANGEBASEURL = "https://exchange.demo.taler.net/"
fileprivate let BANKBASEURL = "https://bank.demo.taler.net/"
@@ -24,62 +25,38 @@ fileprivate let MERCHANTBASEURL =
"https://backend.demo.taler.net/"
fileprivate let MERCHANTAUTHTOKEN = "secret-token:sandbox"
// MARK: -
-class ExchangeTestModel: ObservableObject {
- private let symLog = SymLogC(0)
-
- var walletCore: WalletCore
-
- @Published var loading: Bool = false
-
- init(walletCore: WalletCore) {
- self.walletCore = walletCore
- }
+class ExchangeTestModel: WalletModel {
}
// MARK: -
extension ExchangeTestModel {
- func loadTestKudos() {
- loading = true
-
- let amount = Amount(currency: "KUDOS", integer: 11, fraction: 0)
- let req = WalletBackendWithdrawTestBalance(amount: amount,
bankBaseUrl: BANKBASEURL,
- exchangeBaseUrl: EXCHANGEBASEURL,
bankAccessApiBaseUrl: BANKACCESSAPIBASEURL)
- symLog.log("sending: \(req)")
- walletCore.sendFormattedRequest(request: req) { response, err in
- DispatchQueue.main.async {
- self.loading = false
- if let res = response {
- // TODO: ?
- self.symLog.log("received: \(res)")
- } else {
- // TODO: Handle error
- }
- }
+ @MainActor func loadTestKudos() async throws {
+ do {
+ let amount = Amount(currency: "KUDOS", integer: 11, fraction: 0)
+ let request = WalletBackendWithdrawTestBalance(amount: amount,
+ bankBaseUrl: BANKBASEURL,
+ exchangeBaseUrl:
EXCHANGEBASEURL,
+ bankAccessApiBaseUrl:
BANKACCESSAPIBASEURL)
+ let response = try await sendRequest(request, ASYNCDELAY)
+ symLog?.log("received: \(response)")
+ } catch {
+ throw error
}
}
- func runIntegrationTest() {
- loading = true
-
- let amountW = Amount(currency: "KUDOS", integer: 3, fraction: 0)
- let amountS = Amount(currency: "KUDOS", integer: 1, fraction: 0)
- let req = WalletBackendRunIntegration(amountToWithdraw: amountW,
- amountToSpend: amountS,
- bankBaseUrl:
BANKACCESSAPIBASEURL,
- exchangeBaseUrl: EXCHANGEBASEURL,
- merchantBaseUrl: MERCHANTBASEURL,
- merchantAuthToken:
MERCHANTAUTHTOKEN
- )
- symLog.log("sending: \(req)")
- walletCore.sendFormattedRequest(request: req) { response, err in
- DispatchQueue.main.async {
- self.loading = false
- if let res = response {
- // TODO: ?
- self.symLog.log("received: \(res)")
- } else {
- // TODO: Handle error
- }
- }
+ @MainActor func runIntegrationTest() async throws {
+ do {
+ let amountW = Amount(currency: "KUDOS", integer: 3, fraction: 0)
+ let amountS = Amount(currency: "KUDOS", integer: 1, fraction: 0)
+ let request = WalletBackendRunIntegration(amountToWithdraw:
amountW,
+ amountToSpend:
amountS,
+ bankBaseUrl:
BANKACCESSAPIBASEURL,
+ exchangeBaseUrl:
EXCHANGEBASEURL,
+ merchantBaseUrl:
MERCHANTBASEURL,
+ merchantAuthToken:
MERCHANTAUTHTOKEN)
+ let response = try await sendRequest(request, ASYNCDELAY)
+ symLog?.log("received: \(response)")
+ } catch {
+ throw error
}
}
}
diff --git a/TalerWallet1/Views/Settings/SettingsView.swift
b/TalerWallet1/Views/Settings/SettingsView.swift
index a2f3ea5..b84b242 100644
--- a/TalerWallet1/Views/Settings/SettingsView.swift
+++ b/TalerWallet1/Views/Settings/SettingsView.swift
@@ -66,9 +66,16 @@ struct SettingsView: View {
SettingsItem(name: "Withdraw KUDOS", description: "Get
money for testing") {
Button("Withdraw") {
withDrawDisabled = true // don't run twice
- let testModel: ExchangeTestModel =
ExchangeTestModel(walletCore: walletCore)
- symLog.log("Withdrawing ")
- testModel.loadTestKudos()
+ Task {
+ let testModel: ExchangeTestModel =
ExchangeTestModel(walletCore: walletCore)
+ symLog.log("Withdrawing")
+ do {
+ try await testModel.loadTestKudos()
+ } catch {
+ // TODO: show error
+ symLog.log(error.localizedDescription)
+ }
+ }
}
.buttonStyle(.bordered)
.disabled(withDrawDisabled)
@@ -76,9 +83,16 @@ struct SettingsView: View {
SettingsItem(name: "Run Integration Test", description:
"Check if wallet-core works") {
Button("Check") {
checkDisabled = true // don't run twice
- let testModel: ExchangeTestModel =
ExchangeTestModel(walletCore: walletCore)
- symLog.log("running integration test ")
- testModel.runIntegrationTest()
+ Task {
+ let testModel: ExchangeTestModel =
ExchangeTestModel(walletCore: walletCore)
+ symLog.log("running integration test")
+ do {
+ try await testModel.runIntegrationTest()
+ } catch {
+ // TODO: show error
+ symLog.log(error.localizedDescription)
+ }
+ }
}
.buttonStyle(.bordered)
.disabled(checkDisabled)
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [taler-taler-ios] branch master updated (df4fe35 -> 4f2b20c), gnunet, 2023/02/22
- [taler-taler-ios] 01/07: Error handling, Amount.diff, gnunet, 2023/02/22
- [taler-taler-ios] 04/07: Constants, cleanup, gnunet, 2023/02/22
- [taler-taler-ios] 03/07: added ext+taler and web+taler to the list of recognized URL schemes, gnunet, 2023/02/22
- [taler-taler-ios] 06/07: Info & SceneConfigurations, v0.9.2, bundleID, gnunet, 2023/02/22
- [taler-taler-ios] 02/07: ported remaining sync wallet-core funcs to try await,
gnunet <=
- [taler-taler-ios] 05/07: Transaction definition and JSON decoding - Bug 7678, gnunet, 2023/02/22
- [taler-taler-ios] 07/07: Transaction list and details, gnunet, 2023/02/22