Skip to content

Commit

Permalink
style: linted
Browse files Browse the repository at this point in the history
  • Loading branch information
dafuga committed Aug 14, 2023
1 parent 2580d70 commit ffcebd8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 18 deletions.
24 changes: 16 additions & 8 deletions src/lib/evm.ts
Original file line number Diff line number Diff line change
@@ -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'

Check warning on line 4 in src/lib/evm.ts

View workflow job for this annotation

GitHub Actions / Node.js

'API' is defined but never used

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

Expand Down Expand Up @@ -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,
Expand All @@ -149,7 +149,11 @@ export async function estimateGas({nativeSession, evmAccount, amount}: TransferP
return {gas, gasPrice}
}

export async function getNativeTransferFee({nativeSession}: { nativeSession: LinkSession }): Promise<Asset> {
export async function getNativeTransferFee({
nativeSession,
}: {
nativeSession: LinkSession
}): Promise<Asset> {
const apiClient = getClient(nativeSession.chainId)

let apiResponse
Expand All @@ -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<Asset> {
const { gas, gasPrice } = await estimateGas({nativeSession, evmAccount, amount})
export async function getGasAmount({
nativeSession,
evmAccount,
amount,
}: TransferParams): Promise<Asset> {
const {gas, gasPrice} = await estimateGas({nativeSession, evmAccount, amount})

const eosAmount = ethers.utils.formatEther(Number(gas) * Number(gasPrice))

Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/pages/transfer/confirm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
</tr>
<tr>
<td>Fee Amount</td>
<td>{feeAmount || '0.0000 EOS' }</td>
<td>{feeAmount || '0.0000 EOS'}</td>
</tr>
<tr>
<td>Received Amount</td>
Expand Down
7 changes: 2 additions & 5 deletions src/pages/transfer/form.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,8 @@
</div>
</div>
<div class="bottom-section">
<Button
fluid
style="primary"
disabled={!readyToContinue}
on:action={onContinue}>Continue</Button
<Button fluid style="primary" disabled={!readyToContinue} on:action={onContinue}
>Continue</Button
>
{#if !$evmAccount}
<h3>Connect to metamask wallet to continue</h3>
Expand Down
13 changes: 9 additions & 4 deletions src/pages/transfer/index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -67,8 +74,6 @@
step = 'confirm'
try {
if (from?.name === 'EOS') {
transferFee = await getNativeTransferFee({
Expand All @@ -86,7 +91,7 @@
JSON.stringify(error) === '{}' ? error.message : JSON.stringify(error)
}`)
}
received = (parseFloat(deposit) - parseFloat(transferFee.value.toFixed(4))).toFixed(4)
}
Expand Down

0 comments on commit ffcebd8

Please sign in to comment.