diff --git a/src/components/LockupEvm.tsx b/src/components/LockupEvm.tsx index e5ec14e5..77e81973 100644 --- a/src/components/LockupEvm.tsx +++ b/src/components/LockupEvm.tsx @@ -10,6 +10,8 @@ import ConnectWallet from "./ConnectWallet"; import ContractTransaction from "./ContractTransaction"; import LoadingSpinner from "./LoadingSpinner"; +const lockupGasUsage = 46_000n; + const InsufficientBalance = () => { const { t } = useGlobalContext(); @@ -47,11 +49,16 @@ const LockupEvm = (props: { return; } - const balance = await signer().provider.getBalance( - await signer().getAddress(), - ); - log.info("EVM signer balance", balance); - setSignerBalance(balance); + const [balance, gasPrice] = await Promise.all([ + signer().provider.getBalance(await signer().getAddress()), + signer() + .provider.getFeeData() + .then((data) => data.gasPrice), + ]); + + const spendable = balance - gasPrice * lockupGasUsage; + log.info("EVM signer spendable balance", spendable); + setSignerBalance(spendable); }); return ( diff --git a/src/context/Web3.tsx b/src/context/Web3.tsx index fcc18157..263a1837 100644 --- a/src/context/Web3.tsx +++ b/src/context/Web3.tsx @@ -1,6 +1,11 @@ import { abi as EtherSwapAbi } from "boltz-core/out/EtherSwap.sol/EtherSwap.json"; import { EtherSwap } from "boltz-core/typechain/EtherSwap"; -import { BrowserProvider, Contract, JsonRpcSigner } from "ethers"; +import { + BrowserProvider, + Contract, + JsonRpcProvider, + JsonRpcSigner, +} from "ethers"; import log from "loglevel"; import { Accessor, @@ -160,7 +165,8 @@ const Web3SignerProvider = (props: { return new Contract( contracts().swapContracts.EtherSwap, EtherSwapAbi, - signer(), + signer() || + new JsonRpcProvider(config.assets["RBTC"]?.network?.rpcUrls[0]), ) as unknown as EtherSwap; };