From e9cdd60d4b4972c640be997f90d31e043617b421 Mon Sep 17 00:00:00 2001 From: Blazebrain Date: Thu, 19 Jun 2025 05:58:22 +0100 Subject: [PATCH] refactor(token_validation): Modify token management flow This change: - Removes duplicate token check during token addition in EVMChainWalletBase. - Introduces a flag to indicate if a token is being edited - Adjusts token addition validation to bypass checks when editing an existing token. --- cw_evm/lib/evm_chain_wallet.dart | 5 ----- lib/src/screens/dashboard/edit_token_page.dart | 13 ++++++++++--- .../dashboard/home_settings_view_model.dart | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/cw_evm/lib/evm_chain_wallet.dart b/cw_evm/lib/evm_chain_wallet.dart index 073c264b7..c3c75d82d 100644 --- a/cw_evm/lib/evm_chain_wallet.dart +++ b/cw_evm/lib/evm_chain_wallet.dart @@ -664,11 +664,6 @@ abstract class EVMChainWalletBase List get erc20Currencies => evmChainErc20TokensBox.values.toList(); Future addErc20Token(Erc20Token token) async { - if (evmChainErc20TokensBox.values.any((element) => - element.contractAddress.toLowerCase() == token.contractAddress.toLowerCase())) { - throw Exception('Token already exists'); - } - String? iconPath; if ((token.iconPath == null || token.iconPath!.isEmpty) && !token.isPotentialScam) { diff --git a/lib/src/screens/dashboard/edit_token_page.dart b/lib/src/screens/dashboard/edit_token_page.dart index 2f86a5d30..0b3a9d316 100644 --- a/lib/src/screens/dashboard/edit_token_page.dart +++ b/lib/src/screens/dashboard/edit_token_page.dart @@ -73,6 +73,7 @@ class _EditTokenPageBodyState extends State { bool _showDisclaimer = false; bool _disclaimerChecked = false; + bool isEditingToken = false; @override void initState() { @@ -88,11 +89,15 @@ class _EditTokenPageBodyState extends State { _tokenSymbolController.text = widget.token!.title; _tokenDecimalController.text = widget.token!.decimals.toString(); _tokenIconPathController.text = widget.token?.iconPath ?? ''; + + isEditingToken = true; } if (widget.initialContractAddress != null) { _contractAddressController.text = widget.initialContractAddress!; _getTokenInfo(); + + isEditingToken = true; } _contractAddressFocusNode.addListener(() { @@ -200,8 +205,10 @@ class _EditTokenPageBodyState extends State { onPressed: () async { if (_formKey.currentState!.validate() && (!_showDisclaimer || _disclaimerChecked)) { - final isTokenAlreadyAdded = await widget.homeSettingsViewModel - .checkIfTokenIsAlreadyAdded(_contractAddressController.text); + final isTokenAlreadyAdded = isEditingToken + ? false + : await widget.homeSettingsViewModel + .checkIfTokenIsAlreadyAdded(_contractAddressController.text); if (isTokenAlreadyAdded) { showPopUp( context: context, @@ -216,7 +223,7 @@ class _EditTokenPageBodyState extends State { ); return; } - + final isWhitelisted = await widget.homeSettingsViewModel .checkIfTokenIsWhitelisted(_contractAddressController.text); diff --git a/lib/view_model/dashboard/home_settings_view_model.dart b/lib/view_model/dashboard/home_settings_view_model.dart index 184043619..bf523ad72 100644 --- a/lib/view_model/dashboard/home_settings_view_model.dart +++ b/lib/view_model/dashboard/home_settings_view_model.dart @@ -127,7 +127,7 @@ abstract class HomeSettingsViewModelBase with Store { } @action - Future checkIfTokenIsAlreadyAdded(String contractAddress) async { + bool checkIfTokenIsAlreadyAdded(String contractAddress) { if (_balanceViewModel.wallet.type == WalletType.ethereum) { return ethereum!.isTokenAlreadyAdded(_balanceViewModel.wallet, contractAddress); }