gnunet-svn
[Top][All Lists]
Advanced

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

[taler-taler-ios] 73/204: Published balances


From: gnunet
Subject: [taler-taler-ios] 73/204: Published balances
Date: Thu, 05 Dec 2024 23:50:41 +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 3d5f38bfb93fe0bca0078706dc3566a82ab36fd4
Author: Marc Stibane <marc@taler.net>
AuthorDate: Fri Oct 18 11:41:28 2024 +0200

    Published balances
---
 TalerWallet1/Controllers/Controller.swift          | 18 +++++++++
 TalerWallet1/Controllers/PublicConstants.swift     |  1 -
 TalerWallet1/Model/Model+Balances.swift            | 19 +++++----
 TalerWallet1/Model/WalletModel.swift               |  1 -
 TalerWallet1/Views/Actions/ActionsSheet.swift      | 13 ++-----
 .../Views/Actions/Banking/DepositIbanV.swift       |  1 -
 .../Views/Actions/Banking/ManualWithdraw.swift     |  1 -
 .../Views/Actions/Peer2peer/RequestPayment.swift   | 12 +++---
 .../Views/Actions/Peer2peer/SendAmountV.swift      | 19 +++++----
 TalerWallet1/Views/Balances/BalancesListView.swift | 35 ++---------------
 TalerWallet1/Views/HelperViews/ScopePicker.swift   | 31 +++++++--------
 TalerWallet1/Views/Main/MainView.swift             | 23 ++---------
 .../Views/Settings/Exchange/ExchangeListView.swift |  7 +---
 .../Settings/Exchange/ExchangeSectionView.swift    | 45 ----------------------
 TalerWallet1/Views/Settings/SettingsView.swift     |  2 -
 TalerWallet1/Views/Sheets/QRSheet.swift            |  2 -
 TalerWallet1/Views/Sheets/URLSheet.swift           |  2 -
 TalerWallet1/Views/Sheets/WithdrawExchangeV.swift  |  2 -
 18 files changed, 73 insertions(+), 161 deletions(-)

diff --git a/TalerWallet1/Controllers/Controller.swift 
b/TalerWallet1/Controllers/Controller.swift
index 8f708c0..026b8d4 100755
--- a/TalerWallet1/Controllers/Controller.swift
+++ b/TalerWallet1/Controllers/Controller.swift
@@ -49,6 +49,8 @@ class Controller: ObservableObject {
     public static let shared = Controller()
     private let symLog = SymLogC()
 
+    @Published var balances: [Balance] = []
+
     @Published var backendState: BackendState = .none       // only used for 
launch animation
     @Published var currencyTicker: Int = 0                  // updates 
whenever a new currency is added
     @Published var isConnected: Bool = true
@@ -111,8 +113,24 @@ class Controller: ObservableObject {
         currencyTicker = 0
         currencyInfos = []
         exchanges = []
+        balances = []
 //        checkInternetConnection()
     }
+// MARK: -
+    /// runs on MainActor if called in some Task {}
+    @discardableResult
+    func loadBalances(_ stack: CallStack,_ model: WalletModel) async -> Int? {
+        if let reloaded = try? await model.balancesM(stack.push()) {
+            for balance in reloaded {
+                let scope = balance.scopeInfo
+                checkInfo(for: scope, model: model)
+            }
+            balances = reloaded         // redraw
+            return reloaded.count
+        }
+        return nil
+    }
+
 // MARK: -
     func exchange(for baseUrl: String) -> Exchange? {
         for exchange in exchanges {
diff --git a/TalerWallet1/Controllers/PublicConstants.swift 
b/TalerWallet1/Controllers/PublicConstants.swift
index e185bc8..8a7873c 100644
--- a/TalerWallet1/Controllers/PublicConstants.swift
+++ b/TalerWallet1/Controllers/PublicConstants.swift
@@ -150,7 +150,6 @@ extension Notification.Name {
 
 /// Notifications for internal synchronization
 extension Notification.Name {
-    static let BalanceReloaded = Notification.Name("balanceReloaded")
     static let SendAction = Notification.Name("sendAction")
     static let RequestAction = Notification.Name("requestAction")
     static let DepositAction = Notification.Name("depositAction")
diff --git a/TalerWallet1/Model/Model+Balances.swift 
b/TalerWallet1/Model/Model+Balances.swift
index 461183e..42beaf7 100644
--- a/TalerWallet1/Model/Model+Balances.swift
+++ b/TalerWallet1/Model/Model+Balances.swift
@@ -45,6 +45,14 @@ extension Balance {
             !balance.available.isZero
         }
     }
+    static func firstNonZero(_ balances: [Balance]) -> Balance? {
+        for balance in balances {
+            if !balance.available.isZero {
+                return balance
+            }
+        }
+        return nil
+    }
 }
 // MARK: -
 /// A request to get the balances held in the wallet.
@@ -65,13 +73,8 @@ extension WalletModel {
       async throws -> [Balance] {          // M for MainActor
         await semaphore.wait()
         defer { semaphore.signal() }
-        if cachedBalances == nil {
-            let request = Balances()
-            let response = try await sendRequest(request, ASYNCDELAY, 
viewHandles: viewHandles)
-            cachedBalances = response.balances
-        } else {
-            logger.trace("returning cached Balances")
-        }
-        return cachedBalances ?? []
+        let request = Balances()
+        let response = try await sendRequest(request, ASYNCDELAY, viewHandles: 
viewHandles)
+        return response.balances
     }
 }
diff --git a/TalerWallet1/Model/WalletModel.swift 
b/TalerWallet1/Model/WalletModel.swift
index 181ff7d..88b0c6c 100644
--- a/TalerWallet1/Model/WalletModel.swift
+++ b/TalerWallet1/Model/WalletModel.swift
@@ -25,7 +25,6 @@ class WalletModel: ObservableObject {
     public static let shared = WalletModel()
     let logger = Logger(subsystem: "net.taler.gnu", category: "WalletModel")
     let semaphore = AsyncSemaphore(value: 1)
-    var cachedBalances: [Balance]? = nil
 
     @Published var showError: Bool = false
     @Published var error2: ErrorData? = nil
diff --git a/TalerWallet1/Views/Actions/ActionsSheet.swift 
b/TalerWallet1/Views/Actions/ActionsSheet.swift
index 83af1c7..1a51a32 100644
--- a/TalerWallet1/Views/Actions/ActionsSheet.swift
+++ b/TalerWallet1/Views/Actions/ActionsSheet.swift
@@ -16,14 +16,14 @@ import taler_swift
 ///        [􀎻  Scan QR ]
 struct ActionsSheet: View {
     let stack: CallStack
-    @Binding var balances: [Balance]
     @Binding var qrButtonTapped: Bool
 
     @AppStorage("minimalistic") var minimalistic: Bool = false
     @AppStorage("hideSpendingHint") var hideSpendingHint: Bool = false
+    @EnvironmentObject private var controller: Controller
 
     private var hasKudos: Bool {
-        for balance in balances {
+        for balance in controller.balances {
             if balance.scopeInfo.currency == DEMOCURRENCY {
                 if !balance.available.isZero {
                     return true
@@ -33,7 +33,7 @@ struct ActionsSheet: View {
         return false
     }
     private var canSend: Bool {     // canDeposit
-        for balance in balances {
+        for balance in controller.balances {
             if !balance.available.isZero {
                 return true
             }
@@ -92,7 +92,6 @@ struct ActionsSheet: View {
 @available(iOS 16.4, *)
 struct DualHeightSheet: View {
     let stack: CallStack
-    @Binding var balances: [Balance]
     @Binding var qrButtonTapped: Bool
 
     let logger = Logger(subsystem: "net.taler.gnu", category: "DualSheet")
@@ -117,7 +116,6 @@ struct DualHeightSheet: View {
     var body: some View {
         ScrollView {
             ActionsSheet(stack: stack.push(),
-                      balances: $balances,
                 qrButtonTapped: $qrButtonTapped2)
             .presentationDragIndicator(.hidden)
             .presentationBackground {
@@ -172,8 +170,3 @@ struct DualHeightSheet: View {
         .frame(maxHeight: innerHeight)
     }
 }
-// MARK: -
-//#Preview {
-//    @Previewable @State var balances: [Balance] = []
-//    Actions(stack: CallStack("Preview"), balances: $balances, ...)
-//}
diff --git a/TalerWallet1/Views/Actions/Banking/DepositIbanV.swift 
b/TalerWallet1/Views/Actions/Banking/DepositIbanV.swift
index bd74f2b..a41358c 100644
--- a/TalerWallet1/Views/Actions/Banking/DepositIbanV.swift
+++ b/TalerWallet1/Views/Actions/Banking/DepositIbanV.swift
@@ -13,7 +13,6 @@ import SymLog
 struct DepositIbanV: View {
     private let symLog = SymLogV(0)
     let stack: CallStack
-    let balances: [Balance]
     @Binding var selectedBalance: Balance?
 //    @Binding var currencyInfo: CurrencyInfo
     let feeLabel: String?
diff --git a/TalerWallet1/Views/Actions/Banking/ManualWithdraw.swift 
b/TalerWallet1/Views/Actions/Banking/ManualWithdraw.swift
index 206368e..476886a 100644
--- a/TalerWallet1/Views/Actions/Banking/ManualWithdraw.swift
+++ b/TalerWallet1/Views/Actions/Banking/ManualWithdraw.swift
@@ -14,7 +14,6 @@ import SymLog
 struct ManualWithdraw: View {
     private let symLog = SymLogV(0)
     let stack: CallStack
-    let balances: [Balance]
     @Binding var selectedBalance: Balance?
 //    @Binding var currencyInfo: CurrencyInfo
     let isSheet: Bool
diff --git a/TalerWallet1/Views/Actions/Peer2peer/RequestPayment.swift 
b/TalerWallet1/Views/Actions/Peer2peer/RequestPayment.swift
index 309bc2f..2c20fd6 100644
--- a/TalerWallet1/Views/Actions/Peer2peer/RequestPayment.swift
+++ b/TalerWallet1/Views/Actions/Peer2peer/RequestPayment.swift
@@ -13,11 +13,12 @@ import SymLog
 struct RequestPayment: View {
     private let symLog = SymLogV(0)
     let stack: CallStack
-    let balances: [Balance]
     @Binding var selectedBalance: Balance?
     @Binding var amountLastUsed: Amount
     @Binding var summary: String
 
+    @EnvironmentObject private var controller: Controller
+
     @State private var balanceIndex = 0
     @State private var balance: Balance? = nil      // nil only when balances 
== []
 
@@ -25,15 +26,14 @@ struct RequestPayment: View {
 #if PRINT_CHANGES
         let _ = Self._printChanges()
 #endif
-        let count = balances.count
+        let count = controller.balances.count
         let _ = symLog.log("count = \(count)")
         let scrollView = ScrollView {
             if count > 0 {
                 ScopePicker(value: $balanceIndex,
-                         balances: balances,
                       onlyNonZero: false) { index in
                         balanceIndex = index
-                        balance = balances[index]
+                        balance = controller.balances[index]
                 }
                 .padding(.horizontal)
                 .padding(.bottom, 4)
@@ -48,10 +48,10 @@ struct RequestPayment: View {
             .task {
                 if let selectedBalance {
                     balance = selectedBalance
-                    balanceIndex = balances.firstIndex(of: selectedBalance) ?? 0
+                    balanceIndex = controller.balances.firstIndex(of: 
selectedBalance) ?? 0
                 } else {
                     balanceIndex = 0
-                    balance = (count > 0) ? balances[0] : nil
+                    balance = (count > 0) ? controller.balances[0] : nil
                 }
             }
 
diff --git a/TalerWallet1/Views/Actions/Peer2peer/SendAmountV.swift 
b/TalerWallet1/Views/Actions/Peer2peer/SendAmountV.swift
index c4ae146..715e410 100644
--- a/TalerWallet1/Views/Actions/Peer2peer/SendAmountV.swift
+++ b/TalerWallet1/Views/Actions/Peer2peer/SendAmountV.swift
@@ -13,16 +13,17 @@ import SymLog
 struct SendAmountV: View {
     private let symLog = SymLogV(0)
     let stack: CallStack
-    let balances: [Balance]
     @Binding var selectedBalance: Balance?
     @Binding var amountLastUsed: Amount
     @Binding var summary: String
 
+    @EnvironmentObject private var controller: Controller
+
     @State private var balanceIndex = 0
     @State private var balance: Balance? = nil      // nil only when balances 
== []
 
     func firstNonZero() -> Balance? {
-        for aBalance in balances {
+        for aBalance in controller.balances {
             if !aBalance.available.isZero {
                 return aBalance
             }
@@ -34,15 +35,14 @@ struct SendAmountV: View {
 #if PRINT_CHANGES
         let _ = Self._printChanges()
 #endif
-        let count = balances.count
+        let count = controller.balances.count
         let _ = symLog.log("count = \(count)")
         let scrollView = ScrollView {
             if count > 0 {
                 ScopePicker(value: $balanceIndex,
-                         balances: balances,
                       onlyNonZero: true) { index in
                     balanceIndex = index
-                    balance = balances[index]
+                    balance = controller.balances[index]
                 }
                 .padding(.horizontal)
                 .padding(.bottom, 4)
@@ -58,18 +58,18 @@ struct SendAmountV: View {
                 if let selectedBalance {
                     if selectedBalance.available.isZero {
                         // find another balance
-                        balance = firstNonZero()
+                        balance = Balance.firstNonZero(controller.balances)
                     } else {
                         balance = selectedBalance
                     }
                 } else {
-                    balance = firstNonZero()
+                    balance = Balance.firstNonZero(controller.balances)
                 }
                 if let balance {
-                    balanceIndex = balances.firstIndex(of: balance) ?? 0
+                    balanceIndex = controller.balances.firstIndex(of: balance) 
?? 0
                 } else {
                     balanceIndex = 0
-                    balance = (count > 0) ? balances[0] : nil
+                    balance = (count > 0) ? controller.balances[0] : nil
                 }
             }
 
@@ -348,7 +348,6 @@ fileprivate struct Preview_Content: View {
                         pendingOutgoing: pending,
                                   flags: [])
         SendAmountV(stack: CallStack("Preview"),
-                 balances: [balance],
           selectedBalance: $noBalance,
            amountLastUsed: $amountToPreview,
                   summary: $summary)
diff --git a/TalerWallet1/Views/Balances/BalancesListView.swift 
b/TalerWallet1/Views/Balances/BalancesListView.swift
index 637acb0..0ace005 100644
--- a/TalerWallet1/Views/Balances/BalancesListView.swift
+++ b/TalerWallet1/Views/Balances/BalancesListView.swift
@@ -14,7 +14,6 @@ import AVFoundation
 struct BalancesListView: View {
     private let symLog = SymLogV(0)
     let stack: CallStack
-    @Binding var balances: [Balance]
     @Binding var selectedBalance: Balance?
 //    @Binding var shouldReloadPending: Int
     @Binding var shouldReloadBalances: Int
@@ -23,26 +22,9 @@ struct BalancesListView: View {
     @EnvironmentObject private var controller: Controller
     @AppStorage("myListStyle") var myListStyle: MyListStyle = .automatic
 
-    @State private var lastReloadedBalances = 0
     @State private var amountToTransfer = Amount.zero(currency: EMPTYSTRING)   
 // Update currency when used
     @State private var summary = EMPTYSTRING
 
-    /// runs on MainActor if called in some Task {}
-    @discardableResult
-    private func reloadBalances(_ stack: CallStack, _ invalidateCache: Bool) 
async -> Int? {
-        if invalidateCache {
-            model.cachedBalances = nil
-        }
-
-        if let reloaded = try? await model.balancesM(stack.push()) {
-            let count = reloaded.count
-            balances = reloaded         // redraw
-            return count
-        }
-
-        return nil
-    }
-
     private static func className() -> String {"\(self)"}
 
     var body: some View {
@@ -51,11 +33,11 @@ struct BalancesListView: View {
         let _ = symLog.vlog()       // just to get the # to compare it with 
.onAppear & onDisappear
 #endif
         Group {
-            let count = balances.count
-            if balances.isEmpty {
+            let count = controller.balances.count
+            if controller.balances.isEmpty {
                 WalletEmptyView(stack: stack.push("isEmpty"))
             } else {
-                List(balances, id: \.self) { balance in
+                List(controller.balances, id: \.self) { balance in
                     BalancesSectionView(stack: 
stack.push("\(balance.scopeInfo.currency)"),
                                       balance: balance,                     // 
this is the currency to be used
                               selectedBalance: $selectedBalance,
@@ -75,17 +57,8 @@ struct BalancesListView: View {
         .refreshable {  // already async
             controller.hapticNotification(.success)
             symLog.log("refreshing balances")
-            let count = await reloadBalances(stack.push("refreshing 
balances"), true)
-            if let count, count > 0 {
-                NotificationCenter.default.post(name: .BalanceReloaded, 
object: nil)
-            }
+            await controller.loadBalances(stack.push("refreshing balances"), 
model)
         }
 #endif
-        .task(id: shouldReloadBalances) {
-            symLog.log(".task shouldReloadBalances \(shouldReloadBalances)")
-            let invalidateCache = (lastReloadedBalances != 
shouldReloadBalances)
-            lastReloadedBalances = shouldReloadBalances
-            await reloadBalances(stack.push(".task"), invalidateCache)
-        } // task
     }
 }
diff --git a/TalerWallet1/Views/HelperViews/ScopePicker.swift 
b/TalerWallet1/Views/HelperViews/ScopePicker.swift
index a625c19..1ec2807 100644
--- a/TalerWallet1/Views/HelperViews/ScopePicker.swift
+++ b/TalerWallet1/Views/HelperViews/ScopePicker.swift
@@ -23,19 +23,20 @@ fileprivate func pickerRow(_ balance: Balance) -> String {
 struct ScopePicker: View {
 //    private let symLog = SymLogV(0)
     @Binding var value: Int
-    let balances: [Balance]
     let onlyNonZero: Bool
     let action: (Int) -> Void
 
+    @EnvironmentObject private var controller: Controller
+
     @State private var selected = 0
 
     var body: some View {
 #if PRINT_CHANGES
         let _ = Self._printChanges()
 #endif
-        let count = balances.count
+        let count = controller.balances.count
         if (count > 0) {
-            let balance = balances[selected]
+            let balance = controller.balances[selected]
             let available = balance.available
             let availableA11y = available.formatted(isNegative: false, useISO: 
true, a11y: ".")
             let url = balance.scopeInfo.url?.trimURL ?? EMPTYSTRING
@@ -49,13 +50,12 @@ struct ScopePicker: View {
 
                 if #available(iOS 16.0, *) {
                     ScopeDropDown(selection: $selected,
-                                  balances: balances,
-                               onlyNonZero: onlyNonZero,
-                                  disabled: disabled)
+                                onlyNonZero: onlyNonZero,
+                                   disabled: disabled)
                 } else {
                     Picker(EMPTYSTRING, selection: $selected) {
-                        ForEach(0..<balances.count, id: \.self) { index in
-                            let balance = balances[index]
+                        ForEach(0..<controller.balances.count, id: \.self) { 
index in
+                            let balance = controller.balances[index]
                             Text(pickerRow(balance))
                                 .tag(index)
 //                              .selectionDisabled(balance.available.isZero)   
 needs iOS 17
@@ -84,12 +84,13 @@ struct ScopePicker: View {
 @available(iOS 16.0, *)
 struct  ScopeDropDown: View {
     @Binding  var selection: Int
-    let balances: [Balance]
     let onlyNonZero: Bool
     let disabled: Bool
 
 //    var maxItemDisplayed: Int = 3
 
+    @EnvironmentObject private var controller: Controller
+
     @State private var scrollPosition: Int?
     @State private var showDropdown = false
 
@@ -126,7 +127,7 @@ struct  ScopeDropDown: View {
             let chevron = Image(systemName: "chevron.up")
             let foreColor = disabled ? Color.secondary : Color.primary
             let backColor = disabled ? WalletColors().backgroundColor : 
WalletColors().gray4
-            let otherBalances = balances.filter { $0 != balances[selection] }
+            let otherBalances = controller.balances.filter { $0 != 
controller.balances[selection] }
             let theList = LazyVStack(spacing: 0) {
                 ForEach(0..<otherBalances.count, id: \.self) { index in
                     let item = otherBalances[index]
@@ -134,7 +135,7 @@ struct  ScopeDropDown: View {
                     Button(action: {
                         withAnimation {
                             showDropdown.toggle()
-                            selection = balances.firstIndex(of: item) ?? 
selection
+                            selection = controller.balances.firstIndex(of: 
item) ?? selection
                         }
                     }, label: {
                         HStack(alignment: .top) {
@@ -154,7 +155,7 @@ struct  ScopeDropDown: View {
             }
             VStack {
                 // selected item
-                let balance = balances[selection]
+                let balance = controller.balances[selection]
                 Button(action: buttonAction) {
                     HStack(alignment: .firstTextBaseline) {
                         dropDownRow(balance)
@@ -171,16 +172,16 @@ struct  ScopeDropDown: View {
 //                .border(.red)
                 if (showDropdown) {
                     if #available(iOS 17.0, *) {
-//                      let toomany = balances.count > maxItemDisplayed
+//                      let toomany = controller.balances.count > 
maxItemDisplayed
 //                      let scrollViewHeight = buttonHeight * CGFloat(toomany 
? maxItemDisplayed
-//                                                                            
: balances.count)
+//                                                                            
: controller.balances.count)
                         ScrollView {
                             theList
                                 .scrollTargetLayout()
                         }
 //                      .border(.red)
                         .scrollPosition(id: $scrollPosition)
-                        .scrollDisabled(balances.count <= 3)
+                        .scrollDisabled(controller.balances.count <= 3)
 //                      .frame(height: scrollViewHeight)
                         .onAppear {
                             scrollPosition = selection
diff --git a/TalerWallet1/Views/Main/MainView.swift 
b/TalerWallet1/Views/Main/MainView.swift
index 883b3d8..0add4ba 100644
--- a/TalerWallet1/Views/Main/MainView.swift
+++ b/TalerWallet1/Views/Main/MainView.swift
@@ -38,7 +38,6 @@ struct MainView: View {
     @AppStorage("playSoundsI") var playSoundsI: Int = 1             // 
extension mustn't define this, so it must be here
     @AppStorage("playSoundsB") var playSoundsB: Bool = false
 
-    @State private var balances: [Balance] = []
     @State private var selectedBalance: Balance? = nil
     @State private var urlToOpen: URL? = nil
     @State private var sheetPresented = false
@@ -67,7 +66,6 @@ struct MainView: View {
         Group {
             if controller.backendState == .ready {
                 Content(logger: logger, stack: stack.push("Content"),
-                      balances: $balances,
                selectedBalance: $selectedBalance,
                 talerFontIndex: $talerFontIndex,
                showActionSheet: $showActionSheet,
@@ -101,7 +99,6 @@ struct MainView: View {
         }
         .sheet(item: $urlToOpen, onDismiss: sheetDismissed) { url in
             let sheet = AnyView(URLSheet(stack: stack.push(),
-                                      balances: $balances,
                                selectedBalance: $selectedBalance,
                                      urlToOpen: url))
             Sheet(stack: stack.push(), sheetView: sheet)
@@ -125,7 +122,6 @@ struct MainView: View {
                onDismiss: { showScanner = false; qrButtonTapped = false }
         ) {
             let qrSheet = AnyView(QRSheet(stack: stack.push(".sheet"),
-                                          balances: $balances,
                                           selectedBalance: $selectedBalance))
             if #available(iOS 16.4, *) {
                 if showScanner {
@@ -136,7 +132,6 @@ struct MainView: View {
                 } else {
                     let _ = logger.log("❗️actionsSheet: small❗️")
                     DualHeightSheet(stack: stack.push(),
-                                 balances: $balances,
                            qrButtonTapped: $qrButtonTapped)
                 }
             } else {
@@ -148,7 +143,6 @@ struct MainView: View {
                         Spacer()
                         ScrollView {
                             ActionsSheet(stack: stack.push(),
-                                      balances: $balances,
                                 qrButtonTapped: $qrButtonTapped)
                             .innerHeight($innerHeight)
 //                          .padding()
@@ -220,7 +214,6 @@ extension MainView {
     struct Content: View {
         let logger: Logger
         let stack: CallStack
-        @Binding var balances: [Balance]
         @Binding var selectedBalance: Balance?
         @Binding var talerFontIndex: Int
         @Binding var showActionSheet: Bool
@@ -328,19 +321,16 @@ extension MainView {
                               currency: DEMOCURRENCY)
 
             let sendDest = SendAmountV(stack: 
stack.push("\(Self.className())()"),
-                                    balances: balances,
                              selectedBalance: $selectedBalance,             // 
if nil shows currency picker
                               amountLastUsed: $amountLastUsed,              // 
currency needs to be updated!
                                      summary: $summary)
 
             let requestDest = RequestPayment(stack: 
stack.push("\(Self.className())()"),
-                                          balances: balances,
                                    selectedBalance: $selectedBalance,
                                     amountLastUsed: $amountLastUsed,      // 
currency needs to be updated!
                                            summary: $summary)
 
             let depositDest = DepositIbanV(stack: stack.push(),
-                                        balances: balances,
                                  selectedBalance: $selectedBalance,
                                         feeLabel: nil,
                                     feeIsNotZero: nil,
@@ -349,7 +339,6 @@ extension MainView {
                                   amountLastUsed: $amountLastUsed)
 
             let manualWithdrawDest = ManualWithdraw(stack: stack.push(),
-                                                 balances: balances,
                                           selectedBalance: $selectedBalance,
                                                   isSheet: false,
                                                 scopeInfo: scope,
@@ -361,7 +350,6 @@ extension MainView {
                 TabView(selection: tabSelection()) {
                     NavigationView {
                         BalancesListView(stack: stack.push(balancesTitle),
-                                      balances: $balances,
                                selectedBalance: $selectedBalance,
 //                         shouldReloadPending: $shouldReloadPending,
                           shouldReloadBalances: $shouldReloadBalances)
@@ -388,7 +376,6 @@ extension MainView {
 
                     NavigationView {
                         SettingsView(stack: stack.push(),
-                                  balances: $balances,
                                   navTitle: settingsTitle)
                     }.id(viewState2.rootViewId)               // any change to 
rootViewId triggers popToRootView behaviour
                     .navigationViewStyle(.stack)
@@ -443,12 +430,10 @@ extension MainView {
                     controller.playSound(0)
                 }
             }
-            .onChange(of: balances) { newArray in
-                for balance in newArray {
-                    let scope = balance.scopeInfo
-                    controller.checkInfo(for: scope, model: model)
-                }
-            }
+            .task(id: shouldReloadBalances) {
+//                symLog.log(".task shouldReloadBalances 
\(shouldReloadBalances)")
+                await controller.loadBalances(stack.push("refreshing 
balances"), model)
+            } // task
         } // body
     } // Content
 }
diff --git a/TalerWallet1/Views/Settings/Exchange/ExchangeListView.swift 
b/TalerWallet1/Views/Settings/Exchange/ExchangeListView.swift
index 90cdd26..9373abf 100644
--- a/TalerWallet1/Views/Settings/Exchange/ExchangeListView.swift
+++ b/TalerWallet1/Views/Settings/Exchange/ExchangeListView.swift
@@ -13,7 +13,6 @@ import SymLog
 struct ExchangeListView: View {
     private let symLog = SymLogV(0)
     let stack: CallStack
-    @Binding var balances: [Balance]
     let navTitle: String
     @EnvironmentObject private var model: WalletModel
     @EnvironmentObject private var controller: Controller
@@ -40,7 +39,7 @@ struct ExchangeListView: View {
         let addTitleStr = String(localized: "Add payment service", comment: 
"title of the addExchange alert")
         let addButtonStr = String(localized: "Add", comment: "button in the 
addExchange alert")
         if #available(iOS 16.0, *) {
-            ExchangeListCommonV(symLog: symLog, stack: stack.push(), balances: 
$balances)
+            ExchangeListCommonV(symLog: symLog, stack: stack.push())
                 .navigationTitle(navTitle)
                 .navigationBarItems(trailing: plusButton)
                 .alert(addTitleStr, isPresented: $showAlert) {
@@ -54,7 +53,7 @@ struct ExchangeListView: View {
                     Text("Please enter the URL")
                 }
         } else {    // iOS 15 cannot have a textfield in an alert, so we must
-            ExchangeListCommonV(symLog: symLog, stack: stack.push(), balances: 
$balances)
+            ExchangeListCommonV(symLog: symLog, stack: stack.push())
                 .navigationTitle(navTitle)
                 .navigationBarItems(trailing: plusButton)
                 .textFieldAlert(isPresented: $showAlert,
@@ -70,7 +69,6 @@ struct ExchangeListView: View {
 struct ExchangeListCommonV {
     let symLog: SymLogV?
     let stack: CallStack
-    @Binding var balances: [Balance]
 
     @EnvironmentObject private var model: WalletModel
     @EnvironmentObject private var controller: Controller
@@ -99,7 +97,6 @@ extension ExchangeListCommonV: View {
         let sortedExchanges = exchanges.sorted { $0 < $1 }
         let sortedList = List(sortedExchanges, id: \.self) { exchange in
             ExchangeSectionView(stack: stack.push(),
-                             balances: $balances,
                              exchange: exchange,
 //                        depositIBAN: $depositIBAN,
 //                      accountHolder: $accountHolder,
diff --git a/TalerWallet1/Views/Settings/Exchange/ExchangeSectionView.swift 
b/TalerWallet1/Views/Settings/Exchange/ExchangeSectionView.swift
index d92febe..09ac71a 100755
--- a/TalerWallet1/Views/Settings/Exchange/ExchangeSectionView.swift
+++ b/TalerWallet1/Views/Settings/Exchange/ExchangeSectionView.swift
@@ -15,7 +15,6 @@ import SymLog
 struct ExchangeSectionView: View {
     private let symLog = SymLogV(0)
     let stack: CallStack
-    @Binding var balances: [Balance]
     let exchange: Exchange
 //    let exchanges: [Exchange]
 //    @Binding var depositIBAN: String
@@ -147,47 +146,3 @@ struct ExchangeSectionView: View {
         }
     }
 }
-// MARK: -
-#if false   // model crashes
-fileprivate struct ExchangeSection_Previews: PreviewProvider {
-fileprivate struct ExchangeRow_Container : View {
-    @State private var previewBalances: [Balance] = []
-    @State private var amountToPreview = Amount(currency: LONGCURRENCY, cent: 
1234)
-    @State private var depositIBAN = "DE1234567890"
-    @State private var accountHolder = "Marc Stibane"
-
-//    let amount = Amount(currency: LONGCURRENCY, cent: 123456)
-    var body: some View {
-        let scopeInfo = ScopeInfo(type: .exchange, currency: LONGCURRENCY)
-        let exchange1 = Exchange(exchangeBaseUrl: ARS_AGE_EXCHANGE,
-                                       scopeInfo: scopeInfo,
-                                       paytoUris: [],
-                                       tosStatus: .pending,
-                             exchangeEntryStatus: .preset,
-                            exchangeUpdateStatus: .initial,
-                           ageRestrictionOptions: [12,16])
-        let exchange2 = Exchange(exchangeBaseUrl: ARS_EXP_EXCHANGE,
-                                       scopeInfo: scopeInfo,
-                                       paytoUris: [],
-                                       tosStatus: .proposed,
-                             exchangeEntryStatus: .ephemeral,
-                            exchangeUpdateStatus: .ready,
-                           ageRestrictionOptions: [])
-        ExchangeSectionView(stack: CallStack("Preview"), 
-                         balances: $previewBalances,
-//                        scopeInfo: scopeInfo,
-                         exchange: exchange1,
-//                        exchanges: [exchange1, exchange2],
-//                      depositIBAN: $depositIBAN,
-//                    accountHolder: $accountHolder,
-                 amountToTransfer: $amountToPreview)
-    }
-}
-
-    static var previews: some View {
-        List {
-            ExchangeRow_Container()
-        }
-    }
-}
-#endif
diff --git a/TalerWallet1/Views/Settings/SettingsView.swift 
b/TalerWallet1/Views/Settings/SettingsView.swift
index 8eb19ce..34655c8 100644
--- a/TalerWallet1/Views/Settings/SettingsView.swift
+++ b/TalerWallet1/Views/Settings/SettingsView.swift
@@ -19,7 +19,6 @@ import LocalConsole
 struct SettingsView: View {
     private let symLog = SymLogV(0)
     let stack: CallStack
-    @Binding var balances: [Balance]
     let navTitle: String
 
     @EnvironmentObject private var controller: Controller
@@ -102,7 +101,6 @@ struct SettingsView: View {
                 let exchangesTitle = String(localized: "TitleExchanges", 
defaultValue: "Payment Services")
                 let exchangesDest = LazyView {
                     ExchangeListView(stack: stack.push(exchangesTitle),
-                                  balances: $balances,
                                   navTitle: exchangesTitle)
                 }
                 NavigationLink {        // whole row like in a tableView
diff --git a/TalerWallet1/Views/Sheets/QRSheet.swift 
b/TalerWallet1/Views/Sheets/QRSheet.swift
index 10da229..2bd1a2e 100644
--- a/TalerWallet1/Views/Sheets/QRSheet.swift
+++ b/TalerWallet1/Views/Sheets/QRSheet.swift
@@ -10,7 +10,6 @@ import AVFoundation
 struct QRSheet: View {
     private let symLog = SymLogV(0)
     let stack: CallStack
-    @Binding var balances: [Balance]
     @Binding var selectedBalance: Balance?
 
     @State private var scannedCode: String?
@@ -36,7 +35,6 @@ struct QRSheet: View {
                     let scheme = scannedURL.scheme
                     if scheme?.lowercased() == "taler" {
                         URLSheet(stack: stack.push(),
-                              balances: $balances,
                        selectedBalance: $selectedBalance,
                              urlToOpen: scannedURL)
                     } else {
diff --git a/TalerWallet1/Views/Sheets/URLSheet.swift 
b/TalerWallet1/Views/Sheets/URLSheet.swift
index 0a8687f..8abe48c 100644
--- a/TalerWallet1/Views/Sheets/URLSheet.swift
+++ b/TalerWallet1/Views/Sheets/URLSheet.swift
@@ -12,7 +12,6 @@ import SymLog
 struct URLSheet: View {
     private let symLog = SymLogV(0)
     let stack: CallStack
-    @Binding var balances: [Balance]
     @Binding var selectedBalance: Balance?
     var urlToOpen: URL
 
@@ -36,7 +35,6 @@ struct URLSheet: View {
                     WithdrawURIView(stack: stack.push(), url: urlToOpen)
                 case .withdrawExchange:
                     WithdrawExchangeV(stack: stack.push(),
-                                   balances: $balances,
                             selectedBalance: $selectedBalance,
                                         url: urlToOpen)
                 case .pay:
diff --git a/TalerWallet1/Views/Sheets/WithdrawExchangeV.swift 
b/TalerWallet1/Views/Sheets/WithdrawExchangeV.swift
index 29a4156..97be3fc 100644
--- a/TalerWallet1/Views/Sheets/WithdrawExchangeV.swift
+++ b/TalerWallet1/Views/Sheets/WithdrawExchangeV.swift
@@ -13,7 +13,6 @@ import SymLog
 struct WithdrawExchangeV: View {
     private let symLog = SymLogV(0)
     let stack: CallStack
-    @Binding var balances: [Balance]
     @Binding var selectedBalance: Balance?
     var url: URL
 
@@ -35,7 +34,6 @@ struct WithdrawExchangeV: View {
             let currency = exchange.scopeInfo.currency
             Group {
                 ManualWithdraw(stack: stack.push(),
-                            balances: balances,
                      selectedBalance: $selectedBalance,
 //                      currencyInfo: $currencyInfo,
                              isSheet: true,

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