cake_wallet/lib/reactions/on_current_fiat_api_mode_change.dart

49 lines
2.1 KiB
Dart
Raw Normal View History

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';
import 'package:mobx/mobx.dart';
import 'package:cake_wallet/core/fiat_conversion_service.dart';
import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart';
import 'package:cake_wallet/store/settings_store.dart';
import 'package:cake_wallet/store/app_store.dart';
2024-05-03 08:46:41 +00:00
import 'fiat_historical_rate_update.dart';
ReactionDisposer? _onCurrentFiatCurrencyChangeDisposer;
2024-05-03 12:56:49 +00:00
ReactionDisposer? _onHistoricalRateUpdateDisposer;
2024-05-03 08:46:41 +00:00
void startCurrentFiatApiModeChangeReaction(AppStore appStore, SettingsStore settingsStore,
FiatConversionStore fiatConversionStore, Box<TransactionDescription> transactionDescription) {
_onCurrentFiatCurrencyChangeDisposer?.reaction.dispose();
2024-05-03 08:46:41 +00:00
_onCurrentFiatCurrencyChangeDisposer =
reaction((_) => settingsStore.fiatApiMode, (FiatApiMode fiatApiMode) async {
if (appStore.wallet == null || fiatApiMode == FiatApiMode.disabled) {
return;
}
2024-05-03 08:46:41 +00:00
fiatConversionStore.prices[appStore.wallet!.currency] = await FiatConversionService.fetchPrice(
crypto: appStore.wallet!.currency,
fiat: settingsStore.fiatCurrency,
torOnly: 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
}
2024-05-03 12:56:49 +00:00
});
}
void startHistoricalRateUpdateReaction(AppStore appStore, SettingsStore settingsStore,
FiatConversionStore fiatConversionStore, Box<TransactionDescription> transactionDescription) {
_onHistoricalRateUpdateDisposer?.reaction.dispose();
_onHistoricalRateUpdateDisposer = reaction((_) => settingsStore.showHistoricalFiatAmount,
(bool showHistoricalFiatAmount) async {
2024-05-08 13:28:28 +00:00
if (appStore.wallet == null || settingsStore.fiatApiMode == FiatApiMode.disabled || !showHistoricalFiatAmount) {
2024-05-03 12:56:49 +00:00
return;
}
2024-05-03 08:46:41 +00:00
2024-05-03 12:56:49 +00:00
await historicalRateUpdate(
2024-05-03 13:39:27 +00:00
appStore.wallet!, settingsStore, fiatConversionStore, transactionDescription);
});
}