add updated view for sntAvalanche

This commit is contained in:
Barry Gitarts 2021-02-19 11:13:19 -05:00
parent 2080f7ad9b
commit e4f0e07352
4 changed files with 27 additions and 11 deletions

View File

@ -11,8 +11,8 @@ import { getAndSetProvider } from './utils/network';
import { ERC20 } from './types/ERC20';
import { Bridge as IBridge } from './types/Bridge';
import Header from './components/Header';
import { getISntEthereum, getBridge } from './utils/contracts';
import { goerliProvider } from './utils/providers'
import { getSNTAvalanche, getSNTEthereum, getBridge } from './utils/contracts';
import { goerliProvider, fujiProvider } from './utils/providers'
import { ethereumAddress } from './constants/bridges';
const { useState, useEffect } = React;
@ -23,6 +23,7 @@ function App() {
const [ethereumProvider, setEthereumProvider] = useState<Provider>();
const [account, setAccount] = useState<string>('');
const [sntEthereum, setSntEthereum] = useState<ERC20>();
const [sntAvalanche, setSntAvalanche] = useState<ERC20>();
const [ethereumBridge, setEthereumBridge] = useState<IBridge>();
useEffect(() => {
@ -34,8 +35,10 @@ function App() {
useEffect(() => {
if (provider) {
const snt: ERC20 = getISntEthereum(goerliProvider)
setSntEthereum(snt);
const sntEthereum: ERC20 = getSNTEthereum(goerliProvider);
const sntAvalanche: ERC20 = getSNTAvalanche(fujiProvider);
setSntEthereum(sntEthereum);
setSntAvalanche(sntAvalanche);
}
}, [provider])
@ -67,6 +70,7 @@ function App() {
account={account}
provider={provider}
sntEthereum={sntEthereum}
sntAvalanche={sntAvalanche}
ethereumBridge={ethereumBridge}
/>}
</div>

View File

@ -11,7 +11,6 @@ import StatusButton from './base/Button';
import { ETHEREUM_CHAIN_ID, AVA_CHAIN_ID } from '../constants/networks';
import { createResourceID, createERCDepositData, toWei } from '../utils/helpers';
import { Web3Provider } from '@ethersproject/providers';
import { getISntEthereum } from '../utils/contracts';
import { ERC20 } from "../types/ERC20";
import { fromWei } from "../utils/helpers"
import { getSetBalance } from "../utils/contracts";
@ -27,6 +26,7 @@ interface Props {
account: string,
provider: Web3Provider | undefined,
sntEthereum: ERC20 | undefined,
sntAvalanche: ERC20 | undefined,
ethereumBridge: IBridge
}
const FUJI_BRIDGE = '0xE57Eb49689bCAE4dE61D326F7E79Bd14aB527f0f';
@ -38,14 +38,15 @@ const fujiVoidSigner = new VoidSigner(wallet.address, fujiProvider);
const goerliVoidsigner = new VoidSigner(wallet.address, goerliProvider);
export const Bridge: React.FC<Props> = ({ account, provider, sntEthereum, ethereumBridge }) => {
export const Bridge: React.FC<Props> = ({ account, provider, sntEthereum, sntAvalanche, ethereumBridge }) => {
const classes: any = useStyles()
const bridge: SymfoniBridge = useContext(BridgeContext);
const [message, setMessage] = useState("");
const [inputGreeting, setInputGreeting] = useState("");
const [goerliBridge, setGoerliBridge] = useState<IBridge>();
const [fujiBridge, setFujiBridge] = useState<IBridge>();
const [sntEthereumBalance, setSntEthereumBalance] = useState<BigNumberish>()
const [sntEthereumBalance, setSntEthereumBalance] = useState<BigNumberish>();
const [sntAvalancheBalance, setSntAvalancheBalance] = useState<BigNumberish>();
const { fieldWidth } = classes;
useEffect(() => {
const doAsync = async () => {
@ -71,6 +72,10 @@ export const Bridge: React.FC<Props> = ({ account, provider, sntEthereum, ethere
getSetBalance(sntEthereum, account, setSntEthereumBalance);
}, [account])
useEffect(() => {
getSetBalance(sntAvalanche, account, setSntAvalancheBalance);
}, [account])
return (
<Formik
initialValues={{
@ -119,6 +124,9 @@ export const Bridge: React.FC<Props> = ({ account, provider, sntEthereum, ethere
{!!sntEthereumBalance && <Typography className={classes.balanceText}>
SNT Ethereum balance: {fromWei(sntEthereumBalance)}
</Typography>}
{!!sntAvalancheBalance && <Typography className={classes.balanceText}>
SNT Avalanche balance: {fromWei(sntAvalancheBalance)}
</Typography>}
<StatusTextField
className={fieldWidth}
name="amount"

View File

@ -0,0 +1 @@
export const SNT_ADDRESS = '0xB4042F60Be43605B2A1e01eEE6cA757d7161217C';

View File

@ -1,13 +1,16 @@
import { Wallet, providers, Contract, VoidSigner } from "ethers";
import { SNT_ADDRESS } from "../constants/goerliAddress";
import { SNT_ADDRESS as SNT_ETHEREUM } from "../constants/goerliAddress";
import { SNT_ADDRESS as SNT_AVALANCHE } from "../constants/fuji";
import { ERC20 } from "../types/ERC20";
import { Bridge as IBridge } from "../types/Bridge";
import { Bridge__factory } from "../types/factories/Bridge__factory";
import { ERC20__factory } from "../types/factories/ERC20__factory";
import { Provider } from '@ethersproject/providers'
import { Provider } from '@ethersproject/providers';
export const getISntEthereum = (provider: Provider) => {
return ERC20__factory.connect(SNT_ADDRESS, provider);
export const getSNTEthereum = (provider: Provider) => getSNTContract(provider, SNT_ETHEREUM);
export const getSNTAvalanche = (provider: Provider) => getSNTContract(provider, SNT_AVALANCHE);
export const getSNTContract = (provider: Provider, address: string) => {
return ERC20__factory.connect(address, provider);
}
export const getBridge = (address: string, provider: Provider) => {