| 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 | import 'package:cake_wallet/entities/fiat_currency.dart'; |
| 8 | |
| 9 | ReactionDisposer? _onCurrentFiatCurrencyChangeDisposer; |
| 10 | |
| 11 | void startCurrentFiatChangeReaction( |
| 12 | AppStore appStore, SettingsStore settingsStore, FiatConversionStore fiatConversionStore) { |
| 13 | _onCurrentFiatCurrencyChangeDisposer?.reaction.dispose(); |
| 14 | _onCurrentFiatCurrencyChangeDisposer = |
| 15 | reaction((_) => settingsStore.fiatCurrency, (FiatCurrency fiatCurrency) async { |
| 16 | if (appStore.wallet == null || settingsStore.fiatApiMode == FiatApiMode.disabled) { |
| 17 | return; |
| 18 | } |
| 19 | |
| 20 | final cryptoCurrency = appStore.wallet!.currency; |
| 21 | fiatConversionStore.prices[cryptoCurrency] = await FiatConversionService.fetchPrice( |
| 22 | crypto: cryptoCurrency, |
| 23 | fiat: fiatCurrency, |
| 24 | torOnly: settingsStore.fiatApiMode == FiatApiMode.torOnly); |
| 25 | }); |
| 26 | } |