commit c1b5bd3a11e914c024139b8aa6609042498fc8a6
parent 8075693de154c75e5fb1d30a4c8c7086db7e9692
Author: Marc Stibane <marc@taler.net>
Date: Mon, 22 Dec 2025 19:26:23 +0100
Add exchange (internal)
Diffstat:
2 files changed, 46 insertions(+), 23 deletions(-)
diff --git a/TalerWallet1/Views/Settings/Exchange/ExchangeListView.swift b/TalerWallet1/Views/Settings/Exchange/ExchangeListView.swift
@@ -9,30 +9,34 @@ import SwiftUI
import taler_swift
import SymLog
+@MainActor
+fileprivate
+func addExchange(_ exchange: String, model: WalletModel) -> Void {
+ Task { // runs on MainActor
+ if let _ = try? await model.addExchange(uri: exchange) {
+// symLog.log("added: \(exchange)")
+// View.announce("added: \(exchange)")
+ if UIAccessibility.isVoiceOverRunning {
+ UIAccessibility.post(notification: .announcement, argument: "added: \(exchange)")
+ }
+ NotificationCenter.default.post(name: .ExchangeAdded, object: nil, userInfo: nil)
+ NotificationCenter.default.post(name: .BalanceChange, object: nil, userInfo: nil) // TODO: ExchangeAdded should suffice
+ }
+ }
+}
+
/// This view shows the list of exchanges
struct ExchangeListView: View {
private let symLog = SymLogV(0)
let stack: CallStack
let navTitle: String
+ let showDevelopItems: Bool
@EnvironmentObject private var model: WalletModel
@EnvironmentObject private var controller: Controller
@State var showAlert: Bool = false
@State var newExchange: String = TESTEXCHANGE
- @MainActor
- func addExchange(_ exchange: String) -> Void {
- Task { // runs on MainActor
- symLog.log("adding: \(exchange)")
- if let _ = try? await model.addExchange(uri: exchange) {
- symLog.log("added: \(exchange)")
- announce("added: \(exchange)")
- NotificationCenter.default.post(name: .ExchangeAdded, object: nil, userInfo: nil)
- NotificationCenter.default.post(name: .BalanceChange, object: nil, userInfo: nil) // TODO: ExchangeAdded should suffice
- }
- }
- }
-
var body: some View {
let a11yLabelStr = String(localized: "Add payment service", comment: "a11y for the + button")
let plusButton = PlusButton(accessibilityLabelStr: a11yLabelStr) {
@@ -42,7 +46,7 @@ struct ExchangeListView: View {
let addButtonStr = String(localized: "Add", comment: "button in the addExchange alert")
let enterURL = String(localized: "Enter the URL")
if #available(iOS 16.4, *) {
- ExchangeListCommonV(symLog: symLog, stack: stack.push())
+ ExchangeListCommonV(symLog: symLog, stack: stack.push(), showDevelopItems: showDevelopItems)
.navigationTitle(navTitle)
.navigationBarItems(trailing: plusButton)
.alert(addTitleStr, isPresented: $showAlert) {
@@ -50,7 +54,7 @@ struct ExchangeListView: View {
.accessibilityLabel(enterURL)
// .textFieldStyle(.roundedBorder) Yikes: when adding style the alert will stop showing the textfield! Don't do this.
Button(addButtonStr) {
- addExchange(newExchange)
+ addExchange(newExchange, model: model)
}
Button("Cancel", role: .cancel) { }
} message: {
@@ -58,14 +62,14 @@ struct ExchangeListView: View {
.accessibilityHidden(true)
}
} else { // iOS 15 cannot have a textfield in an alert, so we must
- ExchangeListCommonV(symLog: symLog, stack: stack.push())
+ ExchangeListCommonV(symLog: symLog, stack: stack.push(), showDevelopItems: showDevelopItems)
.navigationTitle(navTitle)
.navigationBarItems(trailing: plusButton)
.textFieldAlert(isPresented: $showAlert,
title: addTitleStr,
doneText: addButtonStr,
text: $newExchange) { text in
- addExchange(text)
+ addExchange(text, model: model)
}
}
}
@@ -74,8 +78,10 @@ struct ExchangeListView: View {
struct ExchangeListCommonV: View {
let symLog: SymLogV?
let stack: CallStack
+ let showDevelopItems: Bool
@EnvironmentObject private var controller: Controller
+ @EnvironmentObject private var model: WalletModel
@AppStorage("minimalistic") var minimalistic: Bool = false
@AppStorage("myListStyle") var myListStyle: MyListStyle = .automatic
@@ -84,10 +90,26 @@ struct ExchangeListCommonV: View {
let _ = Self._printChanges()
let _ = symLog?.vlog() // just to get the # to compare it with .onAppear & onDisappear
#endif
- let balanceList = List(Array(controller.balances.enumerated()), id: \.element) { index, balance in
- ExchangeSectionView(stack: stack.push(),
- balance: balance,
- thousand: index * MAXEXCHANGES) // unique ID
+ let balanceList = List {
+ ForEach(Array(controller.balances.enumerated()), id: \.1.id) { index, balance in
+ ExchangeSectionView(stack: stack.push(),
+ balance: balance,
+ thousand: index * MAXEXCHANGES) // unique ID
+ }
+#if DEBUG
+ if showDevelopItems {
+ Section {
+ let exchanges = ["glsint.fdold.eu", "taler.magnetbank.hu", "stage.taler-ops.ch"]
+ ForEach(exchanges, id: \.self) { exchange in
+ let urlStr = "https://exchange." + exchange
+ Button(urlStr) {
+ addExchange(urlStr, model: model)
+ }
+ // Link(exchange, destination: URL(string: urlStr)!)
+ }
+ }
+ }
+#endif
}
let emptyList = List {
diff --git a/TalerWallet1/Views/Settings/SettingsView.swift b/TalerWallet1/Views/Settings/SettingsView.swift
@@ -117,7 +117,8 @@ struct SettingsView: View {
let exchangesTitle = String(localized: "TitleExchanges", defaultValue: "Payment Services")
let exchangesDest = ExchangeListView(stack: stack.push(exchangesTitle),
- navTitle: exchangesTitle)
+ navTitle: exchangesTitle,
+ showDevelopItems: showDevelopItems)
NavigationLink { // whole row like in a tableView
exchangesDest
} label: {
@@ -212,7 +213,7 @@ struct SettingsView: View {
}
#if DEBUG
if showDevelopItems {
- let banks = ["glstest.taler.net", "glsint.fdold.eu", "taler.fdold.eu", "regio-taler.fdold.eu",
+ let banks = ["glstest.taler.net", "taler.fdold.eu", "regio-taler.fdold.eu",
"taler.grothoff.org", "taler.ar",
"head.taler.net", "test.taler.net", "demo.taler.net", "kyctest.taler.net"]
ForEach(banks, id: \.self) { bank in