gnunet-svn
[Top][All Lists]
Advanced

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

[taler-taler-ios] 26/32: more scopeInfo


From: gnunet
Subject: [taler-taler-ios] 26/32: more scopeInfo
Date: Sat, 10 Feb 2024 15:04: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 17fca55f17f95105b3af14c11db866869f3ca427
Author: Marc Stibane <marc@taler.net>
AuthorDate: Thu Feb 8 18:33:42 2024 +0100

    more scopeInfo
---
 TalerWallet1/Model/Model+Transactions.swift        | 12 +--
 .../Views/Balances/BalancesSectionView.swift       | 16 ++--
 TalerWallet1/Views/Banking/ExchangeListView.swift  | 94 +++++++---------------
 .../Views/Banking/ExchangeSectionView.swift        | 20 +++--
 TalerWallet1/Views/HelperViews/BarGraph.swift      |  3 +-
 .../Views/Transactions/TransactionRowView.swift    |  9 ++-
 .../Views/Transactions/TransactionsListView.swift  | 12 +--
 7 files changed, 67 insertions(+), 99 deletions(-)

diff --git a/TalerWallet1/Model/Model+Transactions.swift 
b/TalerWallet1/Model/Model+Transactions.swift
index d6226cc..3b91b7a 100644
--- a/TalerWallet1/Model/Model+Transactions.swift
+++ b/TalerWallet1/Model/Model+Transactions.swift
@@ -26,12 +26,14 @@ extension WalletModel {
 fileprivate struct GetTransactions: WalletBackendFormattedRequest {
     func operation() -> String { "getTransactions" }
 //    func operation() -> String { "testingGetSampleTransactions" }
-    func args() -> Args { Args(currency: currency, search: search, sort: sort) 
}
+    func args() -> Args { Args(scopeInfo: scopeInfo, currency: currency, 
search: search, sort: sort) }
 
+    var scopeInfo: ScopeInfo?
     var currency: String?
     var search: String?
     var sort: String?
     struct Args: Encodable {
+        var scopeInfo: ScopeInfo?
         var currency: String?
         var search: String?
         var sort: String?
@@ -99,10 +101,10 @@ struct ResumeTransaction: WalletBackendFormattedRequest {
 // MARK: -
 extension WalletModel {
     /// ask wallet-core for its list of transactions filtered by searchString
-    func transactionsT(_ stack: CallStack, currency: String? = nil, 
searchString: String? = nil, sort: String = "descending")
+    func transactionsT(_ stack: CallStack, scopeInfo: ScopeInfo, searchString: 
String? = nil, sort: String = "descending")
     async -> [Transaction] {                                          // might 
be called from a background thread itself
         do {
-            let request = GetTransactions(currency: currency, search: 
searchString, sort: sort)
+            let request = GetTransactions(scopeInfo: scopeInfo, currency: 
scopeInfo.currency, search: searchString, sort: sort)
             let response = try await sendRequest(request, ASYNCDELAY)
             return response.transactions
         } catch {
@@ -110,9 +112,9 @@ extension WalletModel {
         }
     }
     /// fetch transactions from Wallet-Core. No networking involved
-    @MainActor func transactionsMA(_ stack: CallStack, currency: String? = 
nil, searchString: String? = nil, sort: String = "descending")
+    @MainActor func transactionsMA(_ stack: CallStack, scopeInfo: ScopeInfo, 
searchString: String? = nil, sort: String = "descending")
     async -> [Transaction] {    // M for MainActor
-        return await transactionsT(stack.push(), currency: currency, 
searchString: searchString, sort: sort)
+        return await transactionsT(stack.push(), scopeInfo: scopeInfo, 
searchString: searchString, sort: sort)
     }
 
     /// abort the specified transaction from Wallet-Core. No networking 
involved
diff --git a/TalerWallet1/Views/Balances/BalancesSectionView.swift 
b/TalerWallet1/Views/Balances/BalancesSectionView.swift
index 3292272..908f56d 100644
--- a/TalerWallet1/Views/Balances/BalancesSectionView.swift
+++ b/TalerWallet1/Views/Balances/BalancesSectionView.swift
@@ -41,14 +41,12 @@ struct BalancesSectionView {
     @State private var shownSectionID = UUID()  // guaranteed to be different 
the first time
 
     func reloadCompleted(_ stack: CallStack) async -> () {
-        let currency = balance.scopeInfo.currency
-        transactions = await model.transactionsT(stack.push(), currency: 
currency)
+        transactions = await model.transactionsT(stack.push(), scopeInfo: 
balance.scopeInfo)
         completedTransactions = WalletModel.completedTransactions(transactions)
     }
 
     func reloadPending(_ stack: CallStack) async -> () {
-        let currency = balance.scopeInfo.currency
-        transactions = await model.transactionsT(stack.push(), currency: 
currency)
+        transactions = await model.transactionsT(stack.push(), scopeInfo: 
balance.scopeInfo)
         pendingTransactions = WalletModel.pendingTransactions(transactions)
     }
 }
@@ -109,7 +107,7 @@ extension BalancesSectionView: View {
 //            if shownSectionID != sectionID {
                 symLog.log(".task for BalancesSectionView - reload 
Transactions")
             // TODO: only load the MAXRECENT most recent transactions
-                let response = await model.transactionsT(stack.push(".task - 
reload Transactions"), currency: currency)
+                let response = await model.transactionsT(stack.push(".task - 
reload Transactions"), scopeInfo: scopeInfo)
                 transactions = response
                 pendingTransactions = WalletModel.pendingTransactions(response)
                 completedTransactions = 
WalletModel.completedTransactions(response)
@@ -126,7 +124,7 @@ extension BalancesSectionView: View {
                 let threeTransactions = Array(slice)
                 TransactionsArraySliceV(symLog: symLog,
                                          stack: stack.push(),
-                                      currency: currency,
+                                     scopeInfo: scopeInfo,
                                   transactions: threeTransactions,
                                reloadOneAction: reloadOneAction)
                     .padding(.leading, ICONLEADING)
@@ -164,7 +162,7 @@ fileprivate struct BalancesPendingRowView: View {
             LazyView {
                 TransactionsListView(stack: stack.push(),
                                   navTitle: String(localized: "Pending", 
comment: "ViewTitle of TransactionList"),
-                                  currency: balance.scopeInfo.currency,
+                                 scopeInfo: balance.scopeInfo,
                               transactions: pendingTransactions,
                                 showUpDown: false,
                            reloadAllAction: reloadPending,
@@ -231,7 +229,7 @@ fileprivate struct BalancesNavigationLinksView: View {
     }
 
     var body: some View {
-        let currency = balance.scopeInfo.currency
+        let scopeInfo = balance.scopeInfo
         HStack(spacing: 0) {
             NavigationLink(destination: LazyView {
                 SendAmount(stack: stack.push(),
@@ -251,7 +249,7 @@ fileprivate struct BalancesNavigationLinksView: View {
             let balanceDest = LazyView {
                 TransactionsListView(stack: stack.push(),
                                   navTitle: String(localized: "Transactions", 
comment: "ViewTitle of TransactionList"),
-                                  currency: currency,
+                                 scopeInfo: scopeInfo,
                               transactions: completedTransactions,
                                 showUpDown: true,
                            reloadAllAction: reloadAllAction,
diff --git a/TalerWallet1/Views/Banking/ExchangeListView.swift 
b/TalerWallet1/Views/Banking/ExchangeListView.swift
index 718291f..bb776d2 100644
--- a/TalerWallet1/Views/Banking/ExchangeListView.swift
+++ b/TalerWallet1/Views/Banking/ExchangeListView.swift
@@ -64,13 +64,14 @@ struct ExchangeListView: View {
         }
     }
 }
-
-struct ExchangeListCommonV: View {
+// MARK: -
+struct ExchangeListCommonV {
     let symLog: SymLogV?
     let stack: CallStack
     @Binding var balances: [Balance]
 
     @EnvironmentObject private var model: WalletModel
+    @AppStorage("myListStyle") var myListStyle: MyListStyle = .automatic
 
     @State private var exchanges: [Exchange] = []
 
@@ -81,82 +82,45 @@ struct ExchangeListCommonV: View {
         exchanges = await model.listExchangesM()
     }
 
+}
+// MARK: -
+extension ExchangeListCommonV: View {
     var body: some View {
 #if PRINT_CHANGES
         let _ = Self._printChanges()
         let _ = symLog?.vlog()       // just to get the # to compare it with 
.onAppear & onDisappear
 #endif
-        //Text("Exchanges...")
-        Content(symLog: symLog,
-                 stack: stack.push(),
-              balances: $balances,
-             exchanges: $exchanges,
-      amountToTransfer: $amountToTransfer,
-       reloadExchanges: reloadExchanges)
+        let sortedExchanges = exchanges.sorted { $0 < $1 }
+        // TODO: Balances for amountAvailable for Deposit
+        Group {
+            List(sortedExchanges, id: \.self) { exchange in
+                ExchangeSectionView(stack: stack.push(),
+                                 exchange: exchange,
+                         amountToTransfer: $amountToTransfer)               // 
does still have the wrong currency
+            }
+            .refreshable {
+                symLog?.log("refreshing")
+                await reloadExchanges()
+            }
+            .listStyle(myListStyle.style).anyView
+        }
+        .onAppear() {
+            DebugViewC.shared.setViewID(VIEW_EXCHANGES, stack: stack.push())
+        }
         .overlay {
             if exchanges.isEmpty {
                 Text("No Exchanges yet...")
                     .accessibilityFont(.body)
             }
         }
+        .onNotification(.ExchangeAdded) { notification in
+            // doesn't need to be received on main thread because we just 
reload in the background anyway
+            symLog?.log(".onNotification(.ExchangeAdded) ==> reloading 
exchanges")
+            Task { await reloadExchanges() } // runs on MainActor
+        }
         .task {
             symLog?.log(".task")
             await reloadExchanges()
         }
-    }
-}
-// MARK: -
-extension ExchangeListCommonV {
-    struct Content: View {
-        let symLog: SymLogV?
-        let stack: CallStack
-        @AppStorage("myListStyle") var myListStyle: MyListStyle = .automatic
-        @Binding var balances: [Balance]
-        @Binding var exchanges: [Exchange]
-        @Binding var amountToTransfer: Amount           // does still have the 
wrong currency
-        var reloadExchanges: () async -> Void
-
-        func currenciesDict(_ exchanges: [Exchange]) -> [String : [Exchange]] {
-            var currencies: [String : [Exchange]] = [:]
-
-            for exchange in exchanges {
-                let currency = exchange.scopeInfo?.currency
-                            ?? exchange.currency ?? "Unknown"
-                if currencies[currency] != nil {
-                    currencies[currency]!.append(exchange)
-                } else {
-                    currencies[currency] = [exchange]
-                }
-            }
-            return currencies
-        }
-
-//        @State private var exchangeAmount: ExchangeAmount? = nil
-
-        var body: some View {
-            let dict = currenciesDict(exchanges)
-            // TODO: Balances for amountAvailable for Deposit
-            let sortedDict = dict.sorted{ $0.key < $1.key}
-            Group { // necessary for .backslide transition (bug in SwiftUI)
-                List(sortedDict, id: \.key) { key, value in
-                    ExchangeSectionView(stack: stack.push(),
-                                     currency: key, exchanges: value,
-                             amountToTransfer: $amountToTransfer)              
 // does still have the wrong currency
-                }
-                .refreshable {
-                    symLog?.log("refreshing")
-                    await reloadExchanges()
-                }
-                .listStyle(myListStyle.style).anyView
-            }
-            .onAppear() {
-                DebugViewC.shared.setViewID(VIEW_EXCHANGES, stack: 
stack.push())
-            }
-            .onNotification(.ExchangeAdded) { notification in
-                // doesn't need to be received on main thread because we just 
reload in the background anyway
-                symLog?.log(".onNotification(.ExchangeAdded) ==> reloading 
exchanges")
-                Task { await reloadExchanges() } // runs on MainActor
-            }
-        } // body
-    }
+    } // body
 }
diff --git a/TalerWallet1/Views/Banking/ExchangeSectionView.swift 
b/TalerWallet1/Views/Banking/ExchangeSectionView.swift
index e6b59c7..158e4c7 100644
--- a/TalerWallet1/Views/Banking/ExchangeSectionView.swift
+++ b/TalerWallet1/Views/Banking/ExchangeSectionView.swift
@@ -10,8 +10,8 @@ import taler_swift
 /// [Deposit Coins]  [Withdraw Coins]
 struct ExchangeSectionView: View {
     let stack: CallStack
-    let currency: String                        // this is the currency to be 
used
-    let exchanges: [Exchange]
+    let exchange: Exchange
+//    let exchanges: [Exchange]
     @Binding var amountToTransfer: Amount       // does still have the wrong 
currency
     @EnvironmentObject private var controller: Controller
     @AppStorage("minimalistic") var minimalistic: Bool = false
@@ -22,16 +22,18 @@ struct ExchangeSectionView: View {
         let _ = Self._printChanges()
 //        let _ = symLog.vlog()       // just to get the # to compare it with 
.onAppear & onDisappear
 #endif
+        let scopeInfo = exchange.scopeInfo
+        let currency = scopeInfo?.currency ?? exchange.currency ?? "unknown"
         let currencyInfo = controller.info(for: currency)
         let currencyName = currencyInfo?.scope.currency ?? currency
         Section {
-            ForEach(exchanges) { exchange in
+//            ForEach(exchanges) { exchange in
                 ExchangeRowView(stack: stack.push(),
                              exchange: exchange,
                              currency: currencyName,        // TODO: 
(balance.available) amount.isZero to disable Deposit-button
                      amountToTransfer: $amountToTransfer)   // does still have 
the wrong currency
                 .listRowSeparator(.hidden)
-            }
+//            }
             if "KUDOS" == currency {
                 let bankingHint = String(localized: "Since the demo bank 
supports the Taler integration, you can start a withdrawal directly on the")
                 let linkTitle = String(localized: "LinkTitle_DEMOBANK", 
defaultValue: "Demo Bank Website")
@@ -47,7 +49,7 @@ struct ExchangeSectionView: View {
                 .padding(.top)
             }
         } header: {
-            BarGraphHeader(stack: stack.push(), scopeInfo: nil, currencyName: 
currencyName,
+            BarGraphHeader(stack: stack.push(), scopeInfo: scopeInfo, 
currencyName: currencyName,
                            shouldReloadBalances: $shouldReloadBalances)
         }
     }
@@ -75,9 +77,11 @@ fileprivate struct ExchangeRow_Container : View {
                              exchangeEntryStatus: .ephemeral,
                             exchangeUpdateStatus: .ready,
                            ageRestrictionOptions: [])
-        ExchangeSectionView(stack: CallStack("Preview"), currency: 
LONGCURRENCY,
-                            exchanges: [exchange1, exchange2],
-                            amountToTransfer: $amountToPreview)
+        ExchangeSectionView(stack: CallStack("Preview"),
+//                        scopeInfo: scopeInfo,
+                         exchange: exchange1,
+//                        exchanges: [exchange1, exchange2],
+                 amountToTransfer: $amountToPreview)
     }
 }
 
diff --git a/TalerWallet1/Views/HelperViews/BarGraph.swift 
b/TalerWallet1/Views/HelperViews/BarGraph.swift
index 9221d4a..e2f4d99 100644
--- a/TalerWallet1/Views/HelperViews/BarGraph.swift
+++ b/TalerWallet1/Views/HelperViews/BarGraph.swift
@@ -35,8 +35,7 @@ struct BarGraphHeader: View {
                 symLog.log(".task for BarGraphHeader(\(scopeInfo.currency)) - 
reload Transactions")
                 // TODO: only load the 10 most recent transactions
                 let response = await model.transactionsT(stack.push(".task - 
reload Transactions for \(scopeInfo.currency)"),
-//                                                         scopeInfo: 
scopeInfo)
-                                                         currency: 
scopeInfo.currency)
+                                                         scopeInfo: scopeInfo)
                 completedTransactions = 
WalletModel.completedTransactions(response)
             }
         }
diff --git a/TalerWallet1/Views/Transactions/TransactionRowView.swift 
b/TalerWallet1/Views/Transactions/TransactionRowView.swift
index 3b7042e..d3b6f65 100644
--- a/TalerWallet1/Views/Transactions/TransactionRowView.swift
+++ b/TalerWallet1/Views/Transactions/TransactionRowView.swift
@@ -38,7 +38,6 @@ struct IconBadge: View {
 
 struct TransactionRowView: View {
     let transaction : Transaction
-    let currency: String
 
     @Environment(\.sizeCategory) var sizeCategory
     @Environment(\.colorSchemeContrast) private var colorSchemeContrast
@@ -172,8 +171,8 @@ struct TransactionRow_Previews: PreviewProvider {
                                          time: Timestamp(from: 
1_666_666_000_000))
     static var previews: some View {
         List {
-            TransactionRowView(transaction: withdrawal, currency: TESTCURRENCY)
-            TransactionRowView(transaction: payment, currency: DEMOCURRENCY)
+            TransactionRowView(transaction: withdrawal)
+            TransactionRowView(transaction: payment)
         }
     }
 }
@@ -209,7 +208,9 @@ extension Transaction {             // for PreViews
             let pDetails = PaymentTransactionDetails(info: info,
                                                proposalId: "some proposal ID",
                                            totalRefundRaw: Amount(currency: 
LONGCURRENCY, cent: 300),
-                                     totalRefundEffective: Amount(currency: 
LONGCURRENCY, cent: 280))
+                                     totalRefundEffective: Amount(currency: 
LONGCURRENCY, cent: 280),
+                                                  refunds: [],
+                                        refundQueryActive: false)
             self = .payment(PaymentTransaction(common: common, details: 
pDetails))
         }
     }
diff --git a/TalerWallet1/Views/Transactions/TransactionsListView.swift 
b/TalerWallet1/Views/Transactions/TransactionsListView.swift
index 9a61683..9944327 100644
--- a/TalerWallet1/Views/Transactions/TransactionsListView.swift
+++ b/TalerWallet1/Views/Transactions/TransactionsListView.swift
@@ -11,7 +11,7 @@ struct TransactionsListView: View {
     @AppStorage("myListStyle") var myListStyle: MyListStyle = .automatic
     let navTitle: String
 
-    let currency: String
+    let scopeInfo: ScopeInfo
     let transactions: [Transaction]
     let showUpDown: Bool
     let reloadAllAction: (_ stack: CallStack) async -> ()
@@ -30,9 +30,10 @@ struct TransactionsListView: View {
             List {
                 TransactionsArraySliceV(symLog: symLog,
                                          stack: stack.push(),
-                                      currency: currency,
+                                     scopeInfo: scopeInfo,
                                   transactions: transactions,
                                reloadOneAction: reloadOneAction)
+                    .padding(.leading, ICONLEADING)
             }
             .id(viewId)
             .listStyle(myListStyle.style).anyView
@@ -68,7 +69,7 @@ struct TransactionsListView: View {
         }
         .overlay {
             if transactions.isEmpty {
-                TransactionsEmptyView(stack: stack.push(), currency: currency)
+                TransactionsEmptyView(stack: stack.push(), currency: 
scopeInfo.currency)
             }
         }
         .onAppear {
@@ -81,7 +82,7 @@ struct TransactionsListView: View {
 struct TransactionsArraySliceV: View {
     let symLog: SymLogV?
     let stack: CallStack
-    let currency: String
+    let scopeInfo: ScopeInfo
     let transactions: [Transaction]
     let reloadOneAction: ((_ transactionId: String) async throws -> 
Transaction)
 
@@ -111,8 +112,7 @@ struct TransactionsArraySliceV: View {
                                    resumeAction: resumeAction)
                 }
             } label: {
-                TransactionRowView(transaction: transaction,
-                                      currency: currency)
+                TransactionRowView(transaction: transaction)
             }
             .id(Int(index))
         }

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