commit b400eca391e2fffb1b476143e2eb12803ee56726
parent e4c17bc62139bc107417b55f58af642e09a912c5
Author: Marc Stibane <marc@taler.net>
Date: Sat, 28 Sep 2024 08:26:29 +0200
filterByState
Diffstat:
2 files changed, 28 insertions(+), 8 deletions(-)
diff --git a/TalerWallet1/Model/Model+Transactions.swift b/TalerWallet1/Model/Model+Transactions.swift
@@ -22,22 +22,31 @@ extension WalletModel {
}
// MARK: -
+
+enum TransactionStateFilter: String, Codable {
+ case done
+ case final // done, aborted, expired, ...
+ case nonfinal // pending, dialog, suspended, aborting
+}
+
/// A request to get the transactions in the wallet's history.
fileprivate struct GetTransactions: WalletBackendFormattedRequest {
func operation() -> String { "getTransactions" }
// func operation() -> String { "testingGetSampleTransactions" }
- func args() -> Args { Args(scopeInfo: scopeInfo, currency: currency, search: search, sort: sort, includeRefreshes: includeRefreshes) }
-
+ func args() -> Args { Args(scopeInfo: scopeInfo, currency: currency, search: search,
+ sort: sort, filterByState: filterByState, includeRefreshes: includeRefreshes) }
var scopeInfo: ScopeInfo?
var currency: String?
var search: String?
var sort: String?
+ var filterByState: TransactionStateFilter?
var includeRefreshes: Bool?
struct Args: Encodable {
var scopeInfo: ScopeInfo?
var currency: String?
var search: String?
var sort: String?
+ var filterByState: TransactionStateFilter?
var includeRefreshes: Bool?
}
@@ -104,16 +113,21 @@ struct ResumeTransaction: WalletBackendFormattedRequest {
extension WalletModel {
/// ask wallet-core for its list of transactions filtered by searchString
func transactionsT(_ stack: CallStack, scopeInfo: ScopeInfo, searchString: String? = nil,
- sort: String = "descending", includeRefreshes: Bool = false, viewHandles: Bool = false)
+ sort: String = "descending", filterByState: TransactionStateFilter? = nil,
+ includeRefreshes: Bool = false, viewHandles: Bool = false)
async throws -> [Transaction] {
- let request = GetTransactions(scopeInfo: scopeInfo, currency: scopeInfo.currency, search: searchString, sort: sort, includeRefreshes: includeRefreshes)
+ let request = GetTransactions(scopeInfo: scopeInfo, currency: scopeInfo.currency, search: searchString,
+ sort: sort, filterByState: filterByState, includeRefreshes: includeRefreshes)
let response = try await sendRequest(request, ASYNCDELAY, viewHandles: viewHandles)
return response.transactions
}
/// fetch transactions from Wallet-Core. No networking involved
- @MainActor func transactionsMA(_ stack: CallStack, scopeInfo: ScopeInfo, searchString: String? = nil, sort: String = "descending", viewHandles: Bool = false)
+ @MainActor func transactionsMA(_ stack: CallStack, scopeInfo: ScopeInfo, searchString: String? = nil,
+ sort: String = "descending", filterByState: TransactionStateFilter? = nil,
+ viewHandles: Bool = false)
async throws -> [Transaction] { // M for MainActor
- return try await transactionsT(stack.push(), scopeInfo: scopeInfo, searchString: searchString, sort: sort, viewHandles: viewHandles)
+ return try await transactionsT(stack.push(), scopeInfo: scopeInfo, searchString: searchString,
+ sort: sort, filterByState: filterByState, viewHandles: viewHandles)
}
/// abort the specified transaction from Wallet-Core. No networking involved
diff --git a/TalerWallet1/Views/Balances/BalancesSectionView.swift b/TalerWallet1/Views/Balances/BalancesSectionView.swift
@@ -60,13 +60,19 @@ struct BalancesSectionView {
@State private var shownSectionID = UUID() // guaranteed to be different the first time
func reloadCompleted(_ stack: CallStack) async -> () {
- if let transactions = try? await model.transactionsT(stack.push(), scopeInfo: balance.scopeInfo, includeRefreshes: developerMode) {
+ if let transactions = try? await model.transactionsT(stack.push(),
+ scopeInfo: balance.scopeInfo,
+// filterByState: .final, // TODO: .final
+ includeRefreshes: false) {
completedTransactions = WalletModel.completedTransactions(transactions)
}
}
func reloadPending(_ stack: CallStack) async -> () {
- if let transactions = try? await model.transactionsT(stack.push(), scopeInfo: balance.scopeInfo, includeRefreshes: developerMode) {
+ if let transactions = try? await model.transactionsT(stack.push(),
+ scopeInfo: balance.scopeInfo,
+ filterByState: .nonfinal,
+ includeRefreshes: developerMode) {
pendingTransactions = WalletModel.pendingTransactions(transactions)
}
}