Skip to content

Commit

Permalink
Only show CoinGecko information on Mainnet
Browse files Browse the repository at this point in the history
  • Loading branch information
mcintyre94 committed Sep 27, 2023
1 parent 3e5b2a7 commit d55cd51
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions app/utils/coingecko.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import React from 'react';
import useTabVisibility from 'use-tab-visibility';

import { useCluster } from '../providers/cluster';
import { Cluster } from './cluster';

const PRICE_REFRESH = 10000;

export enum CoingeckoStatus {
Expand Down Expand Up @@ -43,6 +46,7 @@ export type CoinGeckoResult = {
};

export function useCoinGecko(coinId?: string): CoinGeckoResult | undefined {
const { cluster } = useCluster()
const [coinInfo, setCoinInfo] = React.useState<CoinGeckoResult>();
const { visible: isTabVisible } = useTabVisibility();
React.useEffect(() => {
Expand All @@ -52,6 +56,9 @@ export function useCoinGecko(coinId?: string): CoinGeckoResult | undefined {
if (!isTabVisible) {
return;
}
if (cluster !== Cluster.MainnetBeta) {
return;
}
let interval: NodeJS.Timeout | undefined;
let stale = false;
if (coinId) {
Expand All @@ -64,14 +71,14 @@ export function useCoinGecko(coinId?: string): CoinGeckoResult | undefined {
try {
const response = await fetch(
`https://api.coingecko.com/api/v3/coins/${coinId}?` +
[
'community_data=false',
'developer_data=false',
'localization=false',
'market_data=true',
'sparkline=false',
'tickers=false',
].join('&')
[
'community_data=false',
'developer_data=false',
'localization=false',
'market_data=true',
'sparkline=false',
'tickers=false',
].join('&')
);
if (stale) {
return;
Expand Down Expand Up @@ -106,7 +113,7 @@ export function useCoinGecko(coinId?: string): CoinGeckoResult | undefined {
}
stale = true;
};
}, [coinId, isTabVisible]);
}, [coinId, isTabVisible, cluster]);

return coinInfo;
}

0 comments on commit d55cd51

Please sign in to comment.