From bfba6d9f5db33c2023da4b75b5da905801de506c Mon Sep 17 00:00:00 2001 From: julian Date: Mon, 22 Apr 2024 10:35:02 -0600 Subject: [PATCH] eth token price fetch "fix" and clearer eth token price fetch error logging --- lib/services/price.dart | 49 ++++++++++--------- .../electrumx_interface.dart | 6 --- 2 files changed, 27 insertions(+), 28 deletions(-) diff --git a/lib/services/price.dart b/lib/services/price.dart index ce1a57301..25a3f154b 100644 --- a/lib/services/price.dart +++ b/lib/services/price.dart @@ -187,33 +187,38 @@ class PriceAPI { } try { - final contractAddressesString = - contractAddresses.reduce((value, element) => "$value,$element"); - 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"); + 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" + "=$contractAddress&include_24hr_change=true"); - final coinGeckoResponse = await client.get( - url: uri, - headers: {'Content-Type': 'application/json'}, - proxyInfo: Prefs.instance.useTor - ? TorService.sharedInstance.getProxyInfo() - : null, - ); + final coinGeckoResponse = await client.get( + url: uri, + headers: {'Content-Type': 'application/json'}, + proxyInfo: Prefs.instance.useTor + ? TorService.sharedInstance.getProxyInfo() + : null, + ); - final coinGeckoData = jsonDecode(coinGeckoResponse.body) as Map; + 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 map = coinGeckoData[contractAddress] as Map; + final price = + Decimal.parse(map[baseCurrency.toLowerCase()].toString()); + final change24h = double.parse( + map["${baseCurrency.toLowerCase()}_24h_change"].toString()); - final price = Decimal.parse(map[baseCurrency.toLowerCase()].toString()); - final change24h = double.parse( - map["${baseCurrency.toLowerCase()}_24h_change"].toString()); - - tokenPrices[contractAddress] = Tuple2(price, change24h); + 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; diff --git a/lib/wallets/wallet/wallet_mixin_interfaces/electrumx_interface.dart b/lib/wallets/wallet/wallet_mixin_interfaces/electrumx_interface.dart index 51ca4ca70..52ceb2a77 100644 --- a/lib/wallets/wallet/wallet_mixin_interfaces/electrumx_interface.dart +++ b/lib/wallets/wallet/wallet_mixin_interfaces/electrumx_interface.dart @@ -697,12 +697,6 @@ mixin ElectrumXInterface on Bip39HDWallet { 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,