optimize API calls

This commit is contained in:
Serhii 2023-06-08 13:45:23 +03:00
parent 7ee9f33e5c
commit 8c30ff5adf

View file

@ -138,6 +138,15 @@ abstract class DashboardViewModelBase with Store {
});
reaction((_) => settingsStore.showHistoricalFiatAmount,
(bool showHistoricalFiatAmount) {
if (showHistoricalFiatAmount) {
_wallet.transactionHistory.transactions.values.forEach((tx) {
_getHistoricalFiatRate(tx);
});
}
});
if (_wallet.type == WalletType.monero) {
subname = monero!.getCurrentAccount(_wallet).label;
@ -182,14 +191,12 @@ abstract class DashboardViewModelBase with Store {
settingsStore: appStore.settingsStore),
filter: (TransactionInfo? transaction) {
_wallet.transactionHistory.transactions.values.forEach((tx) {
_getHistoricalFiatRate(tx);
});
if (transaction == null) {
return false;
}
_getHistoricalFiatRate(transaction);
final wallet = _wallet;
if (wallet.type == WalletType.monero) {
return monero!.getTransactionInfoAccountId(transaction) == monero!.getCurrentAccount(wallet).id;
@ -366,11 +373,6 @@ abstract class DashboardViewModelBase with Store {
wallet.type == WalletType.bitcoin && wallet.seed.split(' ').length < 24;
updateActions();
wallet.transactionHistory.transactions.values.forEach((tx) {
_getHistoricalFiatRate(tx);
});
if (wallet.type == WalletType.monero) {
subname = monero!.getCurrentAccount(wallet).label;
@ -448,9 +450,11 @@ abstract class DashboardViewModelBase with Store {
}
Future<void> _getHistoricalFiatRate(TransactionInfo transactionInfo) async {
if (FiatApiMode.disabled == settingsStore.fiatApiMode) return;
if (FiatApiMode.disabled == settingsStore.fiatApiMode
|| !settingsStore.showHistoricalFiatAmount) return;
final description = getTransactionDescription(transactionInfo);
if (description.historicalFiat != settingsStore.fiatCurrency.toString()
|| description.historicalFiatRate == null) {
if (description.key == 0) description.delete();