taler-ios

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

commit d37deaad8d4e58222e5200a8d8f7ccfa2c005aa8
parent 7db23acf4f69f07a0fda302b4909284741401fe9
Author: Jonathan Buchanan <jonathan.russ.buchanan@gmail.com>
Date:   Tue,  9 Aug 2022 19:10:27 -0400

loading indicator for adding exchanges

Diffstat:
MTaler/ExchangeManager.swift | 25+++++++++++++++++--------
MTaler/SettingsView.swift | 53+++++++++++++++++++++++++++++++++++++++++------------
2 files changed, 58 insertions(+), 20 deletions(-)

diff --git a/Taler/ExchangeManager.swift b/Taler/ExchangeManager.swift @@ -21,7 +21,7 @@ typealias ExchangeItem = WalletBackendListExchanges.ExchangeListItem class ExchangeManager: ObservableObject { var backend: WalletBackend - var loading: Bool + @Published var loading: Bool @Published var exchanges: [ExchangeItem]? init(_backend: WalletBackend) { @@ -33,14 +33,14 @@ class ExchangeManager: ObservableObject { func updateList() { let listRequest = WalletBackendListExchanges() backend.sendFormattedRequest(request: listRequest) { response, err in - self.loading = false - if let result = response { - // TODO: Use Combine instead. - DispatchQueue.main.async { + // TODO: Use Combine instead. + DispatchQueue.main.async { + self.loading = false + if let result = response { self.exchanges = result.exchanges + } else { + // TODO: Show error. } - } else { - // TODO: Show error. } } self.loading = true @@ -49,7 +49,16 @@ class ExchangeManager: ObservableObject { func add(url: String) { let addRequest = WalletBackendAddExchangeRequest(exchangeBaseUrl: url) backend.sendFormattedRequest(request: addRequest) { response, err in - // TODO: Show error. + // TODO: Use Combine instead. + DispatchQueue.main.async { + self.loading = false + if let _ = response { + self.updateList() + } else { + // TODO: Show error. + } + } } + self.loading = true } } diff --git a/Taler/SettingsView.swift b/Taler/SettingsView.swift @@ -64,13 +64,28 @@ extension View { } } -struct ExchangeItemView: View { - var exchange: ExchangeItem +struct WithdrawView: View { + let exchange: ExchangeItem + @State var amount: String = "" + var body: some View { VStack { - Text(exchange.exchangeBaseUrl) - Text("Currency: " + exchange.currency) + Button { + + } label: { + Text("Scan Taler QR Code") + } + Text("Or transfer manually:") + HStack { + TextField(exchange.currency, text: $amount) + } + Button { + + } label: { + Text("Check Fees") + } } + .navigationTitle("Withdraw") } } @@ -79,7 +94,17 @@ struct ExchangeListView: View { @State var showPopup: Bool = false var body: some View { - if let exchanges = exchangeManager.exchanges { + if exchangeManager.exchanges == nil { + ProgressView() + .navigationTitle("Exchanges") + .onAppear { + exchangeManager.updateList() + } + } else if exchangeManager.loading { + ProgressView() + .navigationTitle("Exchanges") + } else { + let exchanges = exchangeManager.exchanges! if exchanges.count == 0 { Text("No Exchanges") .navigationTitle("Exchanges") @@ -99,7 +124,17 @@ struct ExchangeListView: View { }, showing: showPopup) } else { List(exchanges, id: \.self) { exchange in - ExchangeItemView(exchange: exchange) + VStack { + Text(exchange.exchangeBaseUrl) + .frame(maxWidth: .infinity) + Text("Currency: " + exchange.currency) + .frame(maxWidth: .infinity) + NavigationLink { + WithdrawView(exchange: exchange) + } label: { + Text("Withdraw") + } + } } .navigationTitle("Exchanges") .navigationBarItems(trailing: Button(action: { @@ -117,12 +152,6 @@ struct ExchangeListView: View { print(exchangeUrl) }, showing: showPopup) } - } else { - ProgressView() - .navigationTitle("Exchanges") - .onAppear { - exchangeManager.updateList() - } } } }