commit c5b6f18b0ad545c6ef43372b0fe9024695e48ddc
parent 25d37c2412eb436f7e0d4a558c6732abda075f74
Author: Marc Stibane <marc@taler.net>
Date: Thu, 4 Apr 2024 21:12:43 +0200
setConfig(devModeActive)
Diffstat:
4 files changed, 59 insertions(+), 24 deletions(-)
diff --git a/TalerWallet1/Controllers/Controller.swift b/TalerWallet1/Controllers/Controller.swift
@@ -142,12 +142,12 @@ class Controller: ObservableObject {
}
// MARK: -
@MainActor
- func initWalletCore(_ model: WalletModel, sqlite3: Bool)
+ func initWalletCore(_ model: WalletModel, setTesting: Bool)
async throws {
if backendState == .instantiated {
backendState = .initing
do {
- let versionInfo = try await model.initWalletCoreT(sqlite3: sqlite3)
+ let versionInfo = try await model.initWalletCoreT(setTesting: setTesting)
WalletCore.shared.versionInfo = versionInfo
backendState = .ready // dismiss the launch animation
} catch { // rethrows
diff --git a/TalerWallet1/Controllers/TalerWallet1App.swift b/TalerWallet1/Controllers/TalerWallet1App.swift
@@ -27,7 +27,6 @@ struct TalerWallet1App: App {
private let model = WalletModel.shared
private let debugViewC = DebugViewC.shared
let logger = Logger(subsystem: "net.taler.gnu", category: "Main App")
- let sqlite3 = true // true = SQLITE3, false = JSON
func scheduleAppRefresh() {
let request = BGAppRefreshTaskRequest(identifier: "net.taler.gnu.refresh")
@@ -47,7 +46,7 @@ struct TalerWallet1App: App {
/// we handle them in .onOpenURL in MainView.swift
.handlesExternalEvents(preferring: ["*"], allowing: ["*"])
.task {
- try! await controller.initWalletCore(model, sqlite3: sqlite3) // will (and should) crash on failure
+ try! await controller.initWalletCore(model, setTesting: false) // will (and should) crash on failure
}
.onReceive(NotificationCenter.default.publisher(for: UIApplication.didBecomeActiveNotification, object: nil)) { _ in
logger.log("❗️App Did Become Active")
diff --git a/TalerWallet1/Model/WalletModel.swift b/TalerWallet1/Model/WalletModel.swift
@@ -87,14 +87,61 @@ struct VersionInfo: Decodable {
var bank: String
}
// MARK: -
+fileprivate struct Testing: Encodable {
+ var devModeActive: Bool
+ // more to come...
+}
+
+fileprivate struct Builtin: Encodable {
+ var exchanges: [String]
+ // more to come...
+}
+
+fileprivate struct Config: Encodable {
+ var testing: Testing
+ var builtin: Builtin
+}
+// MARK: -
+/// A request to re-configure Wallet-core
+fileprivate struct ConfigRequest: WalletBackendFormattedRequest {
+ var setTesting: Bool
+
+ func operation() -> String { "setConfig" }
+ func args() -> Args {
+ let testing = Testing(devModeActive: setTesting)
+ let builtin = Builtin(exchanges: [])
+ let config = Config(testing: testing, builtin: builtin)
+ return Args(config: config)
+ }
+
+ struct Args: Encodable {
+ var config: Config
+ }
+ struct Response: Decodable {
+ var versionInfo: VersionInfo
+ }
+}
+
+extension WalletModel {
+ /// initalize Wallet-Core. Will do networking
+ func setConfigT(setTesting: Bool) async throws -> VersionInfo {
+ // T for any Thread
+ let request = ConfigRequest(setTesting: setTesting)
+ let response = try await sendRequest(request, 0) // no Delay
+ return response.versionInfo
+ }
+}
+// MARK: -
/// A request to initialize Wallet-core
fileprivate struct InitRequest: WalletBackendFormattedRequest {
+ var persistentStoragePath: String
+ var setTesting: Bool
+
func operation() -> String { "init" }
func args() -> Args {
- let testing = Testing(devModeActive: false) // true, false
+ let testing = Testing(devModeActive: setTesting)
let builtin = Builtin(exchanges: [])
-// let config = Config(testing: testing, builtin: builtin)
- let config = Config(testing: testing)
+ let config = Config(testing: testing, builtin: builtin)
return Args(persistentStoragePath: persistentStoragePath,
// cryptoWorkerType: "sync",
logLevel: "info", // trace, info, warn, error, none
@@ -102,20 +149,6 @@ fileprivate struct InitRequest: WalletBackendFormattedRequest {
useNativeLogging: true)
}
- var persistentStoragePath: String
-
- struct Testing: Encodable {
- var devModeActive: Bool
- // more to come...
- }
- struct Builtin: Encodable {
- var exchanges: [String]
- // more to come...
- }
- struct Config: Encodable {
- var testing: Testing
-// var builtin: Builtin
- }
struct Args: Encodable {
var persistentStoragePath: String
// var cryptoWorkerType: String
@@ -130,10 +163,10 @@ fileprivate struct InitRequest: WalletBackendFormattedRequest {
extension WalletModel {
/// initalize Wallet-Core. Will do networking
- func initWalletCoreT(sqlite3: Bool) async throws -> VersionInfo {
+ func initWalletCoreT(setTesting: Bool) async throws -> VersionInfo {
// T for any Thread
- let docPath = try docPath(sqlite3: sqlite3)
- let request = InitRequest(persistentStoragePath: docPath)
+ let docPath = try docPath(sqlite3: true)
+ let request = InitRequest(persistentStoragePath: docPath, setTesting: setTesting)
let response = try await sendRequest(request, 0) // no Delay
return response.versionInfo
}
diff --git a/TalerWallet1/Views/Settings/SettingsView.swift b/TalerWallet1/Views/Settings/SettingsView.swift
@@ -194,6 +194,7 @@ struct SettingsView: View {
walletCore.developDelay = delay}), id1: "delay",
description: hideDescriptions ? nil : String("After each wallet-core action"))
.id("delay")
+#if DEBUG
SettingsItem(name: String("Run Dev Experiment"), id1: "applyDevExperiment",
description: hideDescriptions ? nil : "dev-experiment/insert-pending-refresh") {
let title = "Refresh"
@@ -201,6 +202,7 @@ struct SettingsView: View {
Task { // runs on MainActor
symLog.log("running applyDevExperiment Refresh")
do {
+ try await model.setConfigT(setTesting: true)
try await model.devExperimentT(talerUri: "taler://dev-experiment/insert-pending-refresh")
} catch { // TODO: show error
symLog.log(error.localizedDescription)
@@ -209,6 +211,7 @@ struct SettingsView: View {
}
.buttonStyle(.bordered)
}.id("Refresh")
+#endif
SettingsItem(name: String("Run Integration Test"), id1: "demo1test",
description: hideDescriptions ? nil : String("Perform basic test transactions")) {
let title = "Demo 1"