Label existing scam tokens (#2164)

* label existing scam tokens because users can get scammed twice ¯\_(ツ)_/¯

* minor ui fix [skip ci]
This commit is contained in:
Omar Hatem 2025-04-07 18:12:39 +02:00 committed by GitHub
parent 9ac784db5c
commit 88ebba9236
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 89 additions and 53 deletions

View file

@ -144,6 +144,8 @@ abstract class EVMChainWalletBase
// required WalletInfo walletInfo,
// });
List<String> get getDefaultTokenContractAddresses;
Future<void> initErc20TokensBox();
String getTransactionHistoryFileName();
@ -171,6 +173,9 @@ abstract class EVMChainWalletBase
await walletAddresses.init();
await transactionHistory.init();
// check for Already existing scam tokens, cuz users can get scammed twice ¯\_()_/¯
await _checkForExistingScamTokens();
if (walletInfo.isHardwareWallet) {
_evmChainPrivateKey = EvmLedgerCredentials(walletInfo.address);
walletAddresses.address = walletInfo.address;
@ -186,6 +191,31 @@ abstract class EVMChainWalletBase
await save();
}
Future<void> _checkForExistingScamTokens() async {
final baseCurrencySymbols = CryptoCurrency.all.map((e) => e.title.toUpperCase()).toList();
for (var token in erc20Currencies) {
bool isPotentialScam = false;
bool isWhitelisted =
getDefaultTokenContractAddresses.any((element) => element == token.contractAddress);
final tokenSymbol = token.title.toUpperCase();
// check if the token symbol is the same as any of the base currencies symbols (ETH, SOL, POL, TRX, etc):
// if it is, then it's probably a scam unless it's in the whitelist
if (baseCurrencySymbols.contains(tokenSymbol.trim().toUpperCase()) && !isWhitelisted) {
isPotentialScam = true;
}
if (isPotentialScam) {
token.isPotentialScam = true;
token.iconPath = null;
await token.save();
}
}
}
@override
int calculateEstimatedFee(TransactionPriority priority, int? amount) {
{