cake_wallet/lib/reactions/on_current_fiat_change.dart

28 lines
1.1 KiB
Dart
Raw Normal View History

import 'package:cake_wallet/entities/fiat_api_mode.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';
2022-10-12 17:09:57 +00:00
ReactionDisposer? _onCurrentFiatCurrencyChangeDisposer;
2020-09-21 11:50:26 +00:00
2023-12-07 16:44:07 +00:00
void startCurrentFiatChangeReaction(
AppStore appStore, SettingsStore settingsStore, FiatConversionStore fiatConversionStore) {
2022-10-12 17:09:57 +00:00
_onCurrentFiatCurrencyChangeDisposer?.reaction.dispose();
2023-12-07 16:44:07 +00:00
_onCurrentFiatCurrencyChangeDisposer =
reaction((_) => settingsStore.fiatCurrency, (FiatCurrency fiatCurrency) async {
if (appStore.wallet == null || settingsStore.fiatApiMode == FiatApiMode.disabled) {
2022-10-12 17:09:57 +00:00
return;
}
final cryptoCurrency = appStore.wallet!.currency;
2023-12-07 16:44:07 +00:00
fiatConversionStore.prices[cryptoCurrency] = await FiatConversionService.fetchPrice(
crypto: cryptoCurrency,
fiat: fiatCurrency,
apiMode: settingsStore.fiatApiMode,
);
2020-09-21 11:50:26 +00:00
});
}