Skip to content

useExchangePayCurrency

Read and update the selected Exchange Pay receive currency.

When to use

On the currency picker. Currency lists come from useExchangePaySupportedCurrencies; this hook only owns selection.

Example

tsx
import {
  useExchangePayCurrency,
  useExchangePaySupportedCurrencies,
} from '@swapped/connect-sdk/react'

function CurrencyPicker() {
  const { currencies, isLoading } = useExchangePaySupportedCurrencies()
  const {
    selectedCurrency,
    selectCurrency,
    isCurrencySelected,
  } = useExchangePayCurrency()

  if (isLoading) return <p>Loading…</p>

  return (
    <ul>
      {currencies.map(currency => (
        <li key={`${currency.symbol}:${currency.blockchain}`}>
          <button
            type="button"
            aria-pressed={isCurrencySelected(currency)}
            onClick={() => selectCurrency(currency)}
          >
            {currency.symbol} on {currency.blockchain}
            {selectedCurrency === currency ? ' ✓' : ''}
          </button>
        </li>
      ))}
    </ul>
  )
}

Selecting a currency whose minimum is higher than the current amount bumps the amount up to that minimum.

Returns

FieldPurpose
selectedCurrencyMatching ExchangePaySupportedCurrency (or undefined)
selectedCurrencyKeyStable symbol:blockchain key
selectCurrency(currency)Set the selected currency
clearCurrency()Clear selection
isCurrencySelected(currency)Convenience check

Requires ExchangePayContextProvider.