| 1 | import 'package:cake_wallet/entities/fiat_api_mode.dart'; |
| 2 | import 'package:mobx/mobx.dart'; |
| 3 | import 'package:cake_wallet/core/fiat_conversion_service.dart'; |
| 4 | import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart'; |
| 5 | import 'package:cake_wallet/store/settings_store.dart'; |
| 6 | import 'package:cake_wallet/store/app_store.dart'; |
| 7 | |
| 8 | ReactionDisposer? _onCurrentFiatCurrencyChangeDisposer; |
| 9 | |
| 10 | void startCurrentFiatApiModeChangeReaction( |
| 11 | AppStore appStore, SettingsStore settingsStore, FiatConversionStore fiatConversionStore) { |
| 12 | _onCurrentFiatCurrencyChangeDisposer?.reaction.dispose(); |
| 13 | _onCurrentFiatCurrencyChangeDisposer = |
| 14 | reaction((_) => settingsStore.fiatApiMode, (FiatApiMode fiatApiMode) async { |
| 15 | if (appStore.wallet == null || fiatApiMode == FiatApiMode.disabled) { |
| 16 | return; |
| 17 | } |
| 18 | |
| 19 | fiatConversionStore.prices[appStore.wallet!.currency] = await FiatConversionService.fetchPrice( |
| 20 | crypto: appStore.wallet!.currency, |
| 21 | fiat: settingsStore.fiatCurrency, |
| 22 | torOnly: fiatApiMode == FiatApiMode.torOnly); |
| 23 | }); |
| 24 | } |