mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-26 06:08:40 +01:00
34 lines
1.0 KiB
Dart
34 lines
1.0 KiB
Dart
import "package:cake_wallet/new-ui/model/charts/price_api_client.dart";
|
|
import 'package:cw_core/crypto_currency.dart';
|
|
import 'package:cake_wallet/entities/fiat_currency.dart';
|
|
|
|
/// Override specific [CryptoCurrency] to fix its price to the price of another
|
|
/// e.g. nDEPS should have the same price as DEPS, but only DEPS is tracked
|
|
CryptoCurrency _overrideCryptoCurrency(CryptoCurrency crypto) {
|
|
if (crypto.title == CryptoCurrency.ndeps.title) return CryptoCurrency.deps;
|
|
return crypto;
|
|
}
|
|
|
|
class FiatConversionService {
|
|
static Future<double> fetchPrice({
|
|
required CryptoCurrency crypto,
|
|
required FiatCurrency fiat,
|
|
required bool torOnly,
|
|
}) async {
|
|
try {
|
|
return double.parse((await PriceApiClient.getLatestPrice(
|
|
LatestPriceRequest(
|
|
from: _overrideCryptoCurrency(crypto),
|
|
to: fiat,
|
|
),
|
|
torOnly: torOnly,
|
|
))
|
|
?.quote
|
|
.toString() ??
|
|
"0");
|
|
} catch (e) {
|
|
return 0.0;
|
|
}
|
|
}
|
|
}
|