Add support for manual price entry
This commit is contained in:
18
SatsPrice/Network/ManualPriceFetcher.swift
Normal file
18
SatsPrice/Network/ManualPriceFetcher.swift
Normal file
@@ -0,0 +1,18 @@
|
||||
//
|
||||
// ManualPriceFetcher.swift
|
||||
// SatsPrice
|
||||
//
|
||||
// Created by Terry Yiu on 8/29/24.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import BigDecimal
|
||||
|
||||
/// Fake price fetcher that returns a randomized price. Useful for development testing without requiring a network call.
|
||||
class ManualPriceFetcher: PriceFetcher {
|
||||
var price: BigDecimal = 1
|
||||
|
||||
func btcToUsd() async throws -> BigDecimal? {
|
||||
return price
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import BigDecimal
|
||||
class PriceFetcherDelegator: PriceFetcher {
|
||||
private let coinbasePriceFetcher = CoinbasePriceFetcher()
|
||||
private let coinGeckoPriceFetcher = CoinGeckoPriceFetcher()
|
||||
private let manualPriceFetcher = ManualPriceFetcher()
|
||||
#if DEBUG
|
||||
private let fakePriceFetcher = FakePriceFetcher()
|
||||
#endif
|
||||
@@ -27,6 +28,8 @@ class PriceFetcherDelegator: PriceFetcher {
|
||||
coinbasePriceFetcher
|
||||
case .coingecko:
|
||||
coinGeckoPriceFetcher
|
||||
case .manual:
|
||||
manualPriceFetcher
|
||||
#if DEBUG
|
||||
case .fake:
|
||||
fakePriceFetcher
|
||||
|
||||
@@ -11,14 +11,15 @@ enum PriceSource: CaseIterable, CustomStringConvertible {
|
||||
|
||||
static var allCases: [PriceSource] {
|
||||
#if DEBUG
|
||||
[.coinbase, .coingecko, .fake]
|
||||
[.coinbase, .coingecko, .manual, .fake]
|
||||
#else
|
||||
[.coinbase, .coingecko]
|
||||
[.coinbase, .coingecko, .manual]
|
||||
#endif
|
||||
}
|
||||
|
||||
case coinbase
|
||||
case coingecko
|
||||
case manual
|
||||
|
||||
#if DEBUG
|
||||
case fake
|
||||
@@ -30,6 +31,8 @@ enum PriceSource: CaseIterable, CustomStringConvertible {
|
||||
"Coinbase"
|
||||
case .coingecko:
|
||||
"CoinGecko"
|
||||
case .manual:
|
||||
"Manual"
|
||||
#if DEBUG
|
||||
case .fake:
|
||||
"Fake"
|
||||
|
||||
Reference in New Issue
Block a user