Skip to content

Commit

Permalink
CW-854 Monero Wallet Group Fix (#1865)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
Blazebrain and OmarHatem28 authored Dec 11, 2024
1 parent 82bad3a commit 6e8cc9c
Showing 1 changed file with 48 additions and 8 deletions.
56 changes: 48 additions & 8 deletions lib/view_model/wallet_list/wallet_list_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:cake_wallet/core/wallet_loading_service.dart';
import 'package:cake_wallet/entities/wallet_group.dart';
import 'package:cake_wallet/entities/wallet_list_order_types.dart';
import 'package:cake_wallet/entities/wallet_manager.dart';
import 'package:cake_wallet/reactions/bip39_wallet_utils.dart';
import 'package:hive/hive.dart';
import 'package:mobx/mobx.dart';
import 'package:cake_wallet/store/app_store.dart';
Expand Down Expand Up @@ -90,20 +91,59 @@ abstract class WalletListViewModelBase with Store {
multiWalletGroups.clear();
singleWalletsList.clear();

wallets.addAll(
_walletInfoSource.values
.map((info) => convertWalletInfoToWalletListItem(info)),
);
for (var info in _walletInfoSource.values) {
wallets.add(convertWalletInfoToWalletListItem(info));
}

//========== Split into shared seed groups and single wallets list
_walletManager.updateWalletGroups();

for (var group in _walletManager.walletGroups) {
final walletGroupsFromManager = _walletManager.walletGroups;

for (var group in walletGroupsFromManager) {
if (group.wallets.length == 1) {
singleWalletsList
.add(convertWalletInfoToWalletListItem(group.wallets.first));
} else {
singleWalletsList.add(convertWalletInfoToWalletListItem(group.wallets.first));
continue;
}

// Identify wallets that should be moved to singleWalletsList using the filters: the type/derivation
final excludedWallets = <WalletInfo>[];

for (var wallet in group.wallets) {
// Check for non-BIP39 wallet types
final isNonBIP39 = !isBIP39Wallet(wallet.type);

// Check for nano derivation type
final isNanoDerivation = wallet.type == WalletType.nano &&
wallet.derivationInfo?.derivationType == DerivationType.nano;

// Check for electrum derivation type
final isElectrumDerivation =
(wallet.type == WalletType.bitcoin || wallet.type == WalletType.litecoin) &&
wallet.derivationInfo?.derivationType == DerivationType.electrum;

if (isNonBIP39 || isNanoDerivation || isElectrumDerivation) {
excludedWallets.add(wallet);
}
}

// Add excluded wallets to singleWalletsList
for (var excludedWallet in excludedWallets) {
singleWalletsList.add(convertWalletInfoToWalletListItem(excludedWallet));
}

// Remove excluded wallets from the group's wallets to avoid duplication
group.wallets.removeWhere((wallet) {
return excludedWallets.any((excluded) => excluded.address == wallet.address);
});

// Check if the group has more than one wallet after the excluded wallets are removed.
if (group.wallets.length > 1) {
//Add the entire group to the multi wallet group list since its still a multi wallet
multiWalletGroups.add(group);
} else if (group.wallets.length == 1) {
// Add the group to the wallet left to the single wallets list
singleWalletsList.add(convertWalletInfoToWalletListItem(group.wallets.first));
}
}
}
Expand Down

0 comments on commit 6e8cc9c

Please sign in to comment.