Token Select

A token picker with balances and search. Symbols are not unique — anyone can deploy a contract called "USDC" — so unverified tokens are segregated, badged, and shown by contract address rather than the name they claim.

src/components/ui/token-select.tsx

About

From the component's own source, where it was written.

A token picker with balances and search.

The security-critical part is what happens for a token that is not on the list. Symbols are not unique — anyone can deploy a contract called "USDC" — so a search that matches on symbol alone is a scam vector. Unverified tokens are therefore segregated below a divider, badged, and shown with their contract address rather than trusting the name they claim.

Balances sort the list, because the token you want is nearly always one you hold. Zero-balance tokens keep their place in the catalogue but fall below anything with a balance.

Install

npx astralyx-ui add token-select

Usage

import { TokenSelect } from '@/components/ui/token-select'

<TokenSelect tokens={tokens} value={token} onValueChange={setToken} />

Composer

Change the props and the source below follows.

Props
tsx
<TokenSelect tokens={tokens} value={token} onValueChange={setToken} size="md" />

Examples

Picker

API

Generated from the source, so it cannot fall behind the code. One table per exported component, then hooks, functions and types.

TokenSelect

Extends Omit<ComponentProps<'div'>, 'onChange'>.

PropTypeDefaultDescription
tokensTokenOption[]required{ address, symbol, name?, icon?, balance?, balanceValue?, fiat?, verified? }.
valuestring—Contract address of the selected token.
onValueChange(address: string) => void——
sizekeyof typeof fieldSize'md'—
placeholderstring'Select a token'—
disabledbooleanfalse—
localestring'en-GB'—
currencystring'USD'—
unverifiedLabelReactNode'Unverified'Badge on a token missing from the trusted list.
unverifiedNoteReactNode'Not on the trusted list. Anyone can deploy a token using an existing symbol — check the contract address.'—
searchPlaceholderstring'Search name or paste address'—
searchLabelstring'Search tokens'Accessible name for the search field.
listLabelstring'Tokens'Accessible name for the listbox.
emptyMessageReactNode'No tokens match.'—

Types

TokenOption

A token picker with balances and search.

FieldTypeDescription
addressstring—
symbolstring—
name?ReactNode—
icon?ReactNode—
balance?stringFormatted balance.
balanceValue?numberUsed only for ordering — held tokens sort first, since the one you want is usually one you have.
fiat?number—
verified?booleanfalse moves the token below a divider with a warning and shows its address instead of its claimed name.

Behaviour

TopicDetailDescription
searchsymbol, name or addressPasting a contract address finds it directly.