Skip to main content
The TokenInput component provides a unified interface for selecting tokens and entering amounts. It includes balance display, USD value calculation, and percentage shortcuts.

Import

Overview

TokenInput is a reusable component used throughout the application for token-related inputs. It combines:
  • Asset Selection: Token picker with search and balance display
  • Amount Input: Numeric input with validation
  • Balance Display: Shows available balance for selected token
  • USD Value: Calculates and displays fiat value
  • Percentage Shortcuts: Quick-select buttons (25%, 50%, 75%, MAX)

Props

string
required
Display label for the input field (e.g., “Sell”, “Buy”, “You’re sending”)
Asset[]
required
Array of available assets to choose from
string
required
The aggregated asset ID of the currently selected token (e.g., “ob:usdc”)
(value: string) => void
required
Callback fired when the selected asset changes
string
required
The current amount value (human-readable format)
(e: React.ChangeEvent<HTMLInputElement>) => void
required
Callback fired when the amount input changes
TokenBalance | null
default:"null"
Balance information for the selected token
boolean
default:"false"
Whether to show percentage shortcut buttons (25%, 50%, 75%, MAX)
(percentage: number) => void
Callback fired when a percentage button is clicked. Receives the percentage (25, 50, 75, or 100)
boolean
default:"false"
Whether the input is disabled
boolean
default:"false"
Whether the amount input is read-only (used for output amounts in swaps)
TokenBalance[]
default:"[]"
Array of all token balances (passed to AssetSelect for balance display)
string | null
default:"null"
Override USD value to display (if not provided, calculated automatically)

Usage Examples

Basic Input

With Balance and Percentage Buttons

Read-Only (Output Display)

Features

Amount Validation

The component validates that input is a valid number:

USD Value Calculation

Automatically calculates USD value based on balance and amount:

Balance Display

Shows formatted balance with token symbol:

Percentage Shortcuts

Optional quick-select buttons:

Layout Structure

Styling

The component uses Tailwind CSS classes and adapts to light/dark themes:
  • Container: bg-muted/50 rounded-2xl p-4 border border-border
  • Input: text-2xl font-medium bg-transparent
  • USD Value: text-sm text-muted-foreground
  • Balance: text-xs text-muted-foreground

Onboarding Support

The amount input includes a data attribute for onboarding:

Asset Symbol Helper

Extracts display symbol from aggregated asset ID:

Dependencies

Best Practices

Always validate the amount on the parent component before using it in API calls. The TokenInput component only validates format, not value constraints.
When using percentage buttons, ensure the onPercentageClick handler accounts for token decimals correctly to avoid precision errors.
The readOnly prop is useful for output fields (like the destination amount in a swap) where users shouldn’t edit the value directly.