Skip to content

Box UI Components

Chain Selector

Component Props

ParameterDescriptionTypeRequired
srcChainIdNetwork from which to initiate transaction.ChainIdtrue
setSrcChainIdState function to update the source chain.(id: ChainId) => voidtrue
chainsOptionally support only a subset of Decent chains.ChainId[]true
titleLabel text for the selector.stringfalse
onSelectedUse custom chain icons.(id: ChainId) => voidfalse
anchorToRightUpdate location of modal.booleanfalse
chainIconDictOverrideUse custom chain icons.Record<number, any>false

Sample Implementation

import { ChainSelector } from '@decent.xyz/box-ui';
import { ChainId } from '@decent.xyz/box-common';
 
const YourComponent = () => {
	const [chain, setChain] = useState< ChainId>(ChainId.ETHEREUM);
  const chains = [
    ChainId.ARBITRUM,
    ChainId.OPTIMISM,
    ChainId.ETHEREUM,
    ChainId.BASE,
    ChainId.RARIBLE,
    ChainId.ZORA,
    ChainId.POLYGON,
  ];
 
  // etc.
  return (
    <ChainSelector
      srcChainId={chain}
      setSrcChainId={setChain}
      chains={chains}
    />
  );
}

Token Selector

Component Props

ParameterDescriptionTypeRequired
disabledOptionally disable the selector.booleanfalse
selectedTokenActive token selection.TokenInfotrue
setSelectedTokenState function to update active source token.(s: TokenInfo) => voidtrue
addressWallet address to query token balances.Addressfalse
chainIdSelected chain.ChainIdtrue
selectTokensOptionally restrict to specific list of tokens.Address[]false
selectChainsOptionally restrict to a specific list of chains.ChainId[]false
selectorOnlyUse custom chain icons.booleanfalse
hidePopularSectionHide common tokens on a chain.booleanfalse
searchBoxClassNameFormat the search input.stringfalse
showUsdValueOptionally disable USD quotes for token balances.booleanfalse

Sample Implementation

import { TokenSelector } from '@decent.xyz/box-ui';
import {
  TokenInfo,
  ChainId,
	ethGasToken
} from '@decent.xyz/box-common';
 
const YourComponent = () => {
  return (
    <TokenSelector
      selectedToken={selectedToken}
      setSelectedToken={setSelectedToken}
      chainId={chainId}
      address={address}
      selectorOnly
      searchBoxClassName="box-py-3 box-rounded-none"
      showUsdValue
    />
  );
};

Balance Selector

This component reads all of a user's token balances and groups them neatly by network and token. It is a very helpful component to let users select which token to use from their available balances.

Component Props

ParameterDescriptionTypeRequired
disabledOptionally disable the selector.booleanfalse
selectedTokenActive token selection.TokenInfotrue
setSelectedTokenState function to update active source token.(s: TokenInfo) => voidtrue
hideZeroBalancesDo not show tokens without a balance.booleanfalse
openToSideShow tokens by chain offset to right vs. in dropdown.booleanfalse
closeOnSelectOptionally close the modal on a selection.booleanfalse
addressConnected wallet address.Addressfalse
chainIdActive chain ID.ChainIdtrue
selectTokensOptionally restrict to specific list of tokens.Address[]false
selectChainsOptionally restrict to a specific list of chains.ChainId[]false
classNameOptional Tailwind CSS styling.stringfalse

Sample Implementation

import { 
  BalanceSelector,
  ClientRendered,
  ChainIcon
} from '@decent.xyz/box-ui'; 
 
const YourComponent = () => {
  return (
    <BalanceSelector
      className=""
      selectedToken={selectedToken}
      setSelectedToken={(tokeninfo: TokenInfo) => {
        setSrcToken(tokeninfo);
        setShowBalanceSelector(false);
      }}
      chainId={chainId}
      address={address}
      selectChains={[ChainId.ARBITRUM, ChainId.OPTIMISM, ChainId.POLYGON, ChainId.ETHEREUM, ChainId.BASE, ChainId.ZORA, ChainId.RARIBLE]}
    />
  )
}

Balance Chain Selector

This component reads all of a user's token balances and groups them neatly by chain. It accomplishes the same UX goals as the Balance Selector component with faster load times.

Component Props

ParameterDescriptionTypeRequired
disabledOptionally disable the selector.booleanfalse
selectedTokenActive token selection.TokenInfotrue
setSelectedTokenState function to update active source token.(s: TokenInfo) => voidtrue
hideZeroBalancesDo not show tokens without a balance.booleanfalse
openToSideShow tokens by chain offset to right vs. in dropdown.booleanfalse
closeOnSelectOptionally close the modal on a selection.booleanfalse
addressConnected wallet address.Addressfalse
chainIdActive chain ID.ChainIdtrue
selectTokensOptionally restrict to specific list of tokens.Address[]false
selectChainsOptionally restrict to a specific list of chains.ChainId[]false
classNameOptional Tailwind CSS styling.stringfalse

Sample Implementation

import { 
  BalanceChainSelector
} from '@decent.xyz/box-ui'; 
 
const YourComponent = () => {
  return (
    <BalanceChainSelector
      className={'box-border-0'}
      selectedToken={selectedSrcToken}
      setSelectedToken={(tokenInfo) => {
        setSelectedSrcToken(tokenInfo);
        setSrcSelectorOpen(false);
      }}
      selectChains={chainIds}
      selectTokens={[]}
      address={address}
    />
  )
}

Client Rendered

ClientRendered wraps Hooks to prevent any hydration errors. While optional, we recommend this component for a cleaner developer experience.

Sample Implementation

import { 
  BalanceSelector,
  ClientRendered,
  ChainIcon
} from '@decent.xyz/box-ui'; 
 
const YourComponent = () => {
  return (
    <ClientRendered> 
      <BalanceSelector
        className=""
        selectedToken={selectedToken}
        setSelectedToken={(tokeninfo: TokenInfo) => {
          setSrcToken(tokeninfo);
          setShowBalanceSelector(false);
        }}
        chainId={chainId}
        address={address}
        selectChains={[ChainId.ARBITRUM, ChainId.OPTIMISM, ChainId.POLYGON, ChainId.ETHEREUM, ChainId.BASE, ChainId.ZORA, ChainId.RARIBLE]}
      />
    </ClientRendered> 
  )
}