taler-ios

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

commit 1ac17f16f70c36a248015b3cfe20169bd7b0359b
parent 5527a4ec55507601b056eed492469ec02bb92613
Author: Marc Stibane <marc@taler.net>
Date:   Tue, 10 Mar 2026 15:02:25 +0100

getDefaultExchanges

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

diff --git a/TalerWallet1/Model/Model+Exchange.swift b/TalerWallet1/Model/Model+Exchange.swift @@ -127,6 +127,17 @@ struct Exchange: Codable, Hashable, Identifiable { } } // MARK: - +struct DefaultExchange: Codable { + var talerUri: String // taler://withdraw-exchange/exchange.taler-ops.ch/ + var currency: String // CHF + var currencySpec: CurrencySpecification // .name = "Swiss Francs"... alt_unit_names":{"0":"Fr.","-2":"Rp."} +// var restrictions: [String] // ["Swiss bank accounts only"] +} +extension DefaultExchange: Identifiable { + var id: String { talerUri } + +} +// MARK: - /// A request to list exchanges names for a currency fileprivate struct ListExchanges: WalletBackendFormattedRequest { func operation() -> String { "listExchanges" } @@ -143,6 +154,17 @@ fileprivate struct ListExchanges: WalletBackendFormattedRequest { } } +fileprivate struct DefaultExchanges: WalletBackendFormattedRequest { + func operation() -> String { "getDefaultExchanges" } + func args() -> Args { Args() } + + struct Args: Encodable {} // no arguments needed + + struct Response: Decodable { // list of known exchanges + var defaultExchanges: [DefaultExchange] + } +} + /// A request to get info for one exchange. fileprivate struct GetExchangeByUrl: WalletBackendFormattedRequest { func operation() -> String { "getExchangeEntryByUrl" } @@ -257,6 +279,18 @@ extension WalletModel { } } + /// ask wallet-core for its list of default exchanges ==> currently only taler-ops.ch + nonisolated func getDefaultExchanges(viewHandles: Bool = false) + async -> [DefaultExchange] { // M for MainActor + do { + let request = DefaultExchanges() + let response = try await sendRequest(request, viewHandles: viewHandles) + return response.defaultExchanges + } catch { + return [] // empty, but not nil + } + } + /// add a new exchange with URL to the wallet's list of known exchanges nonisolated func getExchangeByUrl(url: String, viewHandles: Bool = false) async throws -> Exchange {