taler-ios

iOS apps for GNU Taler (wallet)
Log | Files | Refs | README | LICENSE

commit df49c9c40b3a07be7194798b69f5af47e6552d55
parent 102444ffbbf477019ffac7265fed5a963ed6c5b7
Author: Marc Stibane <marc@taler.net>
Date:   Wed,  2 Oct 2024 19:28:52 +0200

deleteExchange

Diffstat:
MTalerWallet1/Views/Banking/ExchangeListView.swift | 70+++++++++++++++++++++++++++++++++-------------------------------------
MTalerWallet1/Views/Banking/ExchangeSectionView.swift | 22++++++++++++++++++++--
2 files changed, 53 insertions(+), 39 deletions(-)

diff --git a/TalerWallet1/Views/Banking/ExchangeListView.swift b/TalerWallet1/Views/Banking/ExchangeListView.swift @@ -97,51 +97,47 @@ extension ExchangeListCommonV: View { let _ = symLog?.vlog() // just to get the # to compare it with .onAppear & onDisappear #endif 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, + amountToTransfer: $amountToTransfer) // does still have the wrong currency + } + + let emptyList = List { + Section { + Text("There are no Payment Services yet.") + .talerFont(.title3) + } + Section { + Text("Use the Add button to add a service.") + .talerFont(.body) + .listRowSeparator(.hidden) + Text("You can also scan a withdrawal QR code from your bank on the Balances tab to automatically add a payment service.") + .talerFont(.body) + } + } + // TODO: Balances for amountAvailable for Deposit Group { - List(sortedExchanges, id: \.self) { exchange in - ExchangeSectionView(stack: stack.push(), - balances: $balances, - exchange: exchange, -// depositIBAN: $depositIBAN, -// accountHolder: $accountHolder, - amountToTransfer: $amountToTransfer) // does still have the wrong currency + if exchanges.isEmpty { + emptyList + } else { + sortedList } + } + .listStyle(myListStyle.style).anyView //#if REFRESHABLE - .refreshable { - symLog?.log("refreshing") - await reloadExchanges() - } -//#endif - .listStyle(myListStyle.style).anyView + .refreshable { + symLog?.log("refreshing") + await reloadExchanges() } +//#endif .onAppear() { DebugViewC.shared.setViewID(VIEW_BANKING, stack: stack.push()) } - .overlay { - if exchanges.isEmpty { - List { - Section { - Text("There are no Payment Services yet.") - .talerFont(.title3) - } - Section { - Text("Use the Add button to add a service.") - .talerFont(.body) - .listRowSeparator(.hidden) - Text("You can also scan a withdrawal QR code from your bank on the Balances tab to automatically add a payment service.") - .talerFont(.body) - } - } -//#if REFRESHABLE - .refreshable { - symLog?.log("refreshing") - await reloadExchanges() - } -//#endif - .listStyle(myListStyle.style).anyView - } - } .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") diff --git a/TalerWallet1/Views/Banking/ExchangeSectionView.swift b/TalerWallet1/Views/Banking/ExchangeSectionView.swift @@ -52,10 +52,14 @@ struct ExchangeSectionView: View { private func deleteExchange() { disabled = true // don't try this more than once + let doPurge = purge Task { // runs on MainActor - if let _ = try? await model.deleteExchange(url: exchange.exchangeBaseUrl, purge: purge) { + let baseUrl = exchange.exchangeBaseUrl + if let _ = try? await model.deleteExchange(url: baseUrl, purge: doPurge, viewHandles: !doPurge) { symLog.log("deleted \(baseUrl.trimURL())") didDelete = true // change button text + NotificationCenter.default.post(name: .ExchangeDeleted, object: nil, userInfo: nil) + NotificationCenter.default.post(name: .BalanceChange, object: nil, userInfo: nil) } else { purge = true disabled = false @@ -97,15 +101,29 @@ struct ExchangeSectionView: View { .accessibilityElement(children: .combine) .accessibilityLabel(bankingHint + " " + linkTitle) .padding(.top) + .listRowSeparator(.hidden) } let buttonTitle = String(localized: "Exchange.Delete", defaultValue: "Delete Payment Provider", comment: "Action button") - WarningButton(warningText: String(localized: "Are you sure you want to delete this payment provider?"), + let warningText1 = String(localized: "Are you sure you want to delete this payment provider?") + let warningText2 = String(localized: "This payment provider is in use. Delete anyway?") + WarningButton(warningText: warningText1, buttonTitle: buttonTitle, buttonIcon: "trash", role: .destructive, disabled: $disabled, action: deleteExchange) + .padding(.top) + .alert(warningText2, isPresented: $purge, actions: { + Button("Cancel", role: .cancel) { + purge = false + } + Button(buttonTitle) { + deleteExchange() + purge = false + } + }, message: { Text("You will loose all \(currency) of this payment provider") } + ) } header: { BarGraphHeader(stack: stack.push(), scopeInfo: scopeInfo,