diff --git a/bridge_ui/src/App.js b/bridge_ui/src/App.js index 4c824bff..71b4f8aa 100644 --- a/bridge_ui/src/App.js +++ b/bridge_ui/src/App.js @@ -44,6 +44,7 @@ import Stats from "./components/Stats"; import TokenOriginVerifier from "./components/TokenOriginVerifier"; import SolanaQuickMigrate from "./components/Migration/SolanaQuickMigrate"; import Wormhole from "./icons/wormhole-network.svg"; +import WithdrawTokensTerra from "./components/WithdrawTokensTerra"; const useStyles = makeStyles((theme) => ({ appBar: { @@ -323,6 +324,9 @@ function App() { + + + diff --git a/bridge_ui/src/components/WithdrawTokensTerra.tsx b/bridge_ui/src/components/WithdrawTokensTerra.tsx new file mode 100644 index 00000000..0ff179fb --- /dev/null +++ b/bridge_ui/src/components/WithdrawTokensTerra.tsx @@ -0,0 +1,116 @@ +import { useCallback, useState } from "react"; +import { MsgExecuteContract } from "@terra-money/terra.js"; +import { + ConnectedWallet, + useConnectedWallet, +} from "@terra-money/wallet-provider"; +import { + SUPPORTED_TERRA_TOKENS, + TERRA_TOKEN_BRIDGE_ADDRESS, +} from "../utils/consts"; +import TerraWalletKey from "./TerraWalletKey"; +import { + Container, + FormControl, + InputLabel, + makeStyles, + MenuItem, + Select, + Typography, +} from "@material-ui/core"; +import { postWithFees, waitForTerraExecution } from "../utils/terra"; +import ButtonWithLoader from "./ButtonWithLoader"; +import { useSnackbar } from "notistack"; +import { Alert } from "@material-ui/lab"; + +const useStyles = makeStyles((theme) => ({ + formControl: { + display: "flex", + margin: `${theme.spacing(1)}px auto`, + width: "100%", + maxWidth: 400, + textAlign: "center", + }, +})); + +const withdraw = async (wallet: ConnectedWallet, token: string) => { + const withdraw = new MsgExecuteContract( + wallet.walletAddress, + TERRA_TOKEN_BRIDGE_ADDRESS, + { + withdraw_tokens: { + asset: { + native_token: { + denom: token, + }, + }, + }, + }, + {} + ); + const txResult = await postWithFees( + wallet, + [withdraw], + "Wormhole - Withdraw Tokens" + ); + await waitForTerraExecution(txResult); +}; + +export default function WithdrawTokensTerra() { + const wallet = useConnectedWallet(); + const [token, setToken] = useState(SUPPORTED_TERRA_TOKENS[0]); + const [isLoading, setIsLoading] = useState(false); + const classes = useStyles(); + const { enqueueSnackbar } = useSnackbar(); + + const handleClick = useCallback(() => { + if (wallet) { + (async () => { + setIsLoading(true); + try { + await withdraw(wallet, token); + enqueueSnackbar(null, { + content: Transaction confirmed., + }); + } catch (e) { + enqueueSnackbar(null, { + content: Error withdrawing tokens., + }); + console.error(e); + } + setIsLoading(false); + })(); + } + }, [wallet, token, enqueueSnackbar]); + + return ( + + + Withdraw tokens from the Terra token bridge + + + + Token + + + Withdraw + + + + ); +}