diff --git a/src/lib/evm/data/tokens.json b/src/lib/evm/data/tokens.json index 0a9a2027..9a53260a 100644 --- a/src/lib/evm/data/tokens.json +++ b/src/lib/evm/data/tokens.json @@ -25,7 +25,7 @@ "account": "eosio.evm", "chain": "eos", "supply": { - "precision": 2 + "precision": 4 }, "metadata": { "name": "USDT (EVM)", diff --git a/src/lib/evm/index.ts b/src/lib/evm/index.ts index 49310597..0dc3489a 100644 --- a/src/lib/evm/index.ts +++ b/src/lib/evm/index.ts @@ -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'], @@ -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() { @@ -343,3 +350,7 @@ export async function startEvmSession(): Promise { return evmSession } + +export function fromWei(wei: BigNumber, decimals: number) { + return wei.toNumber() / Math.pow(10, decimals); +} diff --git a/src/pages/transfer/form.svelte b/src/pages/transfer/form.svelte index 16e198d4..f3cb41a5 100644 --- a/src/pages/transfer/form.svelte +++ b/src/pages/transfer/form.svelte @@ -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 } @@ -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 } @@ -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' diff --git a/src/pages/transfer/managers/eosEvmBridge.ts b/src/pages/transfer/managers/eosEvmBridge.ts index 3c51c6e6..71b3c658 100644 --- a/src/pages/transfer/managers/eosEvmBridge.ts +++ b/src/pages/transfer/managers/eosEvmBridge.ts @@ -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'] @@ -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() { diff --git a/src/pages/transfer/managers/evmEosBridge.ts b/src/pages/transfer/managers/evmEosBridge.ts index d5abb504..0f19b212 100644 --- a/src/pages/transfer/managers/evmEosBridge.ts +++ b/src/pages/transfer/managers/evmEosBridge.ts @@ -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() } diff --git a/src/pages/transfer/managers/transferManager.ts b/src/pages/transfer/managers/transferManager.ts index 29c217db..909bf80e 100644 --- a/src/pages/transfer/managers/transferManager.ts +++ b/src/pages/transfer/managers/transferManager.ts @@ -39,7 +39,7 @@ export abstract class TransferManager { } /* eslint-enable @typescript-eslint/no-unused-vars */ - balance(): Promise { + balance(tokenName?: string): Promise { throw new Error('balance() not implemented') }