From f23a311a72d37620531a4d03d853a63b075ff9d2 Mon Sep 17 00:00:00 2001 From: dafuga Date: Mon, 16 Oct 2023 12:52:51 -0700 Subject: [PATCH] fix: only displaying tokens with balance on send/receive page --- .../elements/input/token/selector.svelte | 21 ++++++++++++++++++- src/pages/transfer/form.svelte | 2 ++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/components/elements/input/token/selector.svelte b/src/components/elements/input/token/selector.svelte index 2380c5f3..4f9c9cc7 100644 --- a/src/components/elements/input/token/selector.svelte +++ b/src/components/elements/input/token/selector.svelte @@ -4,6 +4,7 @@ import {activeBlockchain} from '~/store' import type {Token} from '~/stores/tokens' import {tokens} from '~/stores/tokens' + import {balances} from '~/stores/balances' import Form from '~/components/elements/form.svelte' import Input from '~/components/elements/input.svelte' @@ -16,6 +17,13 @@ export let selectedToken: Token | undefined = undefined export let tokenOptions: Token[] | undefined = undefined export let onTokenSelect: (token: Token) => void + export let showTokensWithoutBalance: boolean = false + + $: { + if (defaultToken) { + selectedToken = defaultToken + } + } let displayModal = writable(false) let query: string = '' @@ -42,11 +50,22 @@ ($tokens && $tokens.filter((token) => { const blockchainMatches = token.chainId.equals($activeBlockchain.chainId) + let balanceExists + if (!showTokensWithoutBalance) { + balanceExists = !!( + token.balance || + $balances.find((balance) => balance.tokenKey === token.key) + ) + } const queryExists = query.length === 0 const queryMatches = String(token.name) .toLowerCase() .includes(query.toLowerCase()) - return blockchainMatches && (queryExists || queryMatches) + return ( + blockchainMatches && + (queryExists || queryMatches) && + (showTokensWithoutBalance || balanceExists) + ) })) || [] } diff --git a/src/pages/transfer/form.svelte b/src/pages/transfer/form.svelte index cf8a9b78..48f2b9c8 100644 --- a/src/pages/transfer/form.svelte +++ b/src/pages/transfer/form.svelte @@ -234,6 +234,7 @@ onTokenSelect={handleFromChange} selectedToken={from} tokenOptions={fromOptions} + showTokensWithoutBalance /> @@ -257,6 +258,7 @@ onTokenSelect={handleToChange} selectedToken={to} tokenOptions={toOptions} + showTokensWithoutBalance /> {#if receivedAmount && receivedAmount.value > 0 && feeAmount && feeAmount.value > 0}