CW-854 Monero Wallet Group Fix (#1865)
* Fix: Tentative fix to wrong wallet groupings, specifically monero or non bip39 wallet types * fix: Modify logic to filter out single wallets and multi group wallets --------- Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
David Adegoke committed
Dec 11, 2024 at 19:51 UTC
6e8cc9c39e938e318950b64ce42b3bcb3cfd3726
1 file changed
+48
-8
lib/view_model/wallet_list/wallet_list_view_model.dart
+48
-8
@@ -2,6 +2,7 @@ import 'package:cake_wallet/core/wallet_loading_service.dart';
2
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:hive/hive.dart';
7
import 'package:mobx/mobx.dart';
8
import 'package:cake_wallet/store/app_store.dart';
@@ -90,20 +91,59 @@ abstract class WalletListViewModelBase with Store {
91
multiWalletGroups.clear();
92
singleWalletsList.clear();
93
93
- wallets.addAll(
94
- _walletInfoSource.values
95
- .map((info) => convertWalletInfoToWalletListItem(info)),
96
- );
94
+ for (var info in _walletInfoSource.values) {
95
+ wallets.add(convertWalletInfoToWalletListItem(info));
96
+ }
97
98
//========== Split into shared seed groups and single wallets list
99
_walletManager.updateWalletGroups();
100
101
- for (var group in _walletManager.walletGroups) {
101
+ final walletGroupsFromManager = _walletManager.walletGroups;
102
+
103
+ for (var group in walletGroupsFromManager) {
104
if (group.wallets.length == 1) {
103
- singleWalletsList
104
- .add(convertWalletInfoToWalletListItem(group.wallets.first));
105
- } else {
105
+ singleWalletsList.add(convertWalletInfoToWalletListItem(group.wallets.first));
106
+ continue;
107
+ }
108
+
109
+ // Identify wallets that should be moved to singleWalletsList using the filters: the type/derivation
110
+ final excludedWallets = <WalletInfo>[];
111
+
112
+ for (var wallet in group.wallets) {
113
+ // Check for non-BIP39 wallet types
114
+ final isNonBIP39 = !isBIP39Wallet(wallet.type);
115
+
116
+ // Check for nano derivation type
117
+ final isNanoDerivation = wallet.type == WalletType.nano &&
118
+ wallet.derivationInfo?.derivationType == DerivationType.nano;
119
+
120
+ // Check for electrum derivation type
121
+ final isElectrumDerivation =
122
+ (wallet.type == WalletType.bitcoin || wallet.type == WalletType.litecoin) &&
123
+ wallet.derivationInfo?.derivationType == DerivationType.electrum;
124
+
125
+ if (isNonBIP39 || isNanoDerivation || isElectrumDerivation) {
126
+ excludedWallets.add(wallet);
127
+ }
128
+ }
129
+
130
+ // Add excluded wallets to singleWalletsList
131
+ for (var excludedWallet in excludedWallets) {
132
+ singleWalletsList.add(convertWalletInfoToWalletListItem(excludedWallet));
133
+ }
134
+
135
+ // Remove excluded wallets from the group's wallets to avoid duplication
136
+ group.wallets.removeWhere((wallet) {
137
+ return excludedWallets.any((excluded) => excluded.address == wallet.address);
138
+ });
139
+
140
+ // Check if the group has more than one wallet after the excluded wallets are removed.
141
+ if (group.wallets.length > 1) {
142
+ //Add the entire group to the multi wallet group list since its still a multi wallet
143
multiWalletGroups.add(group);
144
+ } else if (group.wallets.length == 1) {
145
+ // Add the group to the wallet left to the single wallets list
146
+ singleWalletsList.add(convertWalletInfoToWalletListItem(group.wallets.first));
147
}
148
}
149
}