diff --git a/app/src/lib/components/TransferFrom/components/DebugBox.svelte b/app/src/lib/components/TransferFrom/components/DebugBox.svelte index 02e435f7c9..477fdb11fb 100644 --- a/app/src/lib/components/TransferFrom/components/DebugBox.svelte +++ b/app/src/lib/components/TransferFrom/components/DebugBox.svelte @@ -1,22 +1,21 @@
@@ -33,31 +32,31 @@ const { userAddress, sourceChain, destinationChain, balances, assetInfo, chains
- +
- +
- +
- +
- +
- +
- +
\ No newline at end of file diff --git a/app/src/lib/components/TransferFrom/index.svelte b/app/src/lib/components/TransferFrom/index.svelte index 508c0f36c8..75fd2ad8e6 100644 --- a/app/src/lib/components/TransferFrom/index.svelte +++ b/app/src/lib/components/TransferFrom/index.svelte @@ -117,6 +117,6 @@ {/if} \ No newline at end of file diff --git a/app/src/lib/components/TransferFrom/transfer/context.ts b/app/src/lib/components/TransferFrom/transfer/context.ts index 102590150c..e521329631 100644 --- a/app/src/lib/components/TransferFrom/transfer/context.ts +++ b/app/src/lib/components/TransferFrom/transfer/context.ts @@ -13,7 +13,6 @@ export type AddressBalance = { gasToken: boolean address: Address symbol: string - chain_id: string } export type NamedBalance = { @@ -22,12 +21,9 @@ export type NamedBalance = { name: string | null symbol: string gasToken: boolean - chain_id: string } -export type EmptyBalance = { - chain_id: string -} +export type EmptyBalance = {} export type Balance = AddressBalance | NamedBalance | EmptyBalance @@ -75,18 +71,22 @@ export function createContextStore(intents: IntentStore): Readable userAddress, userBalancesQuery({ chains, connected: true, userAddr: get(userAddress) }) ], - ([_intentsValue, _userAddressValue, rawBalances]) => { - return rawBalances.flatMap((balanceResult, index) => { - const chain = chains[index] - if (!balanceResult?.isSuccess || balanceResult.data instanceof Error) { - return [] - } - return balanceResult.data.map(balance => ({ - ...balance, - balance: BigInt(balance.balance), - chain_id: chain.chain_id // Add chain_id to each balance - })) - }) + ([intentsValue, _userAddressValue, rawBalances]) => { + const sourceChain = chains.find(chain => chain.chain_id === intentsValue.source) + if (!sourceChain) return [] + + const chainIndex = chains.findIndex(c => c.chain_id === sourceChain.chain_id) + const balanceResult = rawBalances[chainIndex] + + if (!balanceResult?.isSuccess || balanceResult.data instanceof Error) { + console.log("No balances fetched yet for selected chain") + return [] + } + + return balanceResult.data.map(balance => ({ + ...balance, + balance: BigInt(balance.balance) + })) } ) diff --git a/app/src/lib/components/TransferFrom/transfer/intents.ts b/app/src/lib/components/TransferFrom/transfer/intents.ts index 07b2f84dc6..8b536fcd3a 100644 --- a/app/src/lib/components/TransferFrom/transfer/intents.ts +++ b/app/src/lib/components/TransferFrom/transfer/intents.ts @@ -121,4 +121,4 @@ export function createIntentStore(): IntentStore { set(defaultParams) } } -} +} \ No newline at end of file