From 87207c61baa22f803cf4e072b16b1b5dc0eb0cbb Mon Sep 17 00:00:00 2001 From: cyan Date: Mon, 14 Apr 2025 18:47:31 +0200 Subject: [PATCH] fix: wallet grouping eating wallets (#2203) --- lib/entities/wallet_manager.dart | 8 +++- .../wallet_list/wallet_list_view_model.dart | 41 +------------------ 2 files changed, 9 insertions(+), 40 deletions(-) diff --git a/lib/entities/wallet_manager.dart b/lib/entities/wallet_manager.dart index 8bcabcaf2..09b764289 100644 --- a/lib/entities/wallet_manager.dart +++ b/lib/entities/wallet_manager.dart @@ -1,3 +1,5 @@ +import 'dart:math'; + import 'package:cake_wallet/entities/hash_wallet_identifier.dart'; import 'package:cake_wallet/entities/wallet_group.dart'; import 'package:cw_core/wallet_base.dart'; @@ -33,7 +35,11 @@ class WalletManager { } // Fallback to old logic - return walletInfo.parentAddress ?? walletInfo.address; + final address = walletInfo.parentAddress ?? walletInfo.address; + if (address.isEmpty) { + return Random().nextInt(100000).toString(); + } + return address; } WalletGroup _getOrCreateGroup(String groupKey) { diff --git a/lib/view_model/wallet_list/wallet_list_view_model.dart b/lib/view_model/wallet_list/wallet_list_view_model.dart index b27bf52f6..bd135ef96 100644 --- a/lib/view_model/wallet_list/wallet_list_view_model.dart +++ b/lib/view_model/wallet_list/wallet_list_view_model.dart @@ -3,6 +3,7 @@ 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:cw_core/utils/print_verbose.dart'; import 'package:hive/hive.dart'; import 'package:mobx/mobx.dart'; import 'package:cake_wallet/store/app_store.dart'; @@ -109,45 +110,7 @@ abstract class WalletListViewModelBase with Store { continue; } - // Identify wallets that should be moved to singleWalletsList using the filters: the type/derivation - final excludedWallets = []; - - 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)); - } + multiWalletGroups.add(group); } }