CW-1103:Token Validation Issues (#2327)

* feat(token_validation): Improve flow for adding new tokens across wallets

This change:
- Implements check to see if a token is already added, preventing duplicates
- Triggers dialog warning if its a duplicate token
- Takes EVM Chains contract adddress case-insensitivity when making checks for potential scams.

* 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.

* Update lib/src/screens/dashboard/edit_token_page.dart

---------

Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
This commit is contained in:
David Adegoke 2025-06-24 03:47:21 +01:00 committed by GitHub
parent 4434ad7363
commit af89603b81
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
37 changed files with 127 additions and 5 deletions

View file

@ -126,6 +126,31 @@ abstract class HomeSettingsViewModelBase with Store {
}
}
@action
bool checkIfTokenIsAlreadyAdded(String contractAddress) {
if (_balanceViewModel.wallet.type == WalletType.ethereum) {
return ethereum!.isTokenAlreadyAdded(_balanceViewModel.wallet, contractAddress);
}
if (_balanceViewModel.wallet.type == WalletType.polygon) {
return polygon!.isTokenAlreadyAdded(_balanceViewModel.wallet, contractAddress);
}
if (_balanceViewModel.wallet.type == WalletType.solana) {
return solana!.isTokenAlreadyAdded(_balanceViewModel.wallet, contractAddress);
}
if (_balanceViewModel.wallet.type == WalletType.tron) {
return tron!.isTokenAlreadyAdded(_balanceViewModel.wallet, contractAddress);
}
if (_balanceViewModel.wallet.type == WalletType.zano) {
return zano!.isTokenAlreadyAdded(_balanceViewModel.wallet, contractAddress);
}
return false;
}
@action
Future<void> deleteToken(CryptoCurrency token) async {
try {
@ -297,7 +322,7 @@ abstract class HomeSettingsViewModelBase with Store {
required bool isEthereum,
}) async {
final uri = Uri.https(
"api.etherscan.io",
"api.etherscan.io",
"/v2/api",
{
"chainid": isEthereum ? "1" : "137",