ensure ethereumProvider

This commit is contained in:
Barry Gitarts 2021-03-01 14:41:30 -05:00
parent bce4f0059f
commit fed3f2e820
3 changed files with 18 additions and 42 deletions

View File

@ -13,7 +13,7 @@ import { ERC20 } from './types/ERC20';
import { Bridge as IBridge } from './types/Bridge'; import { Bridge as IBridge } from './types/Bridge';
import Header from './components/Header'; import Header from './components/Header';
import { getSNTAvalanche, getSNTEthereum, getBridge } from './utils/contracts'; import { getSNTAvalanche, getSNTEthereum, getBridge } from './utils/contracts';
import { goerliProvider, avaProvider } from './utils/providers' import { ethereumProvider, avaProvider } from './utils/providers'
import { ethereumAddress, avalancheAddress } from './constants/bridges'; import { ethereumAddress, avalancheAddress } from './constants/bridges';
const { useState, useEffect } = React; const { useState, useEffect } = React;
@ -21,7 +21,6 @@ const { useState, useEffect } = React;
function App() { function App() {
const classes: any = useStyles(); const classes: any = useStyles();
const [provider, setProvider] = useState<Web3Provider>(); const [provider, setProvider] = useState<Web3Provider>();
const [ethereumProvider, setEthereumProvider] = useState<Provider>();
const [account, setAccount] = useState<string>(''); const [account, setAccount] = useState<string>('');
const [sntEthereum, setSntEthereum] = useState<ERC20>(); const [sntEthereum, setSntEthereum] = useState<ERC20>();
const [sntAvalanche, setSntAvalanche] = useState<ERC20>(); const [sntAvalanche, setSntAvalanche] = useState<ERC20>();
@ -38,7 +37,7 @@ function App() {
useEffect(() => { useEffect(() => {
if (provider) { if (provider) {
const sntEthereum: ERC20 = getSNTEthereum(goerliProvider); const sntEthereum: ERC20 = getSNTEthereum(ethereumProvider);
const sntAvalanche: ERC20 = getSNTAvalanche(avaProvider); const sntAvalanche: ERC20 = getSNTAvalanche(avaProvider);
setSntEthereum(sntEthereum); setSntEthereum(sntEthereum);
setSntAvalanche(sntAvalanche); setSntAvalanche(sntAvalanche);
@ -51,7 +50,7 @@ function App() {
avalancheBridge.isRelayer(account).then(isRelayer => { avalancheBridge.isRelayer(account).then(isRelayer => {
setIsRelayer(isRelayer) setIsRelayer(isRelayer)
}); });
const ethereumBridge: IBridge = getBridge(ethereumAddress, provider); const ethereumBridge: IBridge = getBridge(ethereumAddress, ethereumProvider);
setEthereumBridge(ethereumBridge); setEthereumBridge(ethereumBridge);
setAvalancheBridge(avalancheBridge); setAvalancheBridge(avalancheBridge);
}, [provider]) }, [provider])
@ -74,18 +73,18 @@ function App() {
sntEthereum={sntEthereum} sntEthereum={sntEthereum}
/> />
{!!ethereumBridge && <Bridge {!!ethereumBridge && <Bridge
account={account} account={account}
provider={provider} provider={provider}
sntEthereum={sntEthereum} sntEthereum={sntEthereum}
sntAvalanche={sntAvalanche} sntAvalanche={sntAvalanche}
ethereumBridge={ethereumBridge} ethereumBridge={ethereumBridge}
/>} />}
{!!isRelayer && <AdminBridge {!!isRelayer && <AdminBridge
account={account} account={account}
provider={provider} provider={provider}
sntEthereum={sntEthereum} sntEthereum={sntEthereum}
sntAvalanche={sntAvalanche} sntAvalanche={sntAvalanche}
ethereumBridge={ethereumBridge} />} ethereumBridge={ethereumBridge} />}
</div> </div>
</Symfoni> </Symfoni>
</ThemeProvider> </ThemeProvider>

View File

@ -21,7 +21,6 @@ type IBridgeInfo = {
amount: string, amount: string,
account: string, account: string,
} }
const wallet = Wallet.createRandom();
interface Props { interface Props {
account: string, account: string,
@ -30,14 +29,6 @@ interface Props {
sntAvalanche: ERC20 | undefined, sntAvalanche: ERC20 | undefined,
ethereumBridge: IBridge | undefined, ethereumBridge: IBridge | undefined,
} }
const FUJI_BRIDGE = '0xE57Eb49689bCAE4dE61D326F7E79Bd14aB527f0f';
const GOERLI_BRIDGE = '0xD0E461b1Dc56503fC72565FA964C28E274146D44';
const fujiProvider = new providers.JsonRpcProvider("https://api.avax-test.network/ext/bc/C/rpc");
const goerliProvider = new providers.InfuraProvider("goerli");
const fujiSigner = new Wallet(wallet.privateKey, fujiProvider);
const fujiVoidSigner = new VoidSigner(wallet.address, fujiProvider);
const goerliVoidsigner = new VoidSigner(wallet.address, goerliProvider);
export const AdminBridge: React.FC<Props> = ({ account, provider, sntEthereum, sntAvalanche, ethereumBridge }) => { export const AdminBridge: React.FC<Props> = ({ account, provider, sntEthereum, sntAvalanche, ethereumBridge }) => {
const classes: any = useStyles() const classes: any = useStyles()
const bridge: SymfoniBridge = useContext(BridgeContext); const bridge: SymfoniBridge = useContext(BridgeContext);
@ -51,23 +42,7 @@ export const AdminBridge: React.FC<Props> = ({ account, provider, sntEthereum, s
const { fieldWidth } = classes; const { fieldWidth } = classes;
useEffect(() => { useEffect(() => {
getDepositEvents(ethereumBridge, setDeposits) getDepositEvents(ethereumBridge, setDeposits)
const doAsync = async () => {
if (!bridge.instance) return
console.log("Bridge is deployed at ", bridge.instance.address)
let gBridge = new Contract(
GOERLI_BRIDGE,
bridge.instance.interface,
goerliVoidsigner
) as IBridge;
setGoerliBridge(gBridge);
let fBridge = new Contract(
FUJI_BRIDGE,
bridge.instance.interface,
fujiVoidSigner
) as IBridge;
setFujiBridge(fBridge);
};
doAsync();
}, [bridge]) }, [bridge])
useEffect(() => { useEffect(() => {
@ -78,6 +53,8 @@ export const AdminBridge: React.FC<Props> = ({ account, provider, sntEthereum, s
getSetBalance(sntAvalanche, account, setSntAvalancheBalance); getSetBalance(sntAvalanche, account, setSntAvalancheBalance);
}, [account]) }, [account])
console.log({deposits})
return ( return (
<Formik <Formik
initialValues={{ initialValues={{

View File

@ -2,8 +2,8 @@ import { Wallet, providers, Contract, VoidSigner } from "ethers";
const wallet = Wallet.createRandom(); const wallet = Wallet.createRandom();
const avaURI = process.env.REACT_APP_AVALANCHE_URI || "https://api.avax-test.network/ext/bc/C/rpc"; const avaURI = process.env.REACT_APP_AVALANCHE_URI || "https://api.avax-test.network/ext/bc/C/rpc";
export const goerliProvider = new providers.InfuraProvider("goerli"); export const ethereumProvider = new providers.InfuraProvider("goerli");
export const avaProvider = new providers.JsonRpcProvider(avaURI); export const avaProvider = new providers.JsonRpcProvider(avaURI);
const avaSigner = new Wallet(wallet.privateKey, avaProvider); const avaSigner = new Wallet(wallet.privateKey, avaProvider);
export const avaVoidSigner = new VoidSigner(wallet.address, avaProvider); export const avaVoidSigner = new VoidSigner(wallet.address, avaProvider);
export const goerliVoidsigner = new VoidSigner(wallet.address, goerliProvider); export const goerliVoidsigner = new VoidSigner(wallet.address, ethereumProvider);