diff --git a/lib/core/fiat_conversion_service.dart b/lib/core/fiat_conversion_service.dart index e2fbd15af..822cf4563 100644 --- a/lib/core/fiat_conversion_service.dart +++ b/lib/core/fiat_conversion_service.dart @@ -80,7 +80,7 @@ Future _fetchHistoricalPrice(Map args) async { final data = json.decode(response.body) as Map; final errors = data['errors'] as Map; - if (errors.isNotEmpty) return 0.0; + if (errors.isNotEmpty) return null; final results = data['results'] as Map; diff --git a/lib/reactions/bootstrap.dart b/lib/reactions/bootstrap.dart index 6bab7f96b..9439f029a 100644 --- a/lib/reactions/bootstrap.dart +++ b/lib/reactions/bootstrap.dart @@ -36,6 +36,7 @@ Future bootstrap(GlobalKey navigatorKey) async { appStore, settingsStore, fiatConversionStore, transactionDescription); startCurrentFiatChangeReaction(appStore, settingsStore, fiatConversionStore, transactionDescription); startCurrentFiatApiModeChangeReaction(appStore, settingsStore, fiatConversionStore, transactionDescription); + startHistoricalRateUpdateReaction(appStore, settingsStore, fiatConversionStore, transactionDescription); startOnCurrentNodeChangeReaction(appStore); startFiatRateUpdate(appStore, settingsStore, fiatConversionStore); } diff --git a/lib/reactions/on_current_fiat_api_mode_change.dart b/lib/reactions/on_current_fiat_api_mode_change.dart index cb76e15f8..6b063a71f 100644 --- a/lib/reactions/on_current_fiat_api_mode_change.dart +++ b/lib/reactions/on_current_fiat_api_mode_change.dart @@ -10,6 +10,7 @@ import 'package:cake_wallet/store/app_store.dart'; import 'fiat_historical_rate_update.dart'; ReactionDisposer? _onCurrentFiatCurrencyChangeDisposer; +ReactionDisposer? _onHistoricalRateUpdateDisposer; void startCurrentFiatApiModeChangeReaction(AppStore appStore, SettingsStore settingsStore, FiatConversionStore fiatConversionStore, Box transactionDescription) { @@ -29,6 +30,19 @@ void startCurrentFiatApiModeChangeReaction(AppStore appStore, SettingsStore sett await historicalRateUpdate( appStore, settingsStore, fiatConversionStore, transactionDescription); } - + }); +} + +void startHistoricalRateUpdateReaction(AppStore appStore, SettingsStore settingsStore, + FiatConversionStore fiatConversionStore, Box transactionDescription) { + _onHistoricalRateUpdateDisposer?.reaction.dispose(); + _onHistoricalRateUpdateDisposer = reaction((_) => settingsStore.showHistoricalFiatAmount, + (bool showHistoricalFiatAmount) async { + if (appStore.wallet == null || settingsStore.fiatApiMode == FiatApiMode.disabled) { + return; + } + + await historicalRateUpdate( + appStore, settingsStore, fiatConversionStore, transactionDescription); }); } diff --git a/lib/src/screens/dashboard/pages/transactions_page.dart b/lib/src/screens/dashboard/pages/transactions_page.dart index 9694322dc..691ae7f10 100644 --- a/lib/src/screens/dashboard/pages/transactions_page.dart +++ b/lib/src/screens/dashboard/pages/transactions_page.dart @@ -98,7 +98,8 @@ class TransactionsPage extends StatelessWidget { formattedAmount: item.formattedCryptoAmount, formattedFiatAmount: dashboardViewModel.balanceViewModel.isFiatDisabled ? '' : formattedFiatValue, isPending: transaction.isPending, - isHistoricalRate: dashboardViewModel.settingsStore.showHistoricalFiatAmount, + isHistoricalRate: dashboardViewModel.settingsStore.showHistoricalFiatAmount && + historicalFiatValue !=null && historicalFiatValue.isNotEmpty, title: item.formattedTitle + item.formattedStatus)); }