mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-11-24 10:54:13 +01:00
CW-1228: Automatically detect wallet tokens for EVM chains (#2827)
* feat: Automatically detect wallet tokens for EVM chains * feat: Disable potential tg scam tokens by default * feat: Add homoglyph normalization to detect spoofing attacks in token symbols * refactor: Improve scam token detection and apply to automatically fetched EVM tokens * refactor: Enhance scam detection for automatically detected tokens in evm wallets * feat: Add fiat check to scam checks on automatically imported token and disable tokens that fail the check * feat: Add fiat check to scam checks on automatically imported token and disable tokens that fail the check * feat: Add fiat check to scam checks on automatically imported token and disable tokens that fail the check * feat: Enable whitelisted tokens with balance when importing wallet tokens
This commit is contained in:
@@ -513,4 +513,56 @@ class CWEVM extends EVM {
|
||||
|
||||
@override
|
||||
bool hasPriorityFee(int chainId) => EVMChainUtils.hasPriorityFee(chainId);
|
||||
|
||||
@override
|
||||
Future<bool> checkTokenFiatPrice(WalletBase wallet, Erc20Token token) async {
|
||||
try {
|
||||
final settingsStore = getIt.get<SettingsStore>();
|
||||
final fiatCurrency = settingsStore.fiatCurrency;
|
||||
final torOnly = settingsStore.fiatApiMode == FiatApiMode.torOnly;
|
||||
|
||||
final price = await FiatConversionService.fetchPrice(
|
||||
crypto: token,
|
||||
fiat: fiatCurrency,
|
||||
torOnly: torOnly,
|
||||
);
|
||||
|
||||
return price > 0;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> discoverAndAddWalletTokens(WalletBase wallet) async {
|
||||
if (wallet is! EVMChainWallet) return;
|
||||
|
||||
try {
|
||||
final discoveredTokens = await wallet.discoverTokensFromMoralis();
|
||||
|
||||
if (discoveredTokens.isEmpty) return;
|
||||
|
||||
final List<Future<void>> tokenChecks = [];
|
||||
|
||||
for (final token in discoveredTokens) {
|
||||
tokenChecks.add((() async {
|
||||
final isPropertiesSuspicious = wallet.isTokenPropertiesSuspicious(token);
|
||||
|
||||
bool hasValidFiatPrice = true;
|
||||
if (!isPropertiesSuspicious) {
|
||||
hasValidFiatPrice = await checkTokenFiatPrice(wallet, token);
|
||||
}
|
||||
|
||||
final isSpam = isPropertiesSuspicious || !hasValidFiatPrice;
|
||||
|
||||
token.isPotentialScam = isSpam;
|
||||
token.enabled = !isSpam;
|
||||
|
||||
await wallet.addErc20Token(token);
|
||||
})());
|
||||
}
|
||||
|
||||
await Future.wait(tokenChecks);
|
||||
} catch (_) {}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user