gnunet-svn
[Top][All Lists]
Advanced

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

[taler-taler-ios] 24/204: @State ScopeInfo.zero


From: gnunet
Subject: [taler-taler-ios] 24/204: @State ScopeInfo.zero
Date: Thu, 05 Dec 2024 23:49:52 +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 5f4c6a0e59f3b1fcac79c04df1259c9d556c8b83
Author: Marc Stibane <marc@taler.net>
AuthorDate: Sun Sep 29 16:42:36 2024 +0200

    @State ScopeInfo.zero
---
 TalerWallet1/Backend/WalletBackendRequest.swift    |   3 +
 .../Views/Actions/Peer2peer/SendAmountV.swift      | 103 ++++++++++-----------
 TalerWallet1/Views/Main/MainView.swift             |   1 -
 3 files changed, 54 insertions(+), 53 deletions(-)

diff --git a/TalerWallet1/Backend/WalletBackendRequest.swift 
b/TalerWallet1/Backend/WalletBackendRequest.swift
index 16b5298..4d68b65 100644
--- a/TalerWallet1/Backend/WalletBackendRequest.swift
+++ b/TalerWallet1/Backend/WalletBackendRequest.swift
@@ -36,6 +36,9 @@ struct ScopeInfo: Codable, Hashable {
     var url: String?            // only for "exchange" and "auditor"
     var currency: String        // 3-char ISO 4217 code for global currency. 
Regional MUST be >= 4 letters
 
+    public static func zero() -> ScopeInfo {
+        ScopeInfo(type: .madeUp, currency: UNKNOWN)
+    }
     public static func < (lhs: ScopeInfo, rhs: ScopeInfo) -> Bool {
         if lhs.type == .global {
             if rhs.type == .global {        // both global ==> alphabetic 
currency
diff --git a/TalerWallet1/Views/Actions/Peer2peer/SendAmountV.swift 
b/TalerWallet1/Views/Actions/Peer2peer/SendAmountV.swift
index 3d7d0b0..f1e582e 100644
--- a/TalerWallet1/Views/Actions/Peer2peer/SendAmountV.swift
+++ b/TalerWallet1/Views/Actions/Peer2peer/SendAmountV.swift
@@ -17,12 +17,11 @@ struct SendAmountV: View {
     @Binding var selectedBalance: Balance?      // selected balance when the 
action button is tapped in Transactions
     @Binding var amountToTransfer: Amount
     @Binding var summary: String
-    let scopeInfo: ScopeInfo
     let cameraAction: () -> Void
 
     @State private var balanceIndex = 0
     @State private var nonZeroBalances: [Balance] = []
-    @State private var balance: Balance? = nil
+    @State private var balance: Balance? = nil      // nil only when (balances 
/ nonZeroBalances) == []
 
     var body: some View {
 #if PRINT_CHANGES
@@ -52,7 +51,6 @@ struct SendAmountV: View {
                        balanceIndex: $balanceIndex,
                    amountToTransfer: $amountToTransfer,
                             summary: $summary,
-                          scopeInfo: scopeInfo,
                        cameraAction: cameraAction)
         } // ScrollView
             
.background(WalletColors().backgroundColor.edgesIgnoringSafeArea(.all))
@@ -89,7 +87,6 @@ struct SendAmountContent: View {
     @Binding var balanceIndex: Int
     @Binding var amountToTransfer: Amount
     @Binding var summary: String
-    let scopeInfo: ScopeInfo
     let cameraAction: () -> Void
 
     // TODO: call getMaxPeerPushDebitAmountM
@@ -114,6 +111,7 @@ struct SendAmountContent: View {
     @State private var currencyInfo = CurrencyInfo.zero(UNKNOWN)
     @State private var currencyName = UNKNOWN
     @State private var currencySymbol = UNKNOWN
+    @State private var scopeInfo: ScopeInfo = ScopeInfo.zero()
 
     private func shortcutAction(_ shortcut: Amount) {
         amountShortcut = shortcut
@@ -197,53 +195,55 @@ struct SendAmountContent: View {
         let navTitle = String(localized: "NavTitle_Send",
                            defaultValue: "Send",
                                 comment: "NavTitle: Send")
-        let availableStr = amountAvailable.formatted(currencyInfo, isNegative: 
false)
-        let amountVoiceOver = amountToTransfer.formatted(currencyInfo, 
isNegative: false)
-        let insufficientLabel2 = String(localized: "but you only have 
\(availableStr) to send.")
-
-        let inputDestination = LazyView {
-            P2PSubjectV(stack: stack.push(),
-                        scope: scopeInfo,
-                 currencyInfo: $currencyInfo,
-                     feeLabel: feeLabel(feeStr),
-                 feeIsNotZero: feeIsNotZero(),
-                     outgoing: true,
-             amountToTransfer: $amountToTransfer,       // from the textedit
-                      summary: $summary,
-                   expireDays: $expireDays)
-        }
-        let shortcutDestination = LazyView {
-            P2PSubjectV(stack: stack.push(),
-                        scope: scopeInfo,
-                 currencyInfo: $currencyInfo,
-                     feeLabel: nil,
-                 feeIsNotZero: feeIsNotZero(),
-                     outgoing: true,
-             amountToTransfer: $amountShortcut,         // from the tapped 
shortcut button
-                      summary: $summary,
-                   expireDays: $expireDays)
-        }
-
         Group {
-            let amountLabel = minimalistic ? String(localized: "Amount:")
-                                           : String(localized: "Amount to 
send:")
-            AmountInputV(stack: stack.push(),
-                  currencyInfo: $currencyInfo,
-               amountAvailable: $amountAvailable,
-                   amountLabel: amountLabel,
-              amountToTransfer: $amountToTransfer,
-                       wireFee: nil,
-                       summary: $summary,
-                shortcutAction: shortcutAction,
-                  buttonAction: buttonAction,
-                 feeIsNegative: false,
-                    computeFee: computeFeeSend)
-            .background(NavigationLink(destination: shortcutDestination, 
isActive: $shortcutSelected)
-                        { EmptyView() }.frame(width: 0).opacity(0).hidden()
-            ) // shortcutDestination
-            .background(NavigationLink(destination: inputDestination, 
isActive: $buttonSelected)
-                        { EmptyView() }.frame(width: 0).opacity(0).hidden()
-            ) // inputDestination
+            if let balance {
+                let scopeInfo = balance.scopeInfo
+                let availableStr = amountAvailable.formatted(currencyInfo, 
isNegative: false)
+                let amountVoiceOver = amountToTransfer.formatted(currencyInfo, 
isNegative: false)
+                let insufficientLabel2 = String(localized: "but you only have 
\(availableStr) to send.")
+
+                let inputDestination = P2PSubjectV(stack: stack.push(),
+                                                   scope: scopeInfo,
+                                            currencyInfo: $currencyInfo,
+                                                feeLabel: feeLabel(feeStr),
+                                            feeIsNotZero: feeIsNotZero(),
+                                                outgoing: true,
+                                        amountToTransfer: $amountToTransfer,   
 // from the textedit
+                                                 summary: $summary,
+                                              expireDays: $expireDays)
+                let shortcutDestination = P2PSubjectV(stack: stack.push(),
+                                                      scope: scopeInfo,
+                                               currencyInfo: $currencyInfo,
+                                                   feeLabel: nil,
+                                               feeIsNotZero: feeIsNotZero(),
+                                                   outgoing: true,
+                                           amountToTransfer: $amountShortcut,  
 // from the tapped shortcut button
+                                                    summary: $summary,
+                                                 expireDays: $expireDays)
+                Group {
+                    let amountLabel = minimalistic ? String(localized: 
"Amount:")
+                                                   : String(localized: "Amount 
to send:")
+                    AmountInputV(stack: stack.push(),
+                          currencyInfo: $currencyInfo,
+                       amountAvailable: $amountAvailable,
+                           amountLabel: amountLabel,
+                      amountToTransfer: $amountToTransfer,
+                               wireFee: nil,
+                               summary: $summary,
+                        shortcutAction: shortcutAction,
+                          buttonAction: buttonAction,
+                         feeIsNegative: false,
+                            computeFee: computeFeeSend)
+                    .background(NavigationLink(destination: 
shortcutDestination, isActive: $shortcutSelected)
+                            { EmptyView() }.frame(width: 0).opacity(0).hidden()
+                        ) // shortcutDestination
+                    .background(NavigationLink(destination: inputDestination, 
isActive: $buttonSelected)
+                            { EmptyView() }.frame(width: 0).opacity(0).hidden()
+                        ) // inputDestination
+                }
+            } else {    // no balance - Yikes
+                Text("No balance. There seems to be a problem with the 
database...")
+            }
         }
         .frame(maxWidth: .infinity, alignment: .leading)
         .background(WalletColors().backgroundColor.edgesIgnoringSafeArea(.all))
@@ -268,7 +268,7 @@ struct SendAmountContent: View {
         .navigationBarItems(trailing: QRButton(action: cameraAction))
         .task(id: balanceIndex + (1000 * controller.currencyTicker)) {
             if let balance {
-                let scopeInfo = balance.scopeInfo
+                scopeInfo = balance.scopeInfo
                 let currency = scopeInfo.currency
                 amountAvailable = balance.available
                 amountToTransfer.setCurrency(currency)
@@ -348,7 +348,6 @@ fileprivate struct Preview_Content: View {
           selectedBalance: $noBalance,
          amountToTransfer: $amountToPreview,
                   summary: $summary,
-                scopeInfo: currencyInfo.scope,
              cameraAction: checkCameraAvailable)
     }
 }
diff --git a/TalerWallet1/Views/Main/MainView.swift 
b/TalerWallet1/Views/Main/MainView.swift
index 0686752..b389e87 100644
--- a/TalerWallet1/Views/Main/MainView.swift
+++ b/TalerWallet1/Views/Main/MainView.swift
@@ -326,7 +326,6 @@ extension MainView {
                              selectedBalance: $selectedBalance,             // 
if nil shows currency picker
                             amountToTransfer: $amountToTransfer,            // 
currency needs to be updated!
                                      summary: $summary,
-                                   scopeInfo: scope,
                                 cameraAction: cameraAction)
 
             let requestDest = RequestPayment(stack: 
stack.push("\(Self.className())()"),

-- 
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]