diff options
Diffstat (limited to 'TalerWallet1/Model/WalletModel.swift')
-rw-r--r-- | TalerWallet1/Model/WalletModel.swift | 43 |
1 files changed, 32 insertions, 11 deletions
diff --git a/TalerWallet1/Model/WalletModel.swift b/TalerWallet1/Model/WalletModel.swift index 9e48f44..8aaa1e2 100644 --- a/TalerWallet1/Model/WalletModel.swift +++ b/TalerWallet1/Model/WalletModel.swift @@ -67,17 +67,26 @@ class WalletModel: ObservableObject { throw error } } +} +// MARK: - +/// A request to tell wallet-core about the network. +fileprivate struct NetworkAvailabilityRequest: WalletBackendFormattedRequest { + struct Response: Decodable {} + func operation() -> String { "hintNetworkAvailability" } + func args() -> Args { Args(isNetworkAvailable: isNetworkAvailable) } - func getTransactionByIdT(_ transactionId: String, viewHandles: Bool = false) - async throws -> Transaction { // T for any Thread - // might be called from a background thread itself - let request = GetTransactionById(transactionId: transactionId) - return try await sendRequest(request, ASYNCDELAY, viewHandles: viewHandles) + var isNetworkAvailable: Bool + + struct Args: Encodable { + var isNetworkAvailable: Bool } - /// get the specified transaction from Wallet-Core. No networking involved - @MainActor func getTransactionByIdM(_ transactionId: String, viewHandles: Bool = false) - async throws -> Transaction { // M for MainActor - return try await getTransactionByIdT(transactionId, viewHandles: viewHandles) // call GetTransactionById on main thread +} + +extension WalletModel { + func hintNetworkAvailabilityT(_ isNetworkAvailable: Bool = false) async { + // T for any Thread + let request = NetworkAvailabilityRequest(isNetworkAvailable: isNetworkAvailable) + _ = try? await sendRequest(request, 0) } } // MARK: - @@ -93,6 +102,20 @@ fileprivate struct GetTransactionById: WalletBackendFormattedRequest { var transactionId: String } } + +extension WalletModel { + func getTransactionByIdT(_ transactionId: String, viewHandles: Bool = false) + async throws -> Transaction { // T for any Thread + // might be called from a background thread itself + let request = GetTransactionById(transactionId: transactionId) + return try await sendRequest(request, ASYNCDELAY, viewHandles: viewHandles) + } + /// get the specified transaction from Wallet-Core. No networking involved + @MainActor func getTransactionByIdM(_ transactionId: String, viewHandles: Bool = false) + async throws -> Transaction { // M for MainActor + return try await getTransactionByIdT(transactionId, viewHandles: viewHandles) // call GetTransactionById on main thread + } +} // MARK: - /// The info returned from Wallet-core init struct VersionInfo: Decodable { @@ -257,7 +280,6 @@ extension WalletModel { } } // MARK: - - fileprivate struct DevExperimentRequest: WalletBackendFormattedRequest { func operation() -> String { "applyDevExperiment" } func args() -> Args { Args(devExperimentUri: talerUri) } @@ -278,4 +300,3 @@ extension WalletModel { _ = try await sendRequest(request, 0, viewHandles: viewHandles) } } - |