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

View File

@ -1,21 +1,23 @@
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';
import { useWeb3React } from '@web3-react/core';
/**
* Provides Vega Ethereum contract instances to its children.
*/
export const ContractsProvider = ({ children }: { children: JSX.Element }) => {
const { provider: activeProvider, account } = useWeb3React();
const { config } = useEthereumConfig();
const { VEGA_ENV, ETHEREUM_PROVIDER_URL } = useEnvironment();
const [contracts, setContracts] = useState<ContractsContextShape | null>(
null
);
console.log(activeProvider);
// 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
@ -24,19 +26,21 @@ export const ContractsProvider = ({ children }: { children: JSX.Element }) => {
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
),
});
if (
account &&
activeProvider &&
typeof activeProvider.getSigner === 'function'
) {
const signer = activeProvider.getSigner();
if (activeProvider && config) {
if (!cancelled) {
setContracts({
multisig: new MultisigControl(
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.
cancelled = true;
};
}, [config, VEGA_ENV, ETHEREUM_PROVIDER_URL]);
}, [config, VEGA_ENV, ETHEREUM_PROVIDER_URL, account, activeProvider]);
if (!contracts) {
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';
export class MultisigControl {
@ -14,15 +14,11 @@ export class MultisigControl {
}
add_signer(newSigner: string, nonce: string, signatures: string) {
return this.contract.add_signer(
newSigner,
BigNumber.from(nonce),
signatures
);
return this.contract.add_signer(newSigner, nonce, signatures);
}
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() {
@ -42,19 +38,11 @@ export class MultisigControl {
}
remove_signer(oldSigner: string, nonce: string, signatures: string) {
return this.contract.remove_signer(
oldSigner,
BigNumber.from(nonce),
signatures
);
return this.contract.remove_signer(oldSigner, nonce, signatures);
}
set_threshold(newThreshold: string, nonce: string, signatures: string) {
return this.contract.set_threshold(
newThreshold,
BigNumber.from(nonce),
signatures
);
return this.contract.set_threshold(newThreshold, nonce, signatures);
}
signers(address: string) {
@ -62,10 +50,6 @@ export class MultisigControl {
}
verify_signatures(nonce: string, message: string, signatures: string) {
return this.contract.verify_signatures(
BigNumber.from(nonce),
message,
signatures
);
return this.contract.verify_signatures(nonce, message, signatures);
}
}