fix: only bind cluster stats on working connections (#18763)

This commit is contained in:
Josh
2021-07-19 10:59:47 -07:00
committed by GitHub
parent 6abafac479
commit d9970c0a7d

View File

@ -74,6 +74,13 @@ const PerformanceContext = React.createContext<PerformanceState | undefined>(
); );
type Props = { children: React.ReactNode }; type Props = { children: React.ReactNode };
function getConnection(url: string): Connection | undefined {
try {
return new Connection(url);
} catch (error) {}
}
export function SolanaClusterStatsProvider({ children }: Props) { export function SolanaClusterStatsProvider({ children }: Props) {
const { cluster, url } = useCluster(); const { cluster, url } = useCluster();
const [active, setActive] = React.useState(false); const [active, setActive] = React.useState(false);
@ -89,7 +96,10 @@ export function SolanaClusterStatsProvider({ children }: Props) {
React.useEffect(() => { React.useEffect(() => {
if (!active || !url) return; if (!active || !url) return;
const connection = new Connection(url); const connection = getConnection(url);
if (!connection) return;
let lastSlot: number | null = null; let lastSlot: number | null = null;
const getPerformanceSamples = async () => { const getPerformanceSamples = async () => {