Balance Display

Formatted on-chain balance with optional fiat value. Coming soon.

Introduction

BalanceDisplay is a component for displaying balances from supported chains with real-time balance display and optional comparison currency.

Features

  • Token Definition: Define which tokens to include by specific asset IDs. Supports native tokens and tokens from pallet assets.
  • Balance Display: Show real-time token balances for connected accounts
  • Comparison Currency: Optionally include a comparison currency
  • Multi-Chain Support: Works with different Substrate-based chains
  • TypeScript: Full type safety with comprehensive interfaces
  • Customizable: Flexible styling, precision settings, and comparison currency

Installation

npx polkadot-ui@latest add balance-display

Usage

Balance Display
Formatted on-chain balance with optional comparison currency
Balance Display - Custom Thousands Separator and Decimal Separator
Formatted Polkadot USDT treasury balance with custom thousands and decimal separator
Balance Display - Compare Token
With compare token. Use any other token as compare token and pass the conversion rate.

Props

PropTypeDefaultDescription
assetIdsnumber[]-Array of asset IDs to filter tokens
chainIdstring"paseoAssetHub"Chain ID to fetch tokens from
valuenumber-Currently selected token asset ID
onChange(assetId: number) => void-Called when token selection changes
placeholderstring"Select Token"Button placeholder text
withBalancebooleanfalseShow token balances
withSearchbooleanfalseEnable search functionality in dialog
includeNativebooleantrueInclude native chain token
balancePrecisionnumber2Decimal precision for balance display
variantButtonVariant"outline"Button style variant
disabledbooleanfalseDisable the component
classNamestring-Additional CSS classes
fallbackReact.ReactNode-Fallback content when loading

Connection States

The component shows different states based on wallet connection:

  • Connected: Shows available tokens with balances
  • Disconnected: Button is disabled with loading state
  • Loading: Shows spinner while fetching token data
  • No Tokens: Shows empty state when no tokens match filters

Token Filtering

Asset IDs

Specify which tokens to include using the assetIds prop:

<SelectTokenDialog
  chainId="paseoAssetHub"
  assetIds={[1984, 8, 27]} // Only show these specific tokens
  withBalance
/>

Native Token Inclusion

Control whether to include the chain's native token:

<SelectTokenDialog
  chainId="paseoAssetHub"
  assetIds={[1984, 8]}
  includeNative={true} // Include native token, default is true
  withBalance
/>

Search Functionality

When withSearch is enabled:

  1. Users can search by token name or symbol
  2. Search is case-insensitive
  3. Results update in real-time
  4. Shows "No tokens found" state for empty results
<SelectTokenDialog
  chainId="paseoAssetHub"
  assetIds={[1984, 8, 27, 1337, 2125]}
  withSearch
  withBalance
/>

Balance Display

When withBalance is enabled:

  • Shows formatted token balances for connected accounts
  • Balances update automatically when account changes
  • Precision controlled by balancePrecision prop
  • Handles loading states gracefully
<SelectTokenDialog
  chainId="paseoAssetHub"
  assetIds={[1984, 8, 27]}
  withBalance
  balancePrecision={4} // Show 4 decimal places
/>

Multi-Chain Support

The component supports different Asset Hub chains:

  • paseoAssetHub: Paseo Asset Hub (testnet)
  • kusamaAssetHub: Kusama Asset Hub
  • polkadotAssetHub: Polkadot Asset Hub
<SelectTokenDialog
  chainId="kusamaAssetHub"
  assetIds={[1000, 2000]}
  withBalance
/>

Token Information

Each token includes:

  • Symbol: Token ticker (e.g., "USDT", "DOT")
  • Name: Full token name
  • Decimals: Token precision
  • Logo: Token icon (when available)
  • Balance: User's current balance
  • Asset ID: On-chain asset identifier

Styling Options

Button Variants

Use different button styles:

<SelectTokenDialog
  variant="secondary" // or "outline", "ghost", etc.
  className="w-[200px]"
/>

Balance Precision

Control decimal places shown:

<SelectTokenDialog
  withBalance
  balancePrecision={6} // Show up to 6 decimal places
/>

Error Handling

The component handles various error states:

  • Network disconnection: Shows appropriate loading state
  • Failed token fetching: Graceful degradation
  • Invalid asset IDs: Filters out non-existent tokens
  • Balance fetch errors: Shows tokens without balance info

Provider Requirements

The component requires a PolkadotProvider wrapper:

import { PolkadotProvider } from "@/registry/polkadot-ui/lib/polkadot-provider.dedot";

<PolkadotProvider>
  <SelectTokenDialog
    chainId="paseoAssetHub"
    assetIds={[1984, 8, 27]}
    withBalance
  />
</PolkadotProvider>;

Alternatively, use the component with provider included:

import { SelectTokenDialogWithProvider } from "@/registry/polkadot-ui/blocks/select-token/select-token-dialog.dedot";

<SelectTokenDialogWithProvider
  chainId="paseoAssetHub"
  assetIds={[1984, 8, 27]}
  withBalance
/>;