Add PriceFetcher API to fetch prices of multiple currencies
This commit is contained in:
@@ -12,9 +12,19 @@ import Foundation
|
||||
|
||||
/// Fake price fetcher that returns a randomized price. Useful for development testing without requiring a network call.
|
||||
class ManualPriceFetcher: PriceFetcher {
|
||||
var price: Decimal = Decimal(1)
|
||||
var prices: [Locale.Currency: Decimal] = [:]
|
||||
|
||||
func convertBTC(toCurrency currency: Locale.Currency) async throws -> Decimal? {
|
||||
return price
|
||||
prices[currency]
|
||||
}
|
||||
|
||||
func convertBTC(toCurrencies currencies: [Locale.Currency]) async throws -> [Locale.Currency : Decimal] {
|
||||
guard !currencies.isEmpty else {
|
||||
return [:]
|
||||
}
|
||||
|
||||
let filteredCurrencies = currencies.filter { prices.keys.contains($0) }
|
||||
let priceValues = filteredCurrencies.map { prices[$0, default: Decimal(0)] }
|
||||
return Dictionary(uniqueKeysWithValues: zip(filteredCurrencies, priceValues))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user