fix: wallet grouping eating wallets (#2203)
cyan committed
Apr 14, 2025 at 18:47 UTC
87207c61baa22f803cf4e072b16b1b5dc0eb0cbb
2 files changed
+9
-40
lib/entities/wallet_manager.dart
+7
-1
@@ -1,3 +1,5 @@
1
+import 'dart:math';
2
+
3
import 'package:cake_wallet/entities/hash_wallet_identifier.dart';
4
import 'package:cake_wallet/entities/wallet_group.dart';
5
import 'package:cw_core/wallet_base.dart';
@@ -33,7 +35,11 @@ class WalletManager {
35
}
36
37
// Fallback to old logic
36
- return walletInfo.parentAddress ?? walletInfo.address;
38
+ final address = walletInfo.parentAddress ?? walletInfo.address;
39
+ if (address.isEmpty) {
40
+ return Random().nextInt(100000).toString();
41
+ }
42
+ return address;
43
}
44
45
WalletGroup _getOrCreateGroup(String groupKey) {
lib/view_model/wallet_list/wallet_list_view_model.dart
+2
-39
@@ -3,6 +3,7 @@ import 'package:cake_wallet/entities/wallet_group.dart';
3
import 'package:cake_wallet/entities/wallet_list_order_types.dart';
4
import 'package:cake_wallet/entities/wallet_manager.dart';
5
import 'package:cake_wallet/reactions/bip39_wallet_utils.dart';
6
+import 'package:cw_core/utils/print_verbose.dart';
7
import 'package:hive/hive.dart';
8
import 'package:mobx/mobx.dart';
9
import 'package:cake_wallet/store/app_store.dart';
@@ -109,45 +110,7 @@ abstract class WalletListViewModelBase with Store {
110
continue;
111
}
112
112
- // Identify wallets that should be moved to singleWalletsList using the filters: the type/derivation
113
- final excludedWallets = <WalletInfo>[];
114
-
115
- for (var wallet in group.wallets) {
116
- // Check for non-BIP39 wallet types
117
- final isNonBIP39 = !isBIP39Wallet(wallet.type);
118
-
119
- // Check for nano derivation type
120
- final isNanoDerivation = wallet.type == WalletType.nano &&
121
- wallet.derivationInfo?.derivationType == DerivationType.nano;
122
-
123
- // Check for electrum derivation type
124
- final isElectrumDerivation =
125
- (wallet.type == WalletType.bitcoin || wallet.type == WalletType.litecoin) &&
126
- wallet.derivationInfo?.derivationType == DerivationType.electrum;
127
-
128
- if (isNonBIP39 || isNanoDerivation || isElectrumDerivation) {
129
- excludedWallets.add(wallet);
130
- }
131
- }
132
-
133
- // Add excluded wallets to singleWalletsList
134
- for (var excludedWallet in excludedWallets) {
135
- singleWalletsList.add(convertWalletInfoToWalletListItem(excludedWallet));
136
- }
137
-
138
- // Remove excluded wallets from the group's wallets to avoid duplication
139
- group.wallets.removeWhere((wallet) {
140
- return excludedWallets.any((excluded) => excluded.address == wallet.address);
141
- });
142
-
143
- // Check if the group has more than one wallet after the excluded wallets are removed.
144
- if (group.wallets.length > 1) {
145
- //Add the entire group to the multi wallet group list since its still a multi wallet
146
- multiWalletGroups.add(group);
147
- } else if (group.wallets.length == 1) {
148
- // Add the group to the wallet left to the single wallets list
149
- singleWalletsList.add(convertWalletInfoToWalletListItem(group.wallets.first));
150
- }
113
+ multiWalletGroups.add(group);
114
}
115
}
116