Skip to content

Commit

Permalink
chore: general polishing of transfer page
Browse files Browse the repository at this point in the history
  • Loading branch information
dafuga committed Oct 27, 2023
1 parent 44dcf2d commit 25144fe
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/lib/evm/data/tokens.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"account": "eosio.evm",
"chain": "eos",
"supply": {
"precision": 2
"precision": 4
},
"metadata": {
"name": "USDT (EVM)",
Expand Down
15 changes: 13 additions & 2 deletions src/lib/evm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const evmChainConfigs: {[key: string]: EvmChainConfig} = {
chainName: 'EOS EVM Network',
tokens: [
{name: 'EOS', symbol: '4,EOS', decimals: 18, nativeToken: true},
{name: 'USDT', symbol: '2,USDT', decimals: 2, address: '0x33B57dC70014FD7AA6e1ed3080eeD2B619632B8e' },
{name: 'USDT', symbol: '4,USDT', decimals: 6, address: '0x33B57dC70014FD7AA6e1ed3080eeD2B619632B8e' },
],
rpcUrls: ['https://api.evm.eosnetwork.com/'],
blockExplorerUrls: ['https://explorer.evm.eosnetwork.com'],
Expand Down Expand Up @@ -132,13 +132,20 @@ export class EvmSession {
const contract = new ethers.Contract(token.address, erc20_abi, this.signer);

wei = await contract.balanceOf(this.address)

} else if (token?.nativeToken) {
wei = await this.signer.getBalance()
} else {
throw new Error('Non native token must have an address.')
}

return Asset.from(formatToken(ethers.utils.formatEther(wei), token.name))
const decimals = token.decimals

if (token.decimals === 18) {
return Asset.from(Number(ethers.utils.formatEther(wei)), token.symbol)
} else {
return Asset.from(fromWei(wei, decimals), token.symbol)
}
}

getBalances() {
Expand Down Expand Up @@ -343,3 +350,7 @@ export async function startEvmSession(): Promise<EvmSession | undefined> {

return evmSession
}

export function fromWei(wei: BigNumber, decimals: number) {
return wei.toNumber() / Math.pow(10, decimals);
}
4 changes: 2 additions & 2 deletions src/pages/transfer/form.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@
const token = $tokens.find(token => token.name === transferManagerData.tokenName)
if (!token) {
console.log({tokens: $tokens, tokenKey: transferManagerData.tokenName})
console.error(`Token ${transferManagerData.tokenName} not found`)
return
}
Expand All @@ -103,7 +102,7 @@
$: {
if (from) {
toOptions = fromOptions.filter((token) => token.name !== from?.name)
toOptions = fromOptions.filter((token) => from?.symbol.equals(token.symbol) && token.name !== from?.name) // this needs to only show options which involve the same token
} else {
toOptions = fromOptions
}
Expand All @@ -113,6 +112,7 @@
$: {
transferManager?.balance().then((balance) => {
console.log({ balance, feeAmount, amount })
availableToReceive = CoreAsset.from(
(balance?.value || 0) - (feeAmount?.value || 0),
balance?.symbol || '4,EOS'
Expand Down
7 changes: 5 additions & 2 deletions src/pages/transfer/managers/eosEvmBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {TransferManager} from './transferManager'
import {currentAccountBalance, evmBalance} from '~/store'
import {updateActiveAccount} from '~/stores/account-provider'
import {updateEvmBalance} from '~/stores/balances-provider'
import { balances } from '~/stores/balances'

export class EosEvmBridge extends TransferManager {
static supportedChains = ['eos']
Expand Down Expand Up @@ -58,8 +59,10 @@ export class EosEvmBridge extends TransferManager {
})
}

async balance() {
return get(currentAccountBalance)
async balance(tokenName?: string) {
const balance = get(balances).find((b) => b.tokenKey === tokenName)

return balance?.quantity
}

async receivingBalance() {
Expand Down
13 changes: 0 additions & 13 deletions src/pages/transfer/managers/evmEosBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,6 @@ export class EvmEosBridge extends TransferManager {
return {gas, gasPrice}
}

async balance() {
return get(evmBalance)
}

async receivingBalance() {
return get(currentAccountBalance)
}

async updateBalances() {
updateActiveAccount()
updateEvmBalance()
}

updateMainBalance() {
return updateEvmBalance()
}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/transfer/managers/transferManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export abstract class TransferManager {
}
/* eslint-enable @typescript-eslint/no-unused-vars */

balance(): Promise<Asset | undefined> {
balance(tokenName?: string): Promise<Asset | undefined> {
throw new Error('balance() not implemented')
}

Expand Down

0 comments on commit 25144fe

Please sign in to comment.