fix erc20 tokens transactions

This commit is contained in:
Serhii 2024-06-12 18:21:56 +03:00
parent ffa0b416e9
commit 4b5eef9072
2 changed files with 32 additions and 10 deletions

View file

@ -29,6 +29,11 @@ class EthereumClient extends EVMChainClient {
final jsonResponse = json.decode(response.body) as Map<String, dynamic>;
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<String, dynamic>, 'ETH'))

View file

@ -338,9 +338,6 @@ abstract class EVMChainWalletBase
@override
Future<Map<String, EVMChainTransactionInfo>> fetchTransactions() async {
final address = _evmChainPrivateKey.address.hex;
final transactions = await _client.fetchTransactions(address);
final internalTransactions = await _client.fetchInternalTransactions(address);
final List<Future<List<EVMChainTransactionModel>>> erc20TokensTransactions = [];
for (var token in balance.keys) {
@ -352,19 +349,39 @@ 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<String, EVMChainTransactionInfo> result = {};
List<EVMChainTransactionModel> transactionsList = [];
Set<String> 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);
}
}
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;
}