mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-22 11:39:22 +00:00
fix erc20 tokens transactions
This commit is contained in:
parent
ffa0b416e9
commit
4b5eef9072
2 changed files with 32 additions and 10 deletions
|
@ -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'))
|
||||
|
|
|
@ -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,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<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);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
|
Loading…
Reference in a new issue