CakeWallet/lib/reactions/on_current_fiat_change.dart

24 lines
968 B
Dart
Raw Normal View History

2020-09-21 14:50:26 +03:00
import 'package:mobx/mobx.dart';
2020-10-30 15:56:23 +02:00
import 'package:cake_wallet/core/fiat_conversion_service.dart';
import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart';
2020-09-21 14:50:26 +03: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';
2022-10-12 13:09:57 -04:00
ReactionDisposer? _onCurrentFiatCurrencyChangeDisposer;
2020-09-21 14:50:26 +03:00
void startCurrentFiatChangeReaction(AppStore appStore,
SettingsStore settingsStore, FiatConversionStore fiatConversionStore) {
2022-10-12 13:09:57 -04:00
_onCurrentFiatCurrencyChangeDisposer?.reaction.dispose();
2020-09-21 14:50:26 +03:00
_onCurrentFiatCurrencyChangeDisposer = reaction(
(_) => settingsStore.fiatCurrency, (FiatCurrency fiatCurrency) async {
2022-10-12 13:09:57 -04:00
if (appStore.wallet == null) {
return;
}
final cryptoCurrency = appStore.wallet!.currency;
fiatConversionStore.prices[appStore.wallet!.currency] =
await FiatConversionService.fetchPrice(cryptoCurrency, fiatCurrency);
2020-09-21 14:50:26 +03:00
});
}