mirror of
https://github.com/aljazceru/breez-sdk-docs.git
synced 2025-12-17 05:44:20 +01:00
move swift examples (#100)
* move swift examples * swift workflow * fixup * rewirte gettingStarted * add README for swift * update fiat examples and addresss feedback
This commit is contained in:
48
snippets/swift/BreezSDKExamples/Sources/FiatCurrencies.swift
Normal file
48
snippets/swift/BreezSDKExamples/Sources/FiatCurrencies.swift
Normal file
@@ -0,0 +1,48 @@
|
||||
//
|
||||
// FiatCurrencies.swift
|
||||
//
|
||||
//
|
||||
// Created by ruben on 14/11/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import BreezSDK
|
||||
|
||||
func listSupportedFiatCurrencies(sdk: BlockingBreezServices) -> [FiatCurrency]? {
|
||||
// ANCHOR: list-fiat-currencies
|
||||
let supportedFiatCurrencies = try? sdk.listFiatCurrencies()
|
||||
// ANCHOR_END: list-fiat-currencies
|
||||
return supportedFiatCurrencies
|
||||
}
|
||||
|
||||
func getCurrentRates(sdk:BlockingBreezServices) -> [Rate]? {
|
||||
// ANCHOR: fetch-fiat-rates
|
||||
let fiatRates = try? sdk.fetchFiatRates()
|
||||
// ANCHOR_END: fetch-fiat-rates
|
||||
return fiatRates
|
||||
}
|
||||
|
||||
func getFiatCurrencyAndRates(sdk: BlockingBreezServices) -> [(FiatCurrency,Rate)]? {
|
||||
// ANCHOR: get-fiat-currencies-and-rates
|
||||
var ratesMap = [String:Rate]()
|
||||
if let supportedFiatCurrencies = try? sdk.listFiatCurrencies(), let fiatRates = try? sdk.fetchFiatRates() {
|
||||
for fiatRate in fiatRates {
|
||||
ratesMap[fiatRate.coin.lowercased()] = fiatRate
|
||||
}
|
||||
|
||||
let sorted = supportedFiatCurrencies.sorted(by: { f1, f2 in
|
||||
f1.id<f2.id
|
||||
})
|
||||
|
||||
var result = [(FiatCurrency,Rate)]()
|
||||
for currency in sorted {
|
||||
if let rate = ratesMap[currency.id.lowercased()] {
|
||||
result.append((currency, rate))
|
||||
}
|
||||
|
||||
}
|
||||
return result
|
||||
}
|
||||
// ANCHOR_END: get-fiat-currencies-and-rates
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user