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.
This commit is contained in:
Blazebrain 2025-06-19 05:58:22 +01:00
parent 6fccd784ec
commit e9cdd60d4b
3 changed files with 11 additions and 9 deletions

View file

@ -664,11 +664,6 @@ abstract class EVMChainWalletBase
List<Erc20Token> get erc20Currencies => evmChainErc20TokensBox.values.toList();
Future<void> 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) {

View file

@ -73,6 +73,7 @@ class _EditTokenPageBodyState extends State<EditTokenPageBody> {
bool _showDisclaimer = false;
bool _disclaimerChecked = false;
bool isEditingToken = false;
@override
void initState() {
@ -88,11 +89,15 @@ class _EditTokenPageBodyState extends State<EditTokenPageBody> {
_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,7 +205,9 @@ class _EditTokenPageBodyState extends State<EditTokenPageBody> {
onPressed: () async {
if (_formKey.currentState!.validate() &&
(!_showDisclaimer || _disclaimerChecked)) {
final isTokenAlreadyAdded = await widget.homeSettingsViewModel
final isTokenAlreadyAdded = isEditingToken
? false
: await widget.homeSettingsViewModel
.checkIfTokenIsAlreadyAdded(_contractAddressController.text);
if (isTokenAlreadyAdded) {
showPopUp<void>(

View file

@ -127,7 +127,7 @@ abstract class HomeSettingsViewModelBase with Store {
}
@action
Future<bool> checkIfTokenIsAlreadyAdded(String contractAddress) async {
bool checkIfTokenIsAlreadyAdded(String contractAddress) {
if (_balanceViewModel.wallet.type == WalletType.ethereum) {
return ethereum!.isTokenAlreadyAdded(_balanceViewModel.wallet, contractAddress);
}