diff --git a/src/pages/transfer/confirm.svelte b/src/pages/transfer/confirm.svelte
index 42b3dca6..5839c746 100644
--- a/src/pages/transfer/confirm.svelte
+++ b/src/pages/transfer/confirm.svelte
@@ -5,9 +5,11 @@
import TokenImage from '~/components/elements/image/token.svelte'
import {systemTokenKey} from '~/stores/tokens'
- import type {TransferManager} from './managers/transferManager'
+ import type { TransferType } from './managers'
+ import type { TransferManager } from './managers/transferManager'
export let transferManager: TransferManager
+ export let transferManagerData: TransferType
export let depositAmount: Asset
export let receivedAmount: Asset
export let feeAmount: Asset | undefined
@@ -136,11 +138,11 @@
- From {transferManager.fromDisplayString} |
+ From {transferManagerData.fromLabel} |
{transferManager.fromAddress} |
- To {transferManager.toDisplayString} |
+ To {transferManagerData.toLabel} |
{transferManager.toAddress} |
diff --git a/src/pages/transfer/form.svelte b/src/pages/transfer/form.svelte
index 2074d9e3..8a29dc80 100644
--- a/src/pages/transfer/form.svelte
+++ b/src/pages/transfer/form.svelte
@@ -63,8 +63,14 @@
let generatingOptions = false
+ $: console.log({ balances: $balances })
+
$: balance = $balances.find((balance) => balance.tokenKey === from?.key)
+ $: console.log({ balance, from })
+
+ console.log({ tokens: $tokens })
+
async function generateOptions(evmSession?: EvmSession) {
if (!!generatingOptions) return
@@ -79,13 +85,10 @@
// Only displaying accounts that support the current chain
if (!TransferManagerClass.supportedChains.includes($activeBlockchain?.id)) return
- if (!TransferManagerClass.evmRequired || evmSession) {
- const transferManager = new (TransferManagerClass as unknown as new (
- ...args: any[]
- ) => TransferManager)($activeSession!, evmSession)
- }
-
- const token = $tokens.find(token => token.name === transferManagerData.tokenName)
+ const token = $tokens?.find(token =>
+ token.name === transferManagerData.tokenName &&
+ String(token.contract) === transferManagerData.tokenContract &&
+ token.chainId.equals($activeBlockchain?.chainId))
if (!token) {
console.error(`Token ${transferManagerData.tokenName} not found`)
@@ -107,10 +110,13 @@
}
}
- generateOptions()
+ $: {
+ if ($tokens) {
+ generateOptions()
+ }
+ }
$: {
- const balance = $balances.find((balance) => from?.key === balance.tokenKey)
const balanceAmount = balance?.quantity
availableToReceive = balanceAmount && CoreAsset.from(
(balanceAmount?.value || 0) - (feeAmount?.value || 0),
diff --git a/src/pages/transfer/index.svelte b/src/pages/transfer/index.svelte
index 9c09b32c..240ed31e 100644
--- a/src/pages/transfer/index.svelte
+++ b/src/pages/transfer/index.svelte
@@ -10,7 +10,7 @@
import Success from './success.svelte'
import Error from './error.svelte'
import {systemToken} from '~/stores/tokens'
- import {transferManagers} from './managers'
+ import {TransferType, transferManagers} from './managers'
import type {TransferManager} from './managers/transferManager'
import {startEvmSession} from '~/lib/evm'
@@ -25,13 +25,16 @@
let to: Token | undefined
let transactResult: TransactResult | ethers.providers.TransactionResponse | undefined
let transferFee: Asset | undefined
+ let transferManagerData: TransferType | undefined
let transferManager: TransferManager | undefined
$: systemContractSymbol = String($systemToken?.symbol)
$: balance = $balances?.find((balance) => balance.tokenKey === from?.key)?.quantity
+ $: receivingBalance = $balances?.find((balance) => balance.tokenKey === to?.key)?.quantity
$: {
- const transferManagerData =
+ transferManagerData =
from?.name && to?.name ? transferManagers[`${from.name} - ${to?.name}`] : undefined
+
const TransferManagerClass = transferManagerData?.transferClass
if (TransferManagerClass) {
@@ -51,7 +54,7 @@
const transferFeeValue = transferFee?.value || 0
received = (
- (balanceValue || 0) - (transferFeeValue === 0 ? 0 : transferFeeValue - 0.0001)
+ (balanceValue || 0) - (transferFeeValue === 0 ? 0 : transferFeeValue)
)?.toFixed(4)
}
@@ -96,6 +99,7 @@
try {
transferFee = await transferManager?.transferFee(transferAmount || received, from?.symbol)
} catch (error) {
+ console.log({ error })
if (
!error?.data?.message?.includes('insufficient funds for transfer') &&
!error?.data?.message?.includes('gas required exceeds allowance')
@@ -177,17 +181,18 @@
bind:from
bind:to
/>
- {:else if step === 'confirm' && receivedAmount}
+ {:else if step === 'confirm' && receivedAmount && transferManagerData}
{:else if step === 'success' && transactResult}
-
+
{/if}
diff --git a/src/pages/transfer/managers/eosEvmBridge.ts b/src/pages/transfer/managers/eosEvmBridge.ts
index 0632929d..26d3d9fa 100644
--- a/src/pages/transfer/managers/eosEvmBridge.ts
+++ b/src/pages/transfer/managers/eosEvmBridge.ts
@@ -38,7 +38,9 @@ export class EosEvmBridge extends TransferManager {
const config = apiResponse.rows[0]
- return Asset.from(config.ingress_bridge_fee || '0.0000 EOS')
+ const ingressBridgeFee = Asset.from(config.ingress_bridge_fee || '0.0000 EOS')
+
+ return Asset.from(ingressBridgeFee.value, tokenSymbol)
}
transfer(amount: string, tokenSymbol: Asset.SymbolType = '4,EOS') {
diff --git a/src/pages/transfer/managers/index.ts b/src/pages/transfer/managers/index.ts
index 354aa143..71f106f3 100644
--- a/src/pages/transfer/managers/index.ts
+++ b/src/pages/transfer/managers/index.ts
@@ -6,7 +6,7 @@ import {EvmEosBridge} from './evmEosBridge'
import {TelosEvmBridge} from './telosEvmBridge'
import type {TransferManager} from './transferManager'
-interface TransferType {
+export interface TransferType {
transferClass: typeof TransferManager
tokenName: string
tokenContract: NameType
@@ -29,7 +29,7 @@ export const transferManagers: {[key: string]: TransferType} = {
'EOS (EVM) - EOS': {
transferClass: EvmEosBridge,
tokenName: 'EOS (EVM)',
- tokenContract: 'eosio.token',
+ tokenContract: 'eosio.evm',
from: 'evm',
fromLabel: 'EOS (EVM)',
to: 'eos',
@@ -47,7 +47,7 @@ export const transferManagers: {[key: string]: TransferType} = {
'USDT (EVM) - USDT': {
transferClass: EvmEosBridge,
tokenName: 'USDT (EVM)',
- tokenContract: 'tethertether',
+ tokenContract: 'eosio.evm',
from: 'evm',
fromLabel: 'USDT (EVM)',
to: 'usdt',
diff --git a/src/pages/transfer/managers/telosEvmBridge.ts b/src/pages/transfer/managers/telosEvmBridge.ts
index 49db621a..e99e730d 100644
--- a/src/pages/transfer/managers/telosEvmBridge.ts
+++ b/src/pages/transfer/managers/telosEvmBridge.ts
@@ -4,6 +4,7 @@ import {Asset, Name} from 'anchor-link'
import {getTelosEvmAccount} from '~/lib/evm'
export class TelosEvmBridge extends TransferManager {
+ static supportedChains = ['telos']
static evmRequired = true
get fromAddress() {
diff --git a/src/pages/transfer/managers/transferManager.ts b/src/pages/transfer/managers/transferManager.ts
index a8b19488..92c83eab 100644
--- a/src/pages/transfer/managers/transferManager.ts
+++ b/src/pages/transfer/managers/transferManager.ts
@@ -1,12 +1,10 @@
import {Asset} from 'anchor-link'
import type {LinkSession, TransactResult} from 'anchor-link'
import type {ethers} from 'ethers'
-import {get} from 'svelte/store'
import type {EvmSession} from '~/lib/evm'
import {valueInFiat} from '~/lib/fiat'
import {activePriceTicker, waitForStoreValue} from '~/store'
-import {systemToken} from '~/stores/tokens'
export abstract class TransferManager {
self: typeof TransferManager
@@ -35,7 +33,7 @@ export abstract class TransferManager {
}
transferFee(_amount?: string, tokenSymbol?: Asset.SymbolType): Promise {
- return Promise.resolve(Asset.from(0, get(systemToken)?.symbol || '4,EOS'))
+ return Promise.resolve(Asset.from(0, tokenSymbol|| '4,EOS'))
}
/* eslint-enable @typescript-eslint/no-unused-vars */
diff --git a/src/pages/transfer/success.svelte b/src/pages/transfer/success.svelte
index 89f79f96..57014c83 100644
--- a/src/pages/transfer/success.svelte
+++ b/src/pages/transfer/success.svelte
@@ -6,17 +6,21 @@
import {activeBlockchain} from '~/store'
import type {TransferManager} from './managers/transferManager'
+ import { updateBalances } from '~/stores/balances-provider'
+ import { activeSession } from '~/store'
export let transferManager: TransferManager
export let transactResult: TransactResult | ethers.providers.TransactionResponse
export let handleBack: () => void
+ export let balance: Asset | undefined
+ export let receivingBalance: Asset | undefined
let refreshInterval: NodeJS.Timeout
async function awaitBalancesUpdate() {
// Create a copy of the initial value
- const initialSendingBalance = await transferManager.balance()
- const initialReceivedBalance = await transferManager.receivingBalance()
+ const initialSendingBalance = balance
+ const initialReceivedBalance = receivingBalance
if (!initialSendingBalance) return
if (!initialReceivedBalance) return
@@ -27,8 +31,8 @@
// Start an interval to continously monitor for changes to that value
refreshInterval = setInterval(async () => {
- currentSendingBalance = await transferManager.balance()
- currentReceivedBalance = await transferManager.receivingBalance()
+ currentSendingBalance = balance
+ currentReceivedBalance = receivingBalance
// If the balances changed, stop the interval
if (
@@ -38,7 +42,7 @@
clearInterval(refreshInterval)
}
// Fetch the balances
- transferManager.updateBalances()
+ updateBalances($activeSession!)
}, 1000)
// Timeout after 30 seconds