diff --git a/src/lib/evm.ts b/src/lib/evm.ts index 6d4b6308..8e5bdecf 100644 --- a/src/lib/evm.ts +++ b/src/lib/evm.ts @@ -1,12 +1,12 @@ import type {LinkSession} from 'anchor-link' import {Asset, Name} from 'anchor-link' import {ethers} from 'ethers' -import { API } from 'anchor-link' +import {API} from 'anchor-link' import BN from 'bn.js' import {Transfer} from '~/abi-types' -import { getClient } from '~/api-client' +import {getClient} from '~/api-client' let provider: ethers.providers.Web3Provider @@ -136,8 +136,8 @@ export async function estimateGas({nativeSession, evmAccount, amount}: TransferP const gasPrice = await provider.getGasPrice() // Reducing the amount by 0.005 EOS to avoid getting an error when entire balance is sent. Proper amount is calculated once the gas fee is known. - const reducedAmount = String(Number(amount) - 0.005) - + const reducedAmount = String(Number(amount) - 0.005) + const gas = await provider.estimateGas({ from: evmAccount.address, to: targetEvmAddress, @@ -149,7 +149,11 @@ export async function estimateGas({nativeSession, evmAccount, amount}: TransferP return {gas, gasPrice} } -export async function getNativeTransferFee({nativeSession}: { nativeSession: LinkSession }): Promise { +export async function getNativeTransferFee({ + nativeSession, +}: { + nativeSession: LinkSession +}): Promise { const apiClient = getClient(nativeSession.chainId) let apiResponse @@ -169,8 +173,12 @@ export async function getNativeTransferFee({nativeSession}: { nativeSession: Lin return Asset.from(config.ingress_bridge_fee) } -export async function getGasAmount({nativeSession, evmAccount, amount}: TransferParams): Promise { - const { gas, gasPrice } = await estimateGas({nativeSession, evmAccount, amount}) +export async function getGasAmount({ + nativeSession, + evmAccount, + amount, +}: TransferParams): Promise { + const {gas, gasPrice} = await estimateGas({nativeSession, evmAccount, amount}) const eosAmount = ethers.utils.formatEther(Number(gas) * Number(gasPrice)) @@ -180,7 +188,7 @@ export async function getGasAmount({nativeSession, evmAccount, amount}: Transfer export async function transferEvmToNative({nativeSession, evmAccount, amount}: TransferParams) { const targetEvmAddress = convertToEvmAddress(String(nativeSession.auth.actor)) - const { gas } = await estimateGas({nativeSession, evmAccount, amount}) + const {gas} = await estimateGas({nativeSession, evmAccount, amount}) return evmAccount.sendTransaction({ from: evmAccount.address, diff --git a/src/pages/transfer/confirm.svelte b/src/pages/transfer/confirm.svelte index bee2c18b..cc6747f3 100644 --- a/src/pages/transfer/confirm.svelte +++ b/src/pages/transfer/confirm.svelte @@ -91,7 +91,7 @@ Fee Amount - {feeAmount || '0.0000 EOS' } + {feeAmount || '0.0000 EOS'} Received Amount diff --git a/src/pages/transfer/form.svelte b/src/pages/transfer/form.svelte index 4e608285..d166f7db 100644 --- a/src/pages/transfer/form.svelte +++ b/src/pages/transfer/form.svelte @@ -192,11 +192,8 @@
- Continue {#if !$evmAccount}

Connect to metamask wallet to continue

diff --git a/src/pages/transfer/index.svelte b/src/pages/transfer/index.svelte index f159300b..7259e5e7 100644 --- a/src/pages/transfer/index.svelte +++ b/src/pages/transfer/index.svelte @@ -4,7 +4,14 @@ import {activeSession, evmAccount} from '~/store' - import {transferNativeToEvm, transferEvmToNative, connectEthWallet, estimateGas, getGasAmount, getNativeTransferFee} from '~/lib/evm' + import { + transferNativeToEvm, + transferEvmToNative, + connectEthWallet, + estimateGas, + getGasAmount, + getNativeTransferFee, + } from '~/lib/evm' import Page from '~/components/layout/page.svelte' import Form from './form.svelte' @@ -67,8 +74,6 @@ step = 'confirm' - - try { if (from?.name === 'EOS') { transferFee = await getNativeTransferFee({ @@ -86,7 +91,7 @@ JSON.stringify(error) === '{}' ? error.message : JSON.stringify(error) }`) } - + received = (parseFloat(deposit) - parseFloat(transferFee.value.toFixed(4))).toFixed(4) }