gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-taler-ios] 04/40: CheckDeposit with cancellation


From: gnunet
Subject: [taler-taler-ios] 04/40: CheckDeposit with cancellation
Date: Mon, 22 Jul 2024 22:45:57 +0200

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 5abe4b8a7a285031c3bdcdf8a8dc39ede3eb5f43
Author: Marc Stibane <marc@taler.net>
AuthorDate: Wed Jul 17 08:38:54 2024 +0200

    CheckDeposit with cancellation
---
 TalerWallet1/Model/Model+Deposit.swift          | 42 +++++++++++++------------
 TalerWallet1/Views/Banking/DepositAmountV.swift | 14 ++++-----
 2 files changed, 29 insertions(+), 27 deletions(-)

diff --git a/TalerWallet1/Model/Model+Deposit.swift 
b/TalerWallet1/Model/Model+Deposit.swift
index 2d520ca..417e828 100644
--- a/TalerWallet1/Model/Model+Deposit.swift
+++ b/TalerWallet1/Model/Model+Deposit.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 Foundation
 import taler_swift
 import AnyCodable
@@ -9,7 +12,6 @@ import AnyCodable
 fileprivate let ASYNCDELAY: UInt = 0   //set e.g to 6 or 9 seconds for 
debugging
 
 // MARK: - IBAN
-/// The result from PrepareDeposit
 struct ValidateIbanResult: Codable {
     let valid: Bool
 }
@@ -31,28 +33,27 @@ struct DepositFees: Codable {
     let wire: Amount
     let refresh: Amount
 }
-
-/// The result from PrepareDeposit
-struct PrepareDepositResult: Codable {
+struct CheckDepositResult: Codable {
     let totalDepositCost: Amount
     let effectiveDepositAmount: Amount
     let fees: DepositFees
 }
 /// A request to get an exchange's deposit contract terms.
-fileprivate struct PrepareDeposit: WalletBackendFormattedRequest {
-    typealias Response = PrepareDepositResult
-    func operation() -> String { "prepareDeposit" }
-    func args() -> Args { Args(depositPaytoUri: depositPaytoUri, amount: 
amount) }
+fileprivate struct CheckDeposit: WalletBackendFormattedRequest {
+    typealias Response = CheckDepositResult
+    func operation() -> String { "checkDeposit" }
+    func args() -> Args { Args(depositPaytoUri: depositPaytoUri, amount: 
amount, clientCancellationId: cancellationId) }
 
     var depositPaytoUri: String
     var amount: Amount
+    var cancellationId: String?
     struct Args: Encodable {
         var depositPaytoUri: String
         var amount: Amount
+        var clientCancellationId: String?
     }
 }
 // MARK: -
-/// The result from CreateDepositGroup
 struct DepositGroupResult: Decodable {
     var depositGroupId: String
     var transactionId: String
@@ -72,26 +73,27 @@ fileprivate struct CreateDepositGroup: 
WalletBackendFormattedRequest {
 }
 // MARK: -
 extension WalletModel {
-    /// validate IBAN
-    @MainActor
-    func validateIbanM(_ iban: String, viewHandles: Bool = false)       // M 
for MainActor
+    /// validate IBAN. No Networking
+    @MainActor    // M for MainActor
+    func validateIbanM(_ 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
     }
 
-    /// deposit coins. Networking involved
-    @MainActor
-    func prepareDepositM(_ depositPaytoUri: String, amount: Amount, 
viewHandles: Bool = false)       // M for MainActor
-      async throws -> PrepareDepositResult {
-          let request = PrepareDeposit(depositPaytoUri: depositPaytoUri, 
amount: amount)
+    /// check fees for deposit. No Networking
+    @MainActor    // M for MainActor
+    func checkDepositM(_ depositPaytoUri: String, amount: Amount, 
cancellationId: String? = nil, viewHandles: Bool = false)
+      async throws -> CheckDepositResult {
+          let request = CheckDeposit(depositPaytoUri: depositPaytoUri, amount: 
amount, cancellationId: cancellationId)
           let response = try await sendRequest(request, ASYNCDELAY, 
viewHandles: viewHandles)
           return response
     }
 
-    @MainActor
-    func createDepositGroupM(_ depositPaytoUri: String, amount: Amount, 
viewHandles: Bool = false)  // M for MainActor
+    /// deposit coins. Networking involved
+    @MainActor          // M for MainActor
+    func createDepositGroupM(_ 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/Banking/DepositAmountV.swift 
b/TalerWallet1/Views/Banking/DepositAmountV.swift
index f4567bd..524a3bd 100644
--- a/TalerWallet1/Views/Banking/DepositAmountV.swift
+++ b/TalerWallet1/Views/Banking/DepositAmountV.swift
@@ -28,7 +28,7 @@ struct DepositAmountV: View {
     @Environment(\.colorSchemeContrast) private var colorSchemeContrast
     @AppStorage("minimalistic") var minimalistic: Bool = false
 
-    @State var prepareDepositResult: PrepareDepositResult? = nil
+    @State var checkDepositResult: CheckDepositResult? = nil
     @State private var insufficient = false
     @State private var feeAmount: Amount? = nil
     @State private var feeStr: String = EMPTYSTRING
@@ -36,7 +36,7 @@ struct DepositAmountV: View {
     @State private var amountShortcut = Amount.zero(currency: EMPTYSTRING)     
 // Update currency when used
     @State private var exchange: Exchange? = nil                               
 // wg. noFees
 
-    private func fee(ppCheck: PrepareDepositResult?) -> Amount? {
+    private func fee(ppCheck: CheckDepositResult?) -> Amount? {
         do {
             if let ppCheck {
                 // Outgoing: fee = effective - raw
@@ -54,7 +54,7 @@ struct DepositAmountV: View {
                 return nil      // this exchange never has fees
             }
         }
-        return prepareDepositResult != nil ? (!(feeAmount?.isZero ?? false))
+        return checkDepositResult != nil ? (!(feeAmount?.isZero ?? false))
                                     : false
     }
 
@@ -165,9 +165,9 @@ struct DepositAmountV: View {
                 if !insufficient {
                     if amountToTransfer.isZero {
                         feeStr = EMPTYSTRING
-                        prepareDepositResult = nil
+                        checkDepositResult = nil
                     } else if let paytoUri {
-                        if let ppCheck = try? await 
model.prepareDepositM(paytoUri, amount: amountToTransfer) {
+                        if let ppCheck = try? await 
model.checkDepositM(paytoUri, amount: amountToTransfer) {
                             if let feeAmount = fee(ppCheck: ppCheck) {
                                 feeStr = feeAmount.formatted(currencyInfo, 
isNegative: false)
                                 let feeLabel = feeLabel(feeStr)
@@ -176,9 +176,9 @@ struct DepositAmountV: View {
                                 feeStr = EMPTYSTRING
                                 announce(amountVoiceOver)
                             }
-                            prepareDepositResult = ppCheck
+                            checkDepositResult = ppCheck
                         } else {
-                            prepareDepositResult = nil
+                            checkDepositResult = nil
                         }
                     }
                 }

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]