bridge_ui: reset keeps chains, switchEthChain req

Change-Id: I3a4ff01bb3324969cbd2c02d91dbb8dfa8df066d
This commit is contained in:
Evan Gray 2021-09-02 21:13:03 -04:00
parent 14e891ac6e
commit 3eae629a1b
5 changed files with 35 additions and 35 deletions

View File

@ -24,6 +24,7 @@ import {
makeStyles, makeStyles,
MenuItem, MenuItem,
TextField, TextField,
Tooltip,
Typography, Typography,
} from "@material-ui/core"; } from "@material-ui/core";
import { Restore } from "@material-ui/icons"; import { Restore } from "@material-ui/icons";
@ -121,7 +122,6 @@ async function terra(tx: string) {
const emitterAddress = await getEmitterAddressTerra( const emitterAddress = await getEmitterAddressTerra(
TERRA_TOKEN_BRIDGE_ADDRESS TERRA_TOKEN_BRIDGE_ADDRESS
); );
console.log(emitterAddress);
const { vaaBytes } = await getSignedVAA( const { vaaBytes } = await getSignedVAA(
WORMHOLE_RPC_HOST, WORMHOLE_RPC_HOST,
CHAIN_ID_TERRA, CHAIN_ID_TERRA,
@ -441,9 +441,11 @@ export default function Recovery({
}, [setOpen]); }, [setOpen]);
return ( return (
<> <>
<Tooltip title="Open Recovery Dialog">
<Fab className={classes.fab} onClick={handleOpenClick}> <Fab className={classes.fab} onClick={handleOpenClick}>
<Restore /> <Restore />
</Fab> </Fab>
</Tooltip>
<Dialog open={open} onClose={handleCloseClick} maxWidth="md" fullWidth> <Dialog open={open} onClose={handleCloseClick} maxWidth="md" fullWidth>
<DialogTitle>Recovery</DialogTitle> <DialogTitle>Recovery</DialogTitle>
<RecoveryDialogContent onClose={handleCloseClick} disabled={disabled} /> <RecoveryDialogContent onClose={handleCloseClick} disabled={disabled} />

View File

@ -175,7 +175,6 @@ const getSolanaParsedTokenAccounts = (
}) })
.then( .then(
(result) => { (result) => {
console.log(result);
const mappedItems = result.value.map((item) => const mappedItems = result.value.map((item) =>
createParsedTokenAccountFromInfo(item.pubkey, item.account) createParsedTokenAccountFromInfo(item.pubkey, item.account)
); );

View File

@ -4,6 +4,7 @@ import {
CHAIN_ID_SOLANA, CHAIN_ID_SOLANA,
CHAIN_ID_TERRA, CHAIN_ID_TERRA,
} from "@certusone/wormhole-sdk"; } from "@certusone/wormhole-sdk";
import { hexlify, hexStripZeros } from "@ethersproject/bytes";
import { useConnectedWallet } from "@terra-money/wallet-provider"; import { useConnectedWallet } from "@terra-money/wallet-provider";
import { useMemo } from "react"; import { useMemo } from "react";
import { useEthereumProvider } from "../contexts/EthereumProviderContext"; import { useEthereumProvider } from "../contexts/EthereumProviderContext";
@ -43,6 +44,13 @@ function useIsWalletReady(chainId: ChainId): {
if (hasCorrectEthNetwork) { if (hasCorrectEthNetwork) {
return createWalletStatus(true); return createWalletStatus(true);
} else { } else {
if (provider) {
try {
provider.send("wallet_switchEthereumChain", [
{ chainId: hexStripZeros(hexlify(ETH_NETWORK_CHAIN_ID)) },
]);
} catch (e) {}
}
return createWalletStatus( return createWalletStatus(
false, false,
`Wallet is not connected to ${CLUSTER}. Expected Chain ID: ${ETH_NETWORK_CHAIN_ID}` `Wallet is not connected to ${CLUSTER}. Expected Chain ID: ${ETH_NETWORK_CHAIN_ID}`
@ -51,7 +59,14 @@ function useIsWalletReady(chainId: ChainId): {
} }
//TODO bsc //TODO bsc
return createWalletStatus(false, "Wallet not connected"); return createWalletStatus(false, "Wallet not connected");
}, [chainId, hasTerraWallet, solPK, hasEthInfo, hasCorrectEthNetwork]); }, [
chainId,
hasTerraWallet,
solPK,
hasEthInfo,
hasCorrectEthNetwork,
provider,
]);
} }
export default useIsWalletReady; export default useIsWalletReady;

View File

@ -2,14 +2,8 @@ import {
ChainId, ChainId,
CHAIN_ID_ETH, CHAIN_ID_ETH,
CHAIN_ID_SOLANA, CHAIN_ID_SOLANA,
CHAIN_ID_TERRA,
} from "@certusone/wormhole-sdk"; } from "@certusone/wormhole-sdk";
import { createSlice, PayloadAction } from "@reduxjs/toolkit"; import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import {
ETH_TEST_TOKEN_ADDRESS,
SOL_TEST_TOKEN_ADDRESS,
TERRA_TEST_TOKEN_ADDRESS,
} from "../utils/consts";
const LAST_STEP = 3; const LAST_STEP = 3;
@ -28,7 +22,7 @@ export interface AttestState {
const initialState: AttestState = { const initialState: AttestState = {
activeStep: 0, activeStep: 0,
sourceChain: CHAIN_ID_SOLANA, sourceChain: CHAIN_ID_SOLANA,
sourceAsset: SOL_TEST_TOKEN_ADDRESS, sourceAsset: "",
targetChain: CHAIN_ID_ETH, targetChain: CHAIN_ID_ETH,
signedVAAHex: undefined, signedVAAHex: undefined,
isSending: false, isSending: false,
@ -51,16 +45,7 @@ export const attestSlice = createSlice({
setSourceChain: (state, action: PayloadAction<ChainId>) => { setSourceChain: (state, action: PayloadAction<ChainId>) => {
const prevSourceChain = state.sourceChain; const prevSourceChain = state.sourceChain;
state.sourceChain = action.payload; state.sourceChain = action.payload;
// TODO: remove or check env - for testing purposes state.sourceAsset = "";
if (action.payload === CHAIN_ID_ETH) {
state.sourceAsset = ETH_TEST_TOKEN_ADDRESS;
}
if (action.payload === CHAIN_ID_SOLANA) {
state.sourceAsset = SOL_TEST_TOKEN_ADDRESS;
}
if (action.payload === CHAIN_ID_TERRA) {
state.sourceAsset = TERRA_TEST_TOKEN_ADDRESS;
}
if (state.targetChain === action.payload) { if (state.targetChain === action.payload) {
state.targetChain = prevSourceChain; state.targetChain = prevSourceChain;
} }
@ -74,16 +59,7 @@ export const attestSlice = createSlice({
if (state.sourceChain === action.payload) { if (state.sourceChain === action.payload) {
state.sourceChain = prevTargetChain; state.sourceChain = prevTargetChain;
state.activeStep = 0; state.activeStep = 0;
// TODO: remove or check env - for testing purposes state.sourceAsset = "";
if (state.targetChain === CHAIN_ID_ETH) {
state.sourceAsset = ETH_TEST_TOKEN_ADDRESS;
}
if (state.targetChain === CHAIN_ID_SOLANA) {
state.sourceAsset = SOL_TEST_TOKEN_ADDRESS;
}
if (state.targetChain === CHAIN_ID_TERRA) {
state.sourceAsset = TERRA_TEST_TOKEN_ADDRESS;
}
} }
}, },
setSignedVAAHex: (state, action: PayloadAction<string>) => { setSignedVAAHex: (state, action: PayloadAction<string>) => {
@ -97,7 +73,11 @@ export const attestSlice = createSlice({
setIsCreating: (state, action: PayloadAction<boolean>) => { setIsCreating: (state, action: PayloadAction<boolean>) => {
state.isCreating = action.payload; state.isCreating = action.payload;
}, },
reset: () => initialState, reset: (state) => ({
...initialState,
sourceChain: state.sourceChain,
targetChain: state.targetChain,
}),
}, },
}); });

View File

@ -181,7 +181,11 @@ export const transferSlice = createSlice({
setRedeemTx: (state, action: PayloadAction<Transaction>) => { setRedeemTx: (state, action: PayloadAction<Transaction>) => {
state.redeemTx = action.payload; state.redeemTx = action.payload;
}, },
reset: () => initialState, reset: (state) => ({
...initialState,
sourceChain: state.sourceChain,
targetChain: state.targetChain,
}),
}, },
}); });