taler-ios

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

commit fa93599052d1eb19046a3a3952636b83eaaaa0e9
parent 1dfae8887cad2631fa2b13af8c8fea31867da1c3
Author: Marc Stibane <marc@taler.net>
Date:   Fri, 20 Oct 2023 08:51:58 +0200

listExchangesForScopedCurrency

Diffstat:
MTalerWallet1/Model/Model+Exchange.swift | 32++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+), 0 deletions(-)

diff --git a/TalerWallet1/Model/Model+Exchange.swift b/TalerWallet1/Model/Model+Exchange.swift @@ -75,7 +75,27 @@ struct ExchangeListItem: Codable, Hashable { hasher.combine(paytoUris) } } + +struct ExchangeUrlItem: Codable, Hashable, Identifiable { + var exchangeBaseUrl: String + var id: String { exchangeBaseUrl } +} // MARK: - +/// A request to list exchanges names for a currency +fileprivate struct ListExchangesForScopedCurrency: WalletBackendFormattedRequest { + func operation() -> String { "listExchangesForScopedCurrency" } + func args() -> Args { Args(scope: scope) } + + var scope: ScopeInfo + + struct Args: Encodable { + var scope: ScopeInfo + } + struct Response: Decodable, Sendable { + var exchanges: [ExchangeUrlItem] // list of Exchange names + } +} + /// A request to list exchanges. fileprivate struct ListExchanges: WalletBackendFormattedRequest { func operation() -> String { "listExchanges" } @@ -129,6 +149,18 @@ fileprivate struct GetCurrencySpecification: WalletBackendFormattedRequest { // MARK: - extension WalletModel { /// ask wallet-core for its list of known exchanges + @MainActor func listExchangesForScopedCurrencyM(scope: ScopeInfo) + async -> [ExchangeUrlItem] { // M for MainActor + do { + let request = ListExchangesForScopedCurrency(scope: scope) + let response = try await sendRequest(request, ASYNCDELAY) + return response.exchanges + } catch { + return [] // empty, but not nil + } + } + + /// ask wallet-core for its list of known exchanges @MainActor func listExchangesM() async -> [Exchange] { // M for MainActor do {