fix: memoize default provider to fix render loop (#584)

This commit is contained in:
Matthew Russell 2022-06-20 08:26:27 -07:00 committed by GitHub
parent a11efacba1
commit 23df113ace
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,7 +6,7 @@ import {
} from '@vegaprotocol/smart-contracts';
import { Splash } from '@vegaprotocol/ui-toolkit';
import { useWeb3React } from '@web3-react/core';
import React from 'react';
import React, { useMemo } from 'react';
import { SplashLoader } from '../../components/splash-loader';
import type { ContractsContextShape } from './contracts-context';
@ -25,9 +25,9 @@ export const ContractsProvider = ({ children }: { children: JSX.Element }) => {
useEnvironment();
const [contracts, setContracts] =
React.useState<ContractsContextShape | null>(null);
const defaultProvider = createDefaultProvider(
ETHEREUM_PROVIDER_URL,
ETHEREUM_CHAIN_ID
const defaultProvider = useMemo(
() => createDefaultProvider(ETHEREUM_PROVIDER_URL, ETHEREUM_CHAIN_ID),
[ETHEREUM_PROVIDER_URL, ETHEREUM_CHAIN_ID]
);
// Create instances of contract classes. If we have an account use a signer for the