2022-12-07 22:11:09 +00:00
|
|
|
import 'package:cake_wallet/entities/fiat_api_mode.dart';
|
2024-05-03 08:46:41 +00:00
|
|
|
import 'package:cake_wallet/entities/transaction_description.dart';
|
|
|
|
import 'package:hive/hive.dart';
|
2020-09-21 11:50:26 +00:00
|
|
|
import 'package:mobx/mobx.dart';
|
2020-10-30 13:56:23 +00:00
|
|
|
import 'package:cake_wallet/core/fiat_conversion_service.dart';
|
|
|
|
import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart';
|
2020-09-21 11:50:26 +00:00
|
|
|
import 'package:cake_wallet/store/settings_store.dart';
|
|
|
|
import 'package:cake_wallet/store/app_store.dart';
|
|
|
|
import 'package:cake_wallet/entities/fiat_currency.dart';
|
|
|
|
|
2024-05-03 08:46:41 +00:00
|
|
|
import 'fiat_historical_rate_update.dart';
|
|
|
|
|
2022-10-12 17:09:57 +00:00
|
|
|
ReactionDisposer? _onCurrentFiatCurrencyChangeDisposer;
|
2020-09-21 11:50:26 +00:00
|
|
|
|
2024-05-03 08:46:41 +00:00
|
|
|
void startCurrentFiatChangeReaction(AppStore appStore, SettingsStore settingsStore,
|
|
|
|
FiatConversionStore fiatConversionStore, Box<TransactionDescription> transactionDescription) {
|
2022-10-12 17:09:57 +00:00
|
|
|
_onCurrentFiatCurrencyChangeDisposer?.reaction.dispose();
|
2024-05-03 08:46:41 +00:00
|
|
|
_onCurrentFiatCurrencyChangeDisposer =
|
|
|
|
reaction((_) => settingsStore.fiatCurrency, (FiatCurrency fiatCurrency) async {
|
2022-12-07 22:11:09 +00:00
|
|
|
if (appStore.wallet == null || settingsStore.fiatApiMode == FiatApiMode.disabled) {
|
2022-10-12 17:09:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-05-03 08:46:41 +00:00
|
|
|
|
2022-10-12 17:09:57 +00:00
|
|
|
final cryptoCurrency = appStore.wallet!.currency;
|
2024-05-03 08:46:41 +00:00
|
|
|
fiatConversionStore.prices[cryptoCurrency] = await FiatConversionService.fetchPrice(
|
|
|
|
crypto: cryptoCurrency,
|
|
|
|
fiat: fiatCurrency,
|
|
|
|
torOnly: settingsStore.fiatApiMode == FiatApiMode.torOnly);
|
|
|
|
|
|
|
|
if (settingsStore.showHistoricalFiatAmount) {
|
|
|
|
await historicalRateUpdate(
|
2024-05-03 13:39:27 +00:00
|
|
|
appStore.wallet!, settingsStore, fiatConversionStore, transactionDescription);
|
2024-05-03 08:46:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
});
|
2020-12-15 16:29:10 +00:00
|
|
|
}
|