From 993dea82a929d14a141287aeb41ec44042ee10a6 Mon Sep 17 00:00:00 2001 From: Serhii Date: Thu, 20 Feb 2025 18:53:18 +0200 Subject: [PATCH] replace connectMapToListWithTransform with reaction --- .../dashboard/dashboard_view_model.dart | 55 ++++++++++--------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/lib/view_model/dashboard/dashboard_view_model.dart b/lib/view_model/dashboard/dashboard_view_model.dart index 99283a409..7cc26b33e 100644 --- a/lib/view_model/dashboard/dashboard_view_model.dart +++ b/lib/view_model/dashboard/dashboard_view_model.dart @@ -578,6 +578,8 @@ abstract class DashboardViewModelBase with Store { ReactionDisposer? _onMoneroBalanceChangeReaction; + ReactionDisposer? _transactionDisposer; + @computed bool get hasPowNodes => [WalletType.nano, WalletType.banano].contains(wallet.type); @@ -682,32 +684,35 @@ abstract class DashboardViewModelBase with Store { ); } - connectMapToListWithTransform( - appStore.wallet!.transactionHistory.transactions, - transactions, - (TransactionInfo? transaction) => TransactionListItem( - transaction: transaction!, - balanceViewModel: balanceViewModel, - settingsStore: appStore.settingsStore, - key: ValueKey( - '${wallet.type.name}_transaction_history_item_${transaction.id}_key', + _transactionDisposer?.reaction.dispose(); + + _transactionDisposer = reaction( + (_) => appStore.wallet!.transactionHistory.transactions.values.toList(), + (List txs) { + // Clear existing transactions + transactions.clear(); + + // Apply filtering before adding to the list + transactions.addAll( + txs.where((tx) { + if (wallet.type == WalletType.monero) { + return monero!.getTransactionInfoAccountId(tx) == monero!.getCurrentAccount(wallet).id; + } + if (wallet.type == WalletType.wownero) { + return wow.wownero!.getTransactionInfoAccountId(tx) == wow.wownero!.getCurrentAccount(wallet).id; + } + return true; // Include other wallet types without filtering + }).map( + (tx) => TransactionListItem( + transaction: tx, + balanceViewModel: balanceViewModel, + settingsStore: appStore.settingsStore, + key: ValueKey('${wallet.type.name}_transaction_history_item_${tx.id}_key'), ), - ), filter: (TransactionInfo? tx) { - if (tx == null) { - return false; - } - - if (wallet.type == WalletType.monero) { - return monero!.getTransactionInfoAccountId(tx) == monero!.getCurrentAccount(wallet).id; - } - - if (wallet.type == WalletType.wownero) { - return wow.wownero!.getTransactionInfoAccountId(tx) == - wow.wownero!.getCurrentAccount(wallet).id; - } - - return true; - }); + ), + ); + } + ); } @action