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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 1 deletions

View File

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