eth token price fetch "fix" and clearer eth token price fetch error logging

This commit is contained in:
julian 2024-04-22 10:35:02 -06:00
parent 622740a8c0
commit bfba6d9f5d
2 changed files with 27 additions and 28 deletions

View file

@ -187,12 +187,11 @@ class PriceAPI {
}
try {
final contractAddressesString =
contractAddresses.reduce((value, element) => "$value,$element");
for (final contractAddress in contractAddresses) {
final uri = Uri.parse(
"https://api.coingecko.com/api/v3/simple/token_price/ethereum"
"?vs_currencies=${baseCurrency.toLowerCase()}&contract_addresses"
"=$contractAddressesString&include_24hr_change=true");
"=$contractAddress&include_24hr_change=true");
final coinGeckoResponse = await client.get(
url: uri,
@ -202,18 +201,24 @@ class PriceAPI {
: null,
);
try {
final coinGeckoData = jsonDecode(coinGeckoResponse.body) as Map;
for (final key in coinGeckoData.keys) {
final contractAddress = key as String;
final map = coinGeckoData[contractAddress] as Map;
final price = Decimal.parse(map[baseCurrency.toLowerCase()].toString());
final price =
Decimal.parse(map[baseCurrency.toLowerCase()].toString());
final change24h = double.parse(
map["${baseCurrency.toLowerCase()}_24h_change"].toString());
tokenPrices[contractAddress] = Tuple2(price, change24h);
} catch (e, s) {
// only log the error as we don't want to interrupt the rest of the loop
Logging.instance.log(
"getPricesAnd24hChangeForEthTokens($baseCurrency,$contractAddress): $e\n$s\nRESPONSE: $coinGeckoResponse.body",
level: LogLevel.Warning,
);
}
}
return tokenPrices;

View file

@ -697,12 +697,6 @@ mixin ElectrumXInterface<T extends Bip39HDCurrency> on Bip39HDWallet<T> {
cryptoCurrency.networkParams,
);
print("=============================================================");
print("$i ${txData.recipients![i].amount.decimal}");
print("$i ${txData.recipients![i].amount.raw}");
print("$address");
print("=============================================================");
final output = coinlib.Output.fromAddress(
txData.recipients![i].amount.raw,
address,