historical rate update reaction

This commit is contained in:
Serhii 2024-05-03 15:56:49 +03:00
parent ba3ef5c2b4
commit 415c39a924
4 changed files with 19 additions and 3 deletions

View file

@ -80,7 +80,7 @@ Future<double?> _fetchHistoricalPrice(Map<String, dynamic> args) async {
final data = json.decode(response.body) as Map<String, dynamic>;
final errors = data['errors'] as Map<String, dynamic>;
if (errors.isNotEmpty) return 0.0;
if (errors.isNotEmpty) return null;
final results = data['results'] as Map<String, dynamic>;

View file

@ -36,6 +36,7 @@ Future<void> bootstrap(GlobalKey<NavigatorState> 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);
}

View file

@ -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> 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> 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);
});
}

View file

@ -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));
}