From a3783d4df824371efa3914bba0aeec4411025c69 Mon Sep 17 00:00:00 2001 From: Kirill Klimenko Date: Wed, 6 Mar 2024 18:13:52 +0100 Subject: [PATCH] Show cached prices on FE if request to CoinGecko failed --- src/components/pages/DAOTreasury/hooks/useFormatCoins.tsx | 8 +++++--- src/providers/App/hooks/usePriceAPI.ts | 4 ++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/components/pages/DAOTreasury/hooks/useFormatCoins.tsx b/src/components/pages/DAOTreasury/hooks/useFormatCoins.tsx index e0f1f8b526..3944108ff9 100644 --- a/src/components/pages/DAOTreasury/hooks/useFormatCoins.tsx +++ b/src/components/pages/DAOTreasury/hooks/useFormatCoins.tsx @@ -32,9 +32,11 @@ export function useFormatCoins(assets: SafeBalanceUsdResponse[]) { for (let i = 0; i < assets.length; i++) { let asset = assets[i]; if (asset.balance === '0') continue; - const tokenPrice = asset.tokenAddress - ? tokenPrices[asset.tokenAddress.toLowerCase()] - : tokenPrices.ethereum; + const tokenPrice = tokenPrices + ? asset.tokenAddress + ? tokenPrices[asset.tokenAddress.toLowerCase()] + : tokenPrices.ethereum + : 0; let tokenFiatBalance = 0; if (tokenPrice && asset.balance) { diff --git a/src/providers/App/hooks/usePriceAPI.ts b/src/providers/App/hooks/usePriceAPI.ts index 1e20353f61..c407fec6a7 100644 --- a/src/providers/App/hooks/usePriceAPI.ts +++ b/src/providers/App/hooks/usePriceAPI.ts @@ -32,6 +32,10 @@ export default function usePriceAPI() { if (pricesResponseBody.error) { // We don't need to log error here as it is supposed to be logged through Netlify function anyway toast.warning(t('tokenPriceFetchingError')); + if (pricesResponseBody.data) { + // Netlify function might fail due to rate limit of CoinGecko error, but it still will return cached prices. + return pricesResponseBody.data; + } } else { return pricesResponseBody.data; }