mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-03 17:40:43 +00:00
reduce API calls
This commit is contained in:
parent
97877c4c7f
commit
d8c1e14020
3 changed files with 24 additions and 27 deletions
|
@ -38,7 +38,7 @@ void startHistoricalRateUpdateReaction(AppStore appStore, SettingsStore settings
|
|||
_onHistoricalRateUpdateDisposer?.reaction.dispose();
|
||||
_onHistoricalRateUpdateDisposer = reaction((_) => settingsStore.showHistoricalFiatAmount,
|
||||
(bool showHistoricalFiatAmount) async {
|
||||
if (appStore.wallet == null || settingsStore.fiatApiMode == FiatApiMode.disabled) {
|
||||
if (appStore.wallet == null || settingsStore.fiatApiMode == FiatApiMode.disabled || !showHistoricalFiatAmount) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -112,11 +112,6 @@ void startCurrentWalletChangeReaction(
|
|||
return;
|
||||
}
|
||||
|
||||
if (settingsStore.showHistoricalFiatAmount) {
|
||||
await historicalRateUpdate(
|
||||
appStore.wallet!, settingsStore, fiatConversionStore, transactionDescription);
|
||||
}
|
||||
|
||||
fiatConversionStore.prices[wallet.currency] = 0;
|
||||
fiatConversionStore.prices[wallet.currency] = await FiatConversionService.fetchPrice(
|
||||
crypto: wallet.currency,
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:cake_wallet/entities/fiat_api_mode.dart';
|
||||
import 'package:cake_wallet/entities/transaction_description.dart';
|
||||
import 'package:cake_wallet/entities/update_haven_rate.dart';
|
||||
|
@ -16,6 +18,7 @@ import 'package:wakelock_plus/wakelock_plus.dart';
|
|||
import 'fiat_historical_rate_update.dart';
|
||||
|
||||
ReactionDisposer? _onWalletSyncStatusChangeReaction;
|
||||
Timer? _debounceTimer;
|
||||
|
||||
void startWalletSyncStatusChangeReaction(
|
||||
WalletBase<Balance, TransactionHistoryBase<TransactionInfo>, TransactionInfo> wallet,
|
||||
|
@ -23,11 +26,10 @@ void startWalletSyncStatusChangeReaction(
|
|||
SettingsStore settingsStore,
|
||||
Box<TransactionDescription> transactionDescription) {
|
||||
_onWalletSyncStatusChangeReaction?.reaction.dispose();
|
||||
|
||||
_onWalletSyncStatusChangeReaction = reaction((_) => wallet.syncStatus, (SyncStatus status) async {
|
||||
try {
|
||||
if (status is ConnectedSyncStatus) {
|
||||
await wallet.startSync();
|
||||
|
||||
if (wallet.type == WalletType.haven) {
|
||||
await updateHavenRate(fiatConversionStore);
|
||||
}
|
||||
|
@ -38,15 +40,15 @@ void startWalletSyncStatusChangeReaction(
|
|||
if (status is SyncedSyncStatus || status is FailedSyncStatus) {
|
||||
await WakelockPlus.disable();
|
||||
|
||||
if (settingsStore.fiatApiMode != FiatApiMode.disabled) {
|
||||
if (settingsStore.showHistoricalFiatAmount) {
|
||||
if (status is SyncedSyncStatus &&
|
||||
(settingsStore.fiatApiMode != FiatApiMode.disabled ||
|
||||
settingsStore.showHistoricalFiatAmount)) {
|
||||
_debounceTimer?.cancel();
|
||||
_debounceTimer = Timer(Duration(milliseconds: 200), () async {
|
||||
await historicalRateUpdate(
|
||||
wallet, settingsStore, fiatConversionStore, transactionDescription);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
print(e.toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue