diff --git a/cw_ethereum/lib/ethereum_client.dart b/cw_ethereum/lib/ethereum_client.dart index f2b25bcdd..252d38811 100644 --- a/cw_ethereum/lib/ethereum_client.dart +++ b/cw_ethereum/lib/ethereum_client.dart @@ -29,6 +29,11 @@ class EthereumClient extends EVMChainClient { final jsonResponse = json.decode(response.body) as Map; + if (jsonResponse['result'] is String && jsonResponse['result'].contains("Max rate limit reached")) { + log("Fetch EVM transactions exception: Max rate limit reached"); + return []; + } + if (response.statusCode >= 200 && response.statusCode < 300 && jsonResponse['status'] != 0) { return (jsonResponse['result'] as List) .map((e) => EVMChainTransactionModel.fromJson(e as Map, 'ETH')) diff --git a/cw_evm/lib/evm_chain_wallet.dart b/cw_evm/lib/evm_chain_wallet.dart index 56b58d400..21d82db60 100644 --- a/cw_evm/lib/evm_chain_wallet.dart +++ b/cw_evm/lib/evm_chain_wallet.dart @@ -338,9 +338,6 @@ abstract class EVMChainWalletBase @override Future> fetchTransactions() async { final address = _evmChainPrivateKey.address.hex; - final transactions = await _client.fetchTransactions(address); - final internalTransactions = await _client.fetchInternalTransactions(address); - final List>> erc20TokensTransactions = []; for (var token in balance.keys) { @@ -352,18 +349,38 @@ abstract class EVMChainWalletBase } } - final tokensTransaction = await Future.wait(erc20TokensTransactions); - transactions.addAll(tokensTransaction.expand((element) => element)); - transactions.addAll(internalTransactions); + final tokensTransaction = await Future.wait(erc20TokensTransactions) + .then((value) => value.expand((element) => element).toList()); final Map result = {}; + List transactionsList = []; + Set transactionHashes = {}; - for (var transactionModel in transactions) { - if (transactionModel.isError) { - continue; + for (var transaction in tokensTransaction) { + transactionsList.add(transaction); + transactionHashes.add(transaction.hash); + } + + final internalTransactions = await _client.fetchInternalTransactions(address); + for (var transaction in internalTransactions) { + if (!transactionHashes.contains(transaction.hash)) { + transactionsList.add(transaction); + transactionHashes.add(transaction.hash); } + } - result[transactionModel.hash] = getTransactionInfo(transactionModel, address); + final transactions = await _client.fetchTransactions(address); + for (var transaction in transactions) { + if (!transactionHashes.contains(transaction.hash)) { + transactionsList.add(transaction); + transactionHashes.add(transaction.hash); + } + } + + for (var transactionModel in transactionsList) { + if (!transactionModel.isError) { + result[transactionModel.hash] = getTransactionInfo(transactionModel, address); + } } return result;