[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-taler-ios] branch master updated: pending operations view
From: |
gnunet |
Subject: |
[taler-taler-ios] branch master updated: pending operations view |
Date: |
Thu, 11 Aug 2022 03:11:10 +0200 |
This is an automated email from the git hooks/post-receive script.
jonathan-buchanan pushed a commit to branch master
in repository taler-ios.
The following commit(s) were added to refs/heads/master by this push:
new 3a8b484 pending operations view
3a8b484 is described below
commit 3a8b484256493117c1ade4d906253ca99160531b
Author: Jonathan Buchanan <jonathan.russ.buchanan@gmail.com>
AuthorDate: Wed Aug 10 21:09:54 2022 -0400
pending operations view
---
Taler/BalanceList.swift | 76 ----------------------
Taler/BalanceRow.swift | 38 -----------
Taler/{ => Model}/BackendManager.swift | 2 +
Taler/{ => Model}/ExchangeManager.swift | 0
.../PendingManager.swift} | 41 ++++--------
Taler/{ => Views}/ContentView.swift | 6 +-
Taler/Views/PendingView.swift | 68 +++++++++++++++++++
Taler/{ => Views}/SettingsView.swift | 23 ++++++-
Taler/WalletBackend.swift | 21 ++++++
9 files changed, 130 insertions(+), 145 deletions(-)
diff --git a/Taler/BalanceList.swift b/Taler/BalanceList.swift
deleted file mode 100644
index 5b326e3..0000000
--- a/Taler/BalanceList.swift
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * This file is part of GNU Taler
- * (C) 2021 Taler Systems S.A.
- *
- * GNU Taler is free software; you can redistribute it and/or modify it under
the
- * terms of the GNU General Public License as published by the Free Software
- * Foundation; either version 3, or (at your option) any later version.
- *
- * GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR
- * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-
-import SwiftUI
-
-/*struct IdentifiedArray<T>: RandomAccessCollection {
- struct Item {
- var id: Int
- var item: T
- }
-
- typealias Element = Item
- typealias ItemArray = [Item]
- typealias Index = ItemArray.Index
- typealias SubSequence = IdentifiedArray<T>
- typealias Indices = ItemArray.Indices
-
- var items: ItemArray
- var startIndex: ItemArray.Index {
- get {
- return items.startIndex
- }
- }
- var endIndex: ItemArray.Index {
- get {
- return items.endIndex
- }
- }
-
- subscript(position: ItemArray.Index) -> Element {
- get {
- return items[position]
- }
- set(value) {
- items[position] = value
- }
- }
-
- init(_ array: [T]) {
- self.items = array.enumerated().map({ (index, element) in
- return Item(id: index, item: element)
- })
- }
-}
-
-struct BalanceList: View {
- var balances: IdentifiedArray<Balance>
-
- var body: some View {
- List(balances, id: \.id) { balance in
- BalanceRow(balance: balance.item)
- }
- }
-}
-
-struct BalanceList_Previews: PreviewProvider {
- static var previews: some View {
- try! BalanceList(balances: IdentifiedArray<Balance>([
- Balance(available: Amount(fromString: "USD:0.01"),
pendingIncoming: Amount(fromString: "USD:0.02"), pendingOutgoing:
Amount(fromString: "USD:0.03"), requiresUserInput: true),
- Balance(available: Amount(fromString: "EUR:0.02"),
pendingIncoming: Amount(fromString: "EUR:0.01"), pendingOutgoing:
Amount(fromString: "EUR:0.03"), requiresUserInput: false)
- ]))
- }
-}*/
diff --git a/Taler/BalanceRow.swift b/Taler/BalanceRow.swift
deleted file mode 100644
index 7a19eef..0000000
--- a/Taler/BalanceRow.swift
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * This file is part of GNU Taler
- * (C) 2021 Taler Systems S.A.
- *
- * GNU Taler is free software; you can redistribute it and/or modify it under
the
- * terms of the GNU General Public License as published by the Free Software
- * Foundation; either version 3, or (at your option) any later version.
- *
- * GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR
- * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-
-import SwiftUI
-import taler_swift
-
-/*struct BalanceRow: View {
- var balance: Balance
-
- var body: some View {
- VStack(alignment: .leading, spacing:
/*@START_MENU_TOKEN@*/nil/*@END_MENU_TOKEN@*/, content: {
- Text("Available: \(balance.available.description)")
- Text("Pending Incoming: \(balance.pendingIncoming.description)")
- Text("Pending Outgoing: \(balance.pendingOutgoing.description)")
- Text("Requires User Input:
\(balance.requiresUserInput.description)")
- })
- .padding()
- }
-}
-
-struct BalanceRow_Previews: PreviewProvider {
- static var previews: some View {
- try! BalanceRow(balance: Balance(available: Amount(fromString:
"USD:0.01"), pendingIncoming: Amount(fromString: "USD:0.02"), pendingOutgoing:
Amount(fromString: "USD:0.03"), requiresUserInput: true))
- }
-}*/
diff --git a/Taler/BackendManager.swift b/Taler/Model/BackendManager.swift
similarity index 89%
rename from Taler/BackendManager.swift
rename to Taler/Model/BackendManager.swift
index 8de4472..d0c262b 100644
--- a/Taler/BackendManager.swift
+++ b/Taler/Model/BackendManager.swift
@@ -20,9 +20,11 @@ class BackendManager: ObservableObject {
var backend: WalletBackend
@Published var exchangeManager: ExchangeManager
+ @Published var pendingManager: PendingManager
init() {
self.backend = try! WalletBackend()
self.exchangeManager = ExchangeManager(_backend: self.backend)
+ self.pendingManager = PendingManager(_backend: self.backend)
}
}
diff --git a/Taler/ExchangeManager.swift b/Taler/Model/ExchangeManager.swift
similarity index 100%
copy from Taler/ExchangeManager.swift
copy to Taler/Model/ExchangeManager.swift
diff --git a/Taler/ExchangeManager.swift b/Taler/Model/PendingManager.swift
similarity index 51%
rename from Taler/ExchangeManager.swift
rename to Taler/Model/PendingManager.swift
index 003d2eb..02a7e37 100644
--- a/Taler/ExchangeManager.swift
+++ b/Taler/Model/PendingManager.swift
@@ -15,47 +15,32 @@
*/
import Foundation
+import AnyCodable
-typealias ExchangeItem = WalletBackendListExchanges.ExchangeListItem
-
-class ExchangeManager: ObservableObject {
+class PendingManager: ObservableObject {
var backend: WalletBackend
@Published var loading: Bool
- @Published var exchanges: [ExchangeItem]?
+ @Published var items: [String]?
init(_backend: WalletBackend) {
self.backend = _backend
self.loading = false
- self.exchanges = nil
- }
-
- func updateList() {
- let listRequest = WalletBackendListExchanges()
- backend.sendFormattedRequest(request: listRequest) { response, err in
- // TODO: Use Combine instead.
- DispatchQueue.main.async {
- self.loading = false
- if let result = response {
- self.exchanges = result.exchanges
- } else {
- // TODO: Show error.
- }
- }
- }
- self.loading = true
+ self.items = nil
}
- func add(url: String) {
- let addRequest = WalletBackendAddExchangeRequest(exchangeBaseUrl: url)
- backend.sendFormattedRequest(request: addRequest) { response, err in
+ func update() {
+ let req = WalletBackendPendingRequest()
+ backend.sendFormattedRequest(request: req) { response, err in
// TODO: Use Combine instead.
DispatchQueue.main.async {
self.loading = false
- if let _ = response {
- self.updateList()
- } else {
- // TODO: Show error.
+ if let x = response {
+ self.items = x.pendingOperations.map({ op in
+ let encoded = try! JSONEncoder().encode(op)
+ let str = String(data: encoded, encoding: .utf8)!
+ return str
+ })
}
}
}
diff --git a/Taler/ContentView.swift b/Taler/Views/ContentView.swift
similarity index 89%
rename from Taler/ContentView.swift
rename to Taler/Views/ContentView.swift
index c830692..346390b 100644
--- a/Taler/ContentView.swift
+++ b/Taler/Views/ContentView.swift
@@ -35,7 +35,11 @@ struct ContentView: View {
SidebarItem(name: "Settings",
view: AnyView(SettingsView {
self.sidebarVisible = true
- }.environmentObject(backend)))
+ }.environmentObject(backend))),
+ SidebarItem(name: "Pending Operations",
+ view: AnyView(PendingView(_showSidebar: {
+ self.sidebarVisible = true
+ }, pending:
backend.pendingManager).environmentObject(backend)))
]}
@State var currentView: Int = 0
diff --git a/Taler/Views/PendingView.swift b/Taler/Views/PendingView.swift
new file mode 100644
index 0000000..40fecd0
--- /dev/null
+++ b/Taler/Views/PendingView.swift
@@ -0,0 +1,68 @@
+/*
+ * This file is part of GNU Taler
+ * (C) 2022 Taler Systems S.A.
+ *
+ * GNU Taler is free software; you can redistribute it and/or modify it under
the
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR
+ * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+
+import SwiftUI
+
+struct PendingView: View {
+ @ObservedObject var pendingManager: PendingManager
+
+ var showSidebar: () -> Void
+ var body: some View {
+ NavigationView {
+ if pendingManager.items == nil {
+ ProgressView()
+ .navigationTitle("Pending")
+ .navigationBarItems(
+ leading: Button(action: self.showSidebar, label: {
+ Image(systemName: "line.3.horizontal")
+ }))
+ .onAppear {
+ pendingManager.update()
+ }
+ } else if pendingManager.loading {
+ ProgressView()
+ .navigationTitle("Pending")
+ .navigationBarItems(
+ leading: Button(action: self.showSidebar, label: {
+ Image(systemName: "line.3.horizontal")
+ }))
+ } else {
+ let items = pendingManager.items!
+ List(items, id: \.self) { item in
+ VStack {
+ Text(item)
+ .font(.system(size: 14, design: .monospaced))
+ }
+ }
+ .navigationTitle("Pending")
+ .navigationBarItems(
+ leading: Button(action: self.showSidebar, label: {
+ Image(systemName: "line.3.horizontal")
+ }),
+ trailing: Button(action: {
+ pendingManager.update()
+ }, label: {
+ Image(systemName: "arrow.clockwise")
+ }))
+ }
+ }
+ }
+
+ init(_showSidebar: @escaping () -> Void, pending: PendingManager) {
+ self.showSidebar = _showSidebar
+ self.pendingManager = pending
+ }
+}
diff --git a/Taler/SettingsView.swift b/Taler/Views/SettingsView.swift
similarity index 93%
rename from Taler/SettingsView.swift
rename to Taler/Views/SettingsView.swift
index e1607a0..63c1f3d 100644
--- a/Taler/SettingsView.swift
+++ b/Taler/Views/SettingsView.swift
@@ -15,6 +15,7 @@
*/
import SwiftUI
+import taler_swift
struct TextInputPopup: ViewModifier {
@State var exchangeUrl: String = "https://"
@@ -64,6 +65,18 @@ extension View {
}
}
+struct PromptWithdrawView: View {
+ let exchange: ExchangeItem
+ let amount: Amount
+
+ var body: some View {
+ VStack {
+ Text("Fees or something")
+ }
+ .navigationTitle("Withdraw Digital Cash")
+ }
+}
+
struct WithdrawView: View {
let exchange: ExchangeItem
@State var amount: String = ""
@@ -79,8 +92,14 @@ struct WithdrawView: View {
HStack {
TextField(exchange.currency, text: $amount)
}
- Button {
-
+ NavigationLink {
+ // TODO: Handle when the user inputs a non-valid amount
+ /*do {
+ let am = try Amount.init(fromString: exchange.currency +
":" + amount)
+ PromptWithdrawView(exchange: exchange, amount: am)
+ } catch {
+
+ }*/
} label: {
Text("Check Fees")
}
diff --git a/Taler/WalletBackend.swift b/Taler/WalletBackend.swift
index 2e15c1e..a3f52e6 100644
--- a/Taler/WalletBackend.swift
+++ b/Taler/WalletBackend.swift
@@ -785,6 +785,27 @@ struct WalletBackendSuspendCoinRequest:
WalletBackendFormattedRequest {
}
}
+typealias PendingOperation = AnyCodable
+
+/// A request to list the backend's currently pending operations.
+struct WalletBackendPendingRequest: WalletBackendFormattedRequest {
+ struct Args: Encodable {
+
+ }
+
+ struct Response: Decodable {
+ var pendingOperations: [PendingOperation]
+ }
+
+ func operation() -> String {
+ return "getPendingOperations"
+ }
+
+ func args() -> Args {
+ Args()
+ }
+}
+
/// Errors for `WalletBackend`.
enum WalletBackendError: Error {
/// An error that prevented the wallet from being initialized occurred.
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [taler-taler-ios] branch master updated: pending operations view,
gnunet <=