Skip to content

Commit

Permalink
Only show CoinGecko information on Mainnet (#295)
Browse files Browse the repository at this point in the history
I often use a USDC-on-devnet coin in workshops, which I guess has a
CoinGecko ID
I think it's a bit weird that the CoinGecko data shows when I look at
that coin on Explorer on Devnet
This PR changes `useCoinGecko` to only fetch and return data on Mainnet
  • Loading branch information
mcintyre94 authored Dec 15, 2023
1 parent 91eab21 commit 5dcb646
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;
}

1 comment on commit 5dcb646

@vercel
Copy link

@vercel vercel bot commented on 5dcb646 Dec 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

explorer – ./

explorer.solana.com
explorer-git-master-solana-labs.vercel.app
explorer-solana-labs.vercel.app

Please sign in to comment.