diff --git a/src/pages/transfer/form.svelte b/src/pages/transfer/form.svelte index f3cb41a5..2074d9e3 100644 --- a/src/pages/transfer/form.svelte +++ b/src/pages/transfer/form.svelte @@ -11,6 +11,7 @@ import type {TransferManager} from './managers/transferManager' import {transferManagers} from './managers' import type {EvmSession} from '~/lib/evm' + import { balances } from '~/stores/balances' export let handleContinue: () => void export let amount: string = '' @@ -62,6 +63,8 @@ let generatingOptions = false + $: balance = $balances.find((balance) => balance.tokenKey === from?.key) + async function generateOptions(evmSession?: EvmSession) { if (!!generatingOptions) return @@ -76,14 +79,10 @@ // Only displaying accounts that support the current chain if (!TransferManagerClass.supportedChains.includes($activeBlockchain?.id)) return - let accountBalance - if (!TransferManagerClass.evmRequired || evmSession) { const transferManager = new (TransferManagerClass as unknown as new ( ...args: any[] ) => TransferManager)($activeSession!, evmSession) - await transferManager.updateMainBalance() - accountBalance = await transferManager.balance() } const token = $tokens.find(token => token.name === transferManagerData.tokenName) @@ -111,13 +110,12 @@ generateOptions() $: { - transferManager?.balance().then((balance) => { - console.log({ balance, feeAmount, amount }) - availableToReceive = CoreAsset.from( - (balance?.value || 0) - (feeAmount?.value || 0), - balance?.symbol || '4,EOS' - ) - }) + const balance = $balances.find((balance) => from?.key === balance.tokenKey) + const balanceAmount = balance?.quantity + availableToReceive = balanceAmount && CoreAsset.from( + (balanceAmount?.value || 0) - (feeAmount?.value || 0), + balanceAmount?.symbol || '4,EOS' + ) } // Continue when the user presses enter diff --git a/src/pages/transfer/index.svelte b/src/pages/transfer/index.svelte index be09ae94..9c09b32c 100644 --- a/src/pages/transfer/index.svelte +++ b/src/pages/transfer/index.svelte @@ -15,6 +15,7 @@ import {startEvmSession} from '~/lib/evm' import type {Token} from '~/stores/tokens' + import { balances } from '~/stores/balances' let step = 'form' let deposit: string = '' @@ -27,6 +28,7 @@ let transferManager: TransferManager | undefined $: systemContractSymbol = String($systemToken?.symbol) + $: balance = $balances?.find((balance) => balance.tokenKey === from?.key)?.quantity $: { const transferManagerData = from?.name && to?.name ? transferManagers[`${from.name} - ${to?.name}`] : undefined @@ -40,11 +42,7 @@ } async function useEntireBalance() { - if (!from || !to) return - - const balance = await transferManager?.balance() - - if (!balance) return + if (!from || !to || !balance) return const balanceValue = balance.value @@ -96,7 +94,7 @@ } try { - transferFee = await transferManager?.transferFee(transferAmount || received) + transferFee = await transferManager?.transferFee(transferAmount || received, from?.symbol) } catch (error) { if ( !error?.data?.message?.includes('insufficient funds for transfer') && @@ -152,8 +150,8 @@ // Eventually we may want to get the symbol from the transferManager instead of the systemToken $: receivedAmount = isNaN(Number(received)) ? undefined - : Asset.from(Number(received), systemContractSymbol) - $: depositAmount = Asset.from(Number(deposit), systemContractSymbol) + : Asset.from(Number(received), from?.symbol || systemContractSymbol) + $: depositAmount = Asset.from(Number(deposit), from?.symbol || systemContractSymbol)