diff --git a/src/components/LockupEvm.tsx b/src/components/LockupEvm.tsx index 5a7422a2..e5ec14e5 100644 --- a/src/components/LockupEvm.tsx +++ b/src/components/LockupEvm.tsx @@ -1,3 +1,4 @@ +import log from "loglevel"; import { Show, createEffect, createSignal } from "solid-js"; import { useGlobalContext } from "../context/Global"; @@ -7,6 +8,7 @@ import { HardwareSigner } from "../utils/hardware/HadwareSigner"; import { prefix0x, satoshiToWei } from "../utils/rootstock"; import ConnectWallet from "./ConnectWallet"; import ContractTransaction from "./ContractTransaction"; +import LoadingSpinner from "./LoadingSpinner"; const InsufficientBalance = () => { const { t } = useGlobalContext(); @@ -37,7 +39,7 @@ const LockupEvm = (props: { const value = () => satoshiToWei(props.amount); - const [signerBalance, setSignerBalance] = createSignal(0n); + const [signerBalance, setSignerBalance] = createSignal(undefined); // eslint-disable-next-line solid/reactivity createEffect(async () => { @@ -45,51 +47,63 @@ const LockupEvm = (props: { return; } - setSignerBalance( - await signer().provider.getBalance(await signer().getAddress()), + const balance = await signer().provider.getBalance( + await signer().getAddress(), ); + log.info("EVM signer balance", balance); + setSignerBalance(balance); }); return ( value()} - fallback={}> - { - const contract = getEtherSwap(); - const tx = await contract.lock( - prefix0x(props.preimageHash), - props.claimAddress, - props.timeoutBlockHeight, - { - value: value(), - }, - ); - const currentSwap = await getSwap(props.swapId); - currentSwap.lockupTx = tx.hash; - currentSwap.signer = signer().address; + when={signerBalance() !== undefined} + fallback={ + }> + + + }> + value()} + fallback={}> + { + const contract = getEtherSwap(); + const tx = await contract.lock( + prefix0x(props.preimageHash), + props.claimAddress, + props.timeoutBlockHeight, + { + value: value(), + }, + ); + const currentSwap = await getSwap(props.swapId); + currentSwap.lockupTx = tx.hash; + currentSwap.signer = signer().address; - if (customDerivationPathRdns.includes(signer().rdns)) { - currentSwap.derivationPath = ( - providers()[signer().rdns] - .provider as unknown as HardwareSigner - ).getDerivationPath(); - } + if (customDerivationPathRdns.includes(signer().rdns)) { + currentSwap.derivationPath = ( + providers()[signer().rdns] + .provider as unknown as HardwareSigner + ).getDerivationPath(); + } - setSwap(currentSwap); - await setSwapStorage(currentSwap); - }} - children={} - address={{ - address: props.signerAddress, - derivationPath: props.derivationPath, - }} - buttonText={t("send")} - promptText={t("transaction_prompt", { button: t("send") })} - waitingText={t("tx_in_mempool_subline")} - showHr={false} - /> + setSwap(currentSwap); + await setSwapStorage(currentSwap); + }} + children={} + address={{ + address: props.signerAddress, + derivationPath: props.derivationPath, + }} + buttonText={t("send")} + promptText={t("transaction_prompt", { button: t("send") })} + waitingText={t("tx_in_mempool_subline")} + showHr={false} + /> + ); };