diff options
author | Marc Stibane <marc@taler.net> | 2024-02-08 17:46:38 +0100 |
---|---|---|
committer | Marc Stibane <marc@taler.net> | 2024-02-08 17:46:38 +0100 |
commit | 17e0e92b012c3fe08c6bb58b3f3044fe0df93d58 (patch) | |
tree | 92bd3fc92086232307baf32acf2efed06a9ae921 | |
parent | 2f0716816f4c25cbd52111eefaba4b69e9e3e8d8 (diff) | |
download | taler-ios-17e0e92b012c3fe08c6bb58b3f3044fe0df93d58.tar.gz taler-ios-17e0e92b012c3fe08c6bb58b3f3044fe0df93d58.tar.bz2 taler-ios-17e0e92b012c3fe08c6bb58b3f3044fe0df93d58.zip |
static func <
-rw-r--r-- | TalerWallet1/Backend/WalletBackendRequest.swift | 24 | ||||
-rw-r--r-- | TalerWallet1/Model/Model+Exchange.swift | 9 |
2 files changed, 33 insertions, 0 deletions
diff --git a/TalerWallet1/Backend/WalletBackendRequest.swift b/TalerWallet1/Backend/WalletBackendRequest.swift index 6a5ef20..19bee0b 100644 --- a/TalerWallet1/Backend/WalletBackendRequest.swift +++ b/TalerWallet1/Backend/WalletBackendRequest.swift @@ -34,6 +34,30 @@ struct ScopeInfo: Codable, Hashable { var url: String? // only for "exchange" var currency: String // 3-char ISO 4217 code for global currency. Regional MUST be >= 4 letters + public static func < (lhs: ScopeInfo, rhs: ScopeInfo) -> Bool { + if lhs.type == .global { + if rhs.type == .global { // both global ==> alphabetic currency + return lhs.currency < rhs.currency + } + return true // global comes first + } + if rhs.type == .global { + return false // global comes first + } + if lhs.currency == rhs.currency { + if let lhsBaseURL = lhs.url { + if let rhsBaseURL = rhs.url { + return lhsBaseURL < rhsBaseURL + } + return true + } + if let rhsBaseURL = rhs.url { + return false + } + // fall thru + } + return lhs.currency < rhs.currency + } public static func == (lhs: ScopeInfo, rhs: ScopeInfo) -> Bool { if let lhsBaseURL = lhs.url { if let rhsBaseURL = rhs.url { diff --git a/TalerWallet1/Model/Model+Exchange.swift b/TalerWallet1/Model/Model+Exchange.swift index 5b362f0..6de9b6a 100644 --- a/TalerWallet1/Model/Model+Exchange.swift +++ b/TalerWallet1/Model/Model+Exchange.swift @@ -29,6 +29,15 @@ enum ExchangeUpdateStatus: String, Codable { // MARK: - /// The result from wallet-core's ListExchanges struct Exchange: Codable, Hashable, Identifiable { + static func < (lhs: Exchange, rhs: Exchange) -> Bool { + if let leftScope = lhs.scopeInfo { + if let rightScope = rhs.scopeInfo { + return leftScope < rightScope + } + return true // scopeInfo comes first + } + return false + } static func == (lhs: Exchange, rhs: Exchange) -> Bool { return lhs.exchangeBaseUrl == rhs.exchangeBaseUrl && lhs.tosStatus == rhs.tosStatus |