diff --git a/lib/pages/add_wallet_views/add_token_view/add_token_view.dart b/lib/pages/add_wallet_views/add_token_view/add_token_view.dart index 2e4e3b03b..fc542d513 100644 --- a/lib/pages/add_wallet_views/add_token_view/add_token_view.dart +++ b/lib/pages/add_wallet_views/add_token_view/add_token_view.dart @@ -70,8 +70,10 @@ class _AddTokenViewState extends ConsumerState { } Future onNextPressed() async { - final selectedTokens = - tokenEntities.where((e) => e.selected).map((e) => e.token).toList(); + final selectedTokens = tokenEntities + .where((e) => e.selected) + .map((e) => e.token.address) + .toList(); final ethWallet = ref .read(walletsChangeNotifierProvider) diff --git a/lib/services/coins/ethereum/ethereum_wallet.dart b/lib/services/coins/ethereum/ethereum_wallet.dart index 523148c4c..3ea83be65 100644 --- a/lib/services/coins/ethereum/ethereum_wallet.dart +++ b/lib/services/coins/ethereum/ethereum_wallet.dart @@ -62,39 +62,23 @@ class EthereumWallet extends CoinServiceAPI with WalletCache, WalletDB { Timer? timer; Timer? _networkAliveTimer; - Future addTokenContracts(List contracts) async { - List updatedContracts = []; - for (final contract in contracts) { - final updatedWalletIds = contract.walletIds.toList(); - if (!updatedWalletIds.contains(walletId)) { - updatedWalletIds.add(walletId); - updatedContracts.add(contract.copyWith(walletIds: updatedWalletIds)); - } else { - updatedContracts.add(contract); - } - } - await db.putEthContracts(updatedContracts); + Future addTokenContracts(List contractAddresses) async { + final set = getWalletTokenContractAddresses().toSet(); + set.addAll(contractAddresses); + await updateWalletTokenContractAddresses(set.toList()); GlobalEventBus.instance.fire( UpdatedInBackgroundEvent( - "$contracts updated/added for: $walletId $walletName", + "$contractAddresses updated/added for: $walletId $walletName", walletId, ), ); } Future removeTokenContract(String contractAddress) async { - final contract = - await db.getEthContracts().addressEqualTo(contractAddress).findFirst(); - - if (contract == null) { - return; // todo some error? - } - - final updatedWalletIds = contract.walletIds.toList(); - updatedWalletIds.removeWhere((e) => e == contractAddress); - - await db.putEthContract(contract.copyWith(walletIds: updatedWalletIds)); + final set = getWalletTokenContractAddresses().toSet(); + set.removeWhere((e) => e == contractAddress); + await updateWalletTokenContractAddresses(set.toList()); GlobalEventBus.instance.fire( UpdatedInBackgroundEvent(