Skip to content

Commit

Permalink
feat(app): show balances for from chain
Browse files Browse the repository at this point in the history
  • Loading branch information
cor committed Jun 8, 2024
1 parent a263cd1 commit 5fba4f7
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions app/src/routes/transfer/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ $: if (
chains: $cosmosChains,
address: $cosmosStore.rawAddress
})
}
const queryParams = queryParameters(
Expand Down Expand Up @@ -124,6 +126,7 @@ function handleAssetSelect(id: string) {
// dialogOpenToken = false
}
const amountRegex = /[^0-9.]|\.(?=\.)|(?<=\.\d+)\./g
let amount = ""
Expand All @@ -133,6 +136,32 @@ $: {
amount = amount.replaceAll(amountRegex, "")
}
// @ts-ignore
let sendableBalances = null;
$: if (evmBalances !== null && cosmosBalances !== null && $cosmosChains !== null) {
sendableBalances = derived([queryParams, evmBalances, cosmosBalances], ([$queryParams, $evmBalances, $cosmosBalances]) => {
const fromChain = $queryParams["from-chain-id"];
if (fromChain === "11155111") {
if (!$evmBalances.isSuccess) {
alert('trying to send from evm but no balances fetched yet');
return [];
}
return $evmBalances.data;
}
const chainIndex = $cosmosChains.findIndex(c => c.chain_id === fromChain);
const cosmosBalance = $cosmosBalances[chainIndex]
if (!cosmosBalance.isSuccess) {
alert('trying to send from evm but no balances fetched yet');
return [];
}
return cosmosBalance.data
});
}
function swapChainsClick(_event: MouseEvent) {
const [fromChain, toChain] = [$queryParams["from-chain-id"], $queryParams["to-chain-id"]]
$queryParams["from-chain-id"] = toChain
Expand Down Expand Up @@ -182,6 +211,9 @@ let buttonText = "Transfer" satisfies
</div>
<!-- asset -->
<CardSectionHeading>Asset</CardSectionHeading>
{#if sendableBalances !== null}
<div>{JSON.stringify($sendableBalances)}</div>
{/if}
<Button variant="outline" on:click={() => (dialogOpenToken = !dialogOpenToken)}>

<!--
Expand Down

0 comments on commit 5fba4f7

Please sign in to comment.