Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(app): fix test page #3482

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 14 additions & 23 deletions app/src/routes/balances/UserBalances.svelte
Original file line number Diff line number Diff line change
@@ -1,31 +1,21 @@
<script lang="ts">
import { derived, type Readable, writable } from "svelte/store"
import type { Chain, UserAddresses } from "$lib/types"
import { userAddressAptos } from "$lib/wallet/aptos"
import { userAddrCosmos } from "$lib/wallet/cosmos"
import { userAddrEvm } from "$lib/wallet/evm"
import { writable, derived } from "svelte/store"
import type { Chain } from "$lib/types"
import { userBalancesQuery } from "$lib/queries/balance"
import { userAddress, balanceStore } from "$lib/components/TransferFrom/transfer/balances.ts"

export let chains: Array<Chain>

let userAddress: Readable<UserAddresses> = derived(
[userAddrCosmos, userAddrEvm, userAddressAptos],
([$userAddrCosmos, $userAddrEvm, $userAddressAptos]) => ({
evm: $userAddrEvm,
cosmos: $userAddrCosmos,
aptos: $userAddressAptos
})
)

$: chainBalances = allChainBalances(chains, userAddress)
$: userBalancesQueries = userBalancesQuery({ chains, userAddr: $userAddress, connected: true })
$: balanceStore.set($userBalancesQueries.map(query => query.data || []))

let hideZeroBalances = writable(true)

$: filteredChainBalances = derived(
[chainBalances, hideZeroBalances],
([$chainBalances, $hideZeroBalances]) => {
if (!$hideZeroBalances) return $chainBalances
return $chainBalances.map(chainAssets =>
chainAssets.filter(asset => BigInt(asset.balance) > 0n)
$: filteredBalanceStore = derived(
[balanceStore, hideZeroBalances],
([$balanceStore, $hideZeroBalances]) => {
return $balanceStore.map(chainAssets =>
$hideZeroBalances ? chainAssets.filter(asset => BigInt(asset.balance) > 0n) : chainAssets
)
}
)
Expand All @@ -46,15 +36,16 @@ function formatBalance(balance: string, decimals: number | null): string {
<label for="hideZeroBalances">Hide zero balances</label>
</div>

{#each $filteredChainBalances as chainAssets, chainIndex}
{#each $filteredBalanceStore as chainAssets, chainIndex}
{#if chainAssets?.length}
<div class="rounded-lg border p-4">
<h2 class="text-lg font-semibold mb-3">
{chains[chainIndex].display_name}
</h2>
<div class="space-y-2">
{#each chainAssets as asset}
<div class="flex items-center justify-between p-2 hover:bg-gray-50 rounded">
<div class="flex items-center justify-between p-2 hover:bg-gray-50 rounded"
class:opacity-50={BigInt(asset.balance) === 0n}>
<div class="flex items-center space-x-2">
<span class="font-medium">{asset.metadata.display_symbol ?? asset.metadata.denom}</span>
{#if asset.metadata.display_name}
Expand Down
Loading