mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-16 17:27:39 +00:00
eth api error handling clean up and token flag
This commit is contained in:
parent
96bfafcd19
commit
461267ec95
2 changed files with 24 additions and 14 deletions
|
@ -1023,6 +1023,7 @@ class EthereumWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
final response = await EthereumAPI.getEthTransactions(
|
||||
address: thisAddress,
|
||||
firstBlock: isRescan ? 0 : firstBlock,
|
||||
includeTokens: true,
|
||||
);
|
||||
|
||||
if (response.value == null) {
|
||||
|
@ -1057,8 +1058,10 @@ class EthereumWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
txFailed = true;
|
||||
}
|
||||
isIncoming = false;
|
||||
} else {
|
||||
} else if (checksumEthereumAddress(element.to) == thisAddress) {
|
||||
isIncoming = true;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
||||
//Calculate fees (GasLimit * gasPrice)
|
||||
|
|
|
@ -50,6 +50,7 @@ abstract class EthereumAPI {
|
|||
static Future<EthereumResponse<List<EthTxDTO>>> getEthTransactions({
|
||||
required String address,
|
||||
int firstBlock = 0,
|
||||
bool includeTokens = false,
|
||||
}) async {
|
||||
try {
|
||||
final response = await get(
|
||||
|
@ -67,7 +68,7 @@ abstract class EthereumAPI {
|
|||
for (final map in list!) {
|
||||
final txn = EthTxDTO.fromMap(Map<String, dynamic>.from(map as Map));
|
||||
|
||||
if (txn.hasToken == 0) {
|
||||
if (txn.hasToken == 0 || includeTokens) {
|
||||
txns.add(txn);
|
||||
}
|
||||
}
|
||||
|
@ -76,9 +77,11 @@ abstract class EthereumAPI {
|
|||
null,
|
||||
);
|
||||
} else {
|
||||
throw EthApiException(
|
||||
"getEthTransactions($address) response is empty but status code is "
|
||||
"${response.statusCode}",
|
||||
// nice that the api returns an empty body instead of being
|
||||
// consistent and returning a json object with no transactions
|
||||
return EthereumResponse(
|
||||
[],
|
||||
null,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
|
@ -196,9 +199,11 @@ abstract class EthereumAPI {
|
|||
null,
|
||||
);
|
||||
} else {
|
||||
throw EthApiException(
|
||||
"getEthTransactionNonces($txns) response is empty but status code is "
|
||||
"${response.statusCode}",
|
||||
// nice that the api returns an empty body instead of being
|
||||
// consistent and returning a json object with no transactions
|
||||
return EthereumResponse(
|
||||
[],
|
||||
null,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
|
@ -252,13 +257,13 @@ abstract class EthereumAPI {
|
|||
);
|
||||
} else {
|
||||
throw EthApiException(
|
||||
"getEthTransaction($txids) response is empty but status code is "
|
||||
"getEthTokenTransactionsByTxids($txids) response is empty but status code is "
|
||||
"${response.statusCode}",
|
||||
);
|
||||
}
|
||||
} else {
|
||||
throw EthApiException(
|
||||
"getEthTransaction($txids) failed with status code: "
|
||||
"getEthTokenTransactionsByTxids($txids) failed with status code: "
|
||||
"${response.statusCode}",
|
||||
);
|
||||
}
|
||||
|
@ -269,7 +274,7 @@ abstract class EthereumAPI {
|
|||
);
|
||||
} catch (e, s) {
|
||||
Logging.instance.log(
|
||||
"getEthTransaction($txids): $e\n$s",
|
||||
"getEthTokenTransactionsByTxids($txids): $e\n$s",
|
||||
level: LogLevel.Error,
|
||||
);
|
||||
return EthereumResponse(
|
||||
|
@ -307,9 +312,11 @@ abstract class EthereumAPI {
|
|||
null,
|
||||
);
|
||||
} else {
|
||||
throw EthApiException(
|
||||
"getTokenTransactions($address, $tokenContractAddress) response is empty but status code is "
|
||||
"${response.statusCode}",
|
||||
// nice that the api returns an empty body instead of being
|
||||
// consistent and returning a json object with no transactions
|
||||
return EthereumResponse(
|
||||
[],
|
||||
null,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue