Skip to content

Commit

Permalink
Show cached prices on FE if request to CoinGecko failed
Browse files Browse the repository at this point in the history
  • Loading branch information
mudrila committed Mar 6, 2024
1 parent 8633535 commit a3783d4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/components/pages/DAOTreasury/hooks/useFormatCoins.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions src/providers/App/hooks/usePriceAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit a3783d4

Please sign in to comment.