feat(explorer): reenable solana ping widget (#23443)

This commit is contained in:
Josh 2022-03-02 08:11:35 -08:00 committed by GitHub
parent 41f78b9925
commit 3ddd018452
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 8 deletions

View File

@ -18,6 +18,7 @@ import { useVoteAccounts } from "providers/accounts/vote-accounts";
import { CoingeckoStatus, useCoinGecko } from "utils/coingecko"; import { CoingeckoStatus, useCoinGecko } from "utils/coingecko";
import { Epoch } from "components/common/Epoch"; import { Epoch } from "components/common/Epoch";
import { TimestampToggle } from "components/common/TimestampToggle"; import { TimestampToggle } from "components/common/TimestampToggle";
import { SolanaPingCard } from "components/SolanaPingCard";
const CLUSTER_STATS_TIMEOUT = 5000; const CLUSTER_STATS_TIMEOUT = 5000;
@ -36,7 +37,7 @@ export function ClusterStatsPage() {
<StatsCardBody /> <StatsCardBody />
</div> </div>
<TpsCard /> <TpsCard />
{/* <SolanaPingCard /> */} <SolanaPingCard />
</div> </div>
); );
} }

View File

@ -1,6 +1,7 @@
import React from "react"; import React from "react";
import { Cluster, clusterSlug, useCluster } from "providers/cluster"; import { Cluster, clusterSlug, useCluster } from "providers/cluster";
import { fetch } from "cross-fetch"; import { fetch } from "cross-fetch";
import { useStatsProvider } from "providers/stats/solanaClusterStats";
const FETCH_PING_INTERVAL = 60 * 1000; const FETCH_PING_INTERVAL = 60 * 1000;
@ -33,7 +34,6 @@ export type PingInfo = {
export enum PingStatus { export enum PingStatus {
Loading, Loading,
Refreshing,
Ready, Ready,
Error, Error,
} }
@ -76,11 +76,16 @@ function downsample(points: PingInfo[], bucketSize: number): PingInfo[] {
export function SolanaPingProvider({ children }: Props) { export function SolanaPingProvider({ children }: Props) {
const { cluster } = useCluster(); const { cluster } = useCluster();
const { active } = useStatsProvider();
const [rollup, setRollup] = React.useState<PingRollupInfo | undefined>({ const [rollup, setRollup] = React.useState<PingRollupInfo | undefined>({
status: PingStatus.Loading, status: PingStatus.Loading,
}); });
React.useEffect(() => { React.useEffect(() => {
if (!active) {
return;
}
const url = getPingUrl(cluster); const url = getPingUrl(cluster);
setRollup({ setRollup({
@ -137,17 +142,13 @@ export function SolanaPingProvider({ children }: Props) {
}; };
const fetchPingInterval = setInterval(() => { const fetchPingInterval = setInterval(() => {
setRollup({
status: PingStatus.Refreshing,
});
fetchPingMetrics(); fetchPingMetrics();
}, FETCH_PING_INTERVAL); }, FETCH_PING_INTERVAL);
fetchPingMetrics(); fetchPingMetrics();
return () => { return () => {
clearInterval(fetchPingInterval); clearInterval(fetchPingInterval);
}; };
}, [cluster]); }, [cluster, active]);
return <PingContext.Provider value={rollup}>{children}</PingContext.Provider>; return <PingContext.Provider value={rollup}>{children}</PingContext.Provider>;
} }

View File

@ -1,7 +1,12 @@
import { SolanaPingProvider } from "providers/stats/SolanaPingProvider";
import React from "react"; import React from "react";
import { SolanaClusterStatsProvider } from "./solanaClusterStats"; import { SolanaClusterStatsProvider } from "./solanaClusterStats";
type Props = { children: React.ReactNode }; type Props = { children: React.ReactNode };
export function StatsProvider({ children }: Props) { export function StatsProvider({ children }: Props) {
return <SolanaClusterStatsProvider>{children}</SolanaClusterStatsProvider>; return (
<SolanaClusterStatsProvider>
<SolanaPingProvider>{children}</SolanaPingProvider>
</SolanaClusterStatsProvider>
);
} }