replace connectMapToListWithTransform with reaction
Serhii committed
Feb 20, 2025 at 18:53 UTC
993dea82a929d14a141287aeb41ec44042ee10a6
1 file changed
+30
-25
lib/view_model/dashboard/dashboard_view_model.dart
+30
-25
@@ -578,6 +578,8 @@ abstract class DashboardViewModelBase with Store {
578
579
ReactionDisposer? _onMoneroBalanceChangeReaction;
580
581
+ ReactionDisposer? _transactionDisposer;
582
+
583
@computed
584
bool get hasPowNodes => [WalletType.nano, WalletType.banano].contains(wallet.type);
585
@@ -682,32 +684,35 @@ abstract class DashboardViewModelBase with Store {
684
);
685
}
686
685
- connectMapToListWithTransform(
686
- appStore.wallet!.transactionHistory.transactions,
687
- transactions,
688
- (TransactionInfo? transaction) => TransactionListItem(
689
- transaction: transaction!,
690
- balanceViewModel: balanceViewModel,
691
- settingsStore: appStore.settingsStore,
692
- key: ValueKey(
693
- '${wallet.type.name}_transaction_history_item_${transaction.id}_key',
687
+ _transactionDisposer?.reaction.dispose();
688
+
689
+ _transactionDisposer = reaction(
690
+ (_) => appStore.wallet!.transactionHistory.transactions.values.toList(),
691
+ (List<TransactionInfo> txs) {
692
+ // Clear existing transactions
693
+ transactions.clear();
694
+
695
+ // Apply filtering before adding to the list
696
+ transactions.addAll(
697
+ txs.where((tx) {
698
+ if (wallet.type == WalletType.monero) {
699
+ return monero!.getTransactionInfoAccountId(tx) == monero!.getCurrentAccount(wallet).id;
700
+ }
701
+ if (wallet.type == WalletType.wownero) {
702
+ return wow.wownero!.getTransactionInfoAccountId(tx) == wow.wownero!.getCurrentAccount(wallet).id;
703
+ }
704
+ return true; // Include other wallet types without filtering
705
+ }).map(
706
+ (tx) => TransactionListItem(
707
+ transaction: tx,
708
+ balanceViewModel: balanceViewModel,
709
+ settingsStore: appStore.settingsStore,
710
+ key: ValueKey('${wallet.type.name}_transaction_history_item_${tx.id}_key'),
711
),
695
- ), filter: (TransactionInfo? tx) {
696
- if (tx == null) {
697
- return false;
698
- }
699
-
700
- if (wallet.type == WalletType.monero) {
701
- return monero!.getTransactionInfoAccountId(tx) == monero!.getCurrentAccount(wallet).id;
702
- }
703
-
704
- if (wallet.type == WalletType.wownero) {
705
- return wow.wownero!.getTransactionInfoAccountId(tx) ==
706
- wow.wownero!.getCurrentAccount(wallet).id;
707
- }
708
-
709
- return true;
710
- });
712
+ ),
713
+ );
714
+ }
715
+ );
716
}
717
718
@action