fix: multisigner app

This commit is contained in:
Dexter 2022-11-03 17:21:08 +00:00
parent 999c768090
commit 57446c508a
3 changed files with 43 additions and 55 deletions

View File

@ -74,21 +74,23 @@ function App() {
return ( return (
<ThemeContext.Provider value={theme}> <ThemeContext.Provider value={theme}>
<Web3Provider connectors={Connectors}> <AsyncRenderer loading={loading} data={config} error={error}>
<Web3Connector dialogOpen={dialogOpen} setDialogOpen={setDialogOpen}> <Web3Provider connectors={Connectors}>
<div className={pageWrapperClasses}> <Web3Connector dialogOpen={dialogOpen} setDialogOpen={setDialogOpen}>
<AsyncRenderer loading={loading} data={config} error={error}> <EthWalletContainer
<Header theme={theme} toggleTheme={toggleTheme} /> dialogOpen={dialogOpen}
<EthWalletContainer setDialogOpen={setDialogOpen}
dialogOpen={dialogOpen} >
setDialogOpen={setDialogOpen} <ContractsProvider>
> <div className={pageWrapperClasses}>
<ConnectedApp config={config} /> <Header theme={theme} toggleTheme={toggleTheme} />
</EthWalletContainer> <ConnectedApp config={config} />
</AsyncRenderer> </div>
</div> </ContractsProvider>
</Web3Connector> </EthWalletContainer>
</Web3Provider> </Web3Connector>
</Web3Provider>
</AsyncRenderer>
</ThemeContext.Provider> </ThemeContext.Provider>
); );
} }
@ -97,9 +99,7 @@ const Wrapper = () => {
return ( return (
<EnvironmentProvider> <EnvironmentProvider>
<NetworkLoader createClient={createClient}> <NetworkLoader createClient={createClient}>
<ContractsProvider> <App />
<App />
</ContractsProvider>
</NetworkLoader> </NetworkLoader>
</EnvironmentProvider> </EnvironmentProvider>
); );

View File

@ -1,21 +1,23 @@
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import { MultisigControl } from '@vegaprotocol/smart-contracts'; import { MultisigControl } from '@vegaprotocol/smart-contracts';
import { Splash } from '@vegaprotocol/ui-toolkit'; import { Splash } from '@vegaprotocol/ui-toolkit';
import { ethers } from 'ethers';
import type { ContractsContextShape } from './contracts-context'; import type { ContractsContextShape } from './contracts-context';
import { ContractsContext } from './contracts-context'; import { ContractsContext } from './contracts-context';
import { useEthereumConfig } from '@vegaprotocol/web3'; import { useEthereumConfig } from '@vegaprotocol/web3';
import { useEnvironment } from '@vegaprotocol/environment'; import { useEnvironment } from '@vegaprotocol/environment';
import { useWeb3React } from '@web3-react/core';
/** /**
* Provides Vega Ethereum contract instances to its children. * Provides Vega Ethereum contract instances to its children.
*/ */
export const ContractsProvider = ({ children }: { children: JSX.Element }) => { export const ContractsProvider = ({ children }: { children: JSX.Element }) => {
const { provider: activeProvider, account } = useWeb3React();
const { config } = useEthereumConfig(); const { config } = useEthereumConfig();
const { VEGA_ENV, ETHEREUM_PROVIDER_URL } = useEnvironment(); const { VEGA_ENV, ETHEREUM_PROVIDER_URL } = useEnvironment();
const [contracts, setContracts] = useState<ContractsContextShape | null>( const [contracts, setContracts] = useState<ContractsContextShape | null>(
null null
); );
console.log(activeProvider);
// Create instances of contract classes. If we have an account use a signer for the // 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 // contracts so that we can sign transactions, otherwise use the provider for just
@ -24,19 +26,21 @@ export const ContractsProvider = ({ children }: { children: JSX.Element }) => {
let cancelled = false; let cancelled = false;
const run = async () => { const run = async () => {
if (config) { if (config) {
const provider = new ethers.providers.JsonRpcProvider( if (
ETHEREUM_PROVIDER_URL, account &&
Number(config.chain_id) activeProvider &&
); typeof activeProvider.getSigner === 'function'
) {
if (provider && config) { const signer = activeProvider.getSigner();
if (!cancelled) { if (activeProvider && config) {
setContracts({ if (!cancelled) {
multisig: new MultisigControl( setContracts({
config.multisig_control_contract.address, multisig: new MultisigControl(
provider config.multisig_control_contract.address,
), signer
}); ),
});
}
} }
} }
} }
@ -46,7 +50,7 @@ export const ContractsProvider = ({ children }: { children: JSX.Element }) => {
// TODO: hacky quick fix for release to prevent race condition, find a better fix for this. // TODO: hacky quick fix for release to prevent race condition, find a better fix for this.
cancelled = true; cancelled = true;
}; };
}, [config, VEGA_ENV, ETHEREUM_PROVIDER_URL]); }, [config, VEGA_ENV, ETHEREUM_PROVIDER_URL, account, activeProvider]);
if (!contracts) { if (!contracts) {
return <Splash>Error: cannot get data on multisig contract</Splash>; return <Splash>Error: cannot get data on multisig contract</Splash>;

View File

@ -1,4 +1,4 @@
import { ethers, BigNumber } from 'ethers'; import { ethers } from 'ethers';
import abi from '../abis/multisig_abi.json'; import abi from '../abis/multisig_abi.json';
export class MultisigControl { export class MultisigControl {
@ -14,15 +14,11 @@ export class MultisigControl {
} }
add_signer(newSigner: string, nonce: string, signatures: string) { add_signer(newSigner: string, nonce: string, signatures: string) {
return this.contract.add_signer( return this.contract.add_signer(newSigner, nonce, signatures);
newSigner,
BigNumber.from(nonce),
signatures
);
} }
burn_nonce(nonce: string, signatures: string) { burn_nonce(nonce: string, signatures: string) {
return this.contract.burn_nonce(BigNumber.from(nonce), signatures); return this.contract.burn_nonce(nonce, signatures);
} }
get_current_threshold() { get_current_threshold() {
@ -42,19 +38,11 @@ export class MultisigControl {
} }
remove_signer(oldSigner: string, nonce: string, signatures: string) { remove_signer(oldSigner: string, nonce: string, signatures: string) {
return this.contract.remove_signer( return this.contract.remove_signer(oldSigner, nonce, signatures);
oldSigner,
BigNumber.from(nonce),
signatures
);
} }
set_threshold(newThreshold: string, nonce: string, signatures: string) { set_threshold(newThreshold: string, nonce: string, signatures: string) {
return this.contract.set_threshold( return this.contract.set_threshold(newThreshold, nonce, signatures);
newThreshold,
BigNumber.from(nonce),
signatures
);
} }
signers(address: string) { signers(address: string) {
@ -62,10 +50,6 @@ export class MultisigControl {
} }
verify_signatures(nonce: string, message: string, signatures: string) { verify_signatures(nonce: string, message: string, signatures: string) {
return this.contract.verify_signatures( return this.contract.verify_signatures(nonce, message, signatures);
BigNumber.from(nonce),
message,
signatures
);
} }
} }