cake_wallet/lib/entities/update_haven_rate.dart

26 lines
855 B
Dart
Raw Normal View History

2022-03-30 15:57:04 +00:00
import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart';
import 'package:cw_core/crypto_currency.dart';
import 'package:cw_core/monero_amount_format.dart';
2022-04-07 11:19:10 +00:00
import 'package:cake_wallet/haven/haven.dart';
2022-03-30 15:57:04 +00:00
Future<void> updateHavenRate(FiatConversionStore fiatConversionStore) async {
2022-10-12 17:09:57 +00:00
try {
final rate = haven!.getAssetRate();
final base = rate.firstWhere((row) => row.asset == 'XUSD');
2022-03-30 15:57:04 +00:00
2022-10-12 17:09:57 +00:00
rate.forEach((row) {
final cur = CryptoCurrency.fromString(row.asset);
final baseRate = moneroAmountToDouble(amount: base.rate);
final rowRate = moneroAmountToDouble(amount: row.rate);
2022-03-30 15:57:04 +00:00
2022-10-12 17:09:57 +00:00
if (cur == CryptoCurrency.xusd) {
fiatConversionStore.prices[cur] = 1.0;
return;
}
fiatConversionStore.prices[cur] = baseRate / rowRate;
});
} catch(_) {
// FIX-ME: handle exception
}
2022-03-30 15:57:04 +00:00
}