* Feat/807: ABI and classes for the contract methods * Feat/807: Added a new multisig-signer app * Feat/807: Added a new multisig-signer app * Feat/800: Untested signer forms * Feat/800: Moved reused bg video into ui-toolkit to use in multisig-signer project, and cleaned up some spacing that was overlooked in the stats theme changes * Feat/800: Componentised a bit, made the app look ok * Feat/800: Linting, prettifying, removing some unneeded tests, ensuring e2e tests run * Feat/800: Bit of translation * chore: fix type errors * chore: some parts error handling * feat: handle error and not found cases * feat: add changes to remove signer form as well * chore: rename component * chore: fix type issues * feat: add web3 connector logic * feat: allow disconnecting and show connected eth wallet info * Feat/800: Removed unused 'useApolloClient' * Feat/800: Ensure bundle.nonce and bundle.signatures have '0x' prepended * Feat/800: Removed unused e2e directory * Feat/800: Removed unnecessary app test * Feat/800: Removed unnecessary router * Feat/800: Capturing GQL errors in Sentry * Feat/800: Removing references to the unused e2e test directory * Feat/807: Consistent react hook imports * Feat/807: Removed unnecessary spreads Co-authored-by: Dexter <dexter.edwards93@gmail.com>
61 lines
1.9 KiB
TypeScript
61 lines
1.9 KiB
TypeScript
import { useEffect, useState } from 'react';
|
|
import { MultisigControl } from '@vegaprotocol/smart-contracts';
|
|
import { Splash } from '@vegaprotocol/ui-toolkit';
|
|
import { ethers } from 'ethers';
|
|
import type { ContractsContextShape } from './contracts-context';
|
|
import { ContractsContext } from './contracts-context';
|
|
import { useEthereumConfig } from '@vegaprotocol/web3';
|
|
import { useEnvironment } from '@vegaprotocol/environment';
|
|
|
|
/**
|
|
* Provides Vega Ethereum contract instances to its children.
|
|
*/
|
|
export const ContractsProvider = ({ children }: { children: JSX.Element }) => {
|
|
const { config } = useEthereumConfig();
|
|
const { VEGA_ENV, ETHEREUM_PROVIDER_URL } = useEnvironment();
|
|
const [contracts, setContracts] = useState<ContractsContextShape | null>(
|
|
null
|
|
);
|
|
|
|
// Create instances of contract classes. If we have an account use a signer for the
|
|
// contracts so that we can sign transactions, otherwise use the provider for just
|
|
// reading data
|
|
useEffect(() => {
|
|
let cancelled = false;
|
|
const run = async () => {
|
|
if (config) {
|
|
const provider = new ethers.providers.JsonRpcProvider(
|
|
ETHEREUM_PROVIDER_URL,
|
|
Number(config.chain_id)
|
|
);
|
|
|
|
if (provider && config) {
|
|
if (!cancelled) {
|
|
setContracts({
|
|
multisig: new MultisigControl(
|
|
config.multisig_control_contract.address,
|
|
provider
|
|
),
|
|
});
|
|
}
|
|
}
|
|
}
|
|
};
|
|
run();
|
|
return () => {
|
|
// TODO: hacky quick fix for release to prevent race condition, find a better fix for this.
|
|
cancelled = true;
|
|
};
|
|
}, [config, VEGA_ENV, ETHEREUM_PROVIDER_URL]);
|
|
|
|
if (!contracts) {
|
|
return <Splash>Error: cannot get data on multisig contract</Splash>;
|
|
}
|
|
|
|
return (
|
|
<ContractsContext.Provider value={contracts}>
|
|
{children}
|
|
</ContractsContext.Provider>
|
|
);
|
|
};
|