feat(explorer): reenable solana ping widget (#23443)
This commit is contained in:
parent
41f78b9925
commit
3ddd018452
|
@ -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>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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>;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue