Skip to content

ExchangePayContextProvider

Owns Exchange Pay deposit selection state (provider, currency, amount) and shared fetched data for the React hooks.

Internally composes focused providers (providers → currencies → currency → amount → selection); consumers only mount this facade.

When to use

Wrap the Exchange Pay deposit UI under SwappedConnectProvider. Selection hooks (useExchangePayProviders, useExchangePayCurrency, useExchangePayAmount, …) and createOrder() require this provider.

Checkout / summary screens that call useExchangePayOrder also need the provider (even when they do not show the form), because createOrder reads selection context.

Example

tsx
import { createSwappedConnectClient } from '@swapped/connect-sdk'
import {
  ExchangePayContextProvider,
  SwappedConnectProvider,
} from '@swapped/connect-sdk/react'

const client = createSwappedConnectClient({
  sessionId: 'your-session-id',
})

void client.loadSession()

function App() {
  return (
    <SwappedConnectProvider client={client}>
      <ExchangePayContextProvider>
        <DepositScreen />
      </ExchangePayContextProvider>
    </SwappedConnectProvider>
  )
}

Props

PropDefaultPurpose
defaultProviderInitial selected exchange (uncontrolled after mount)
autoSelectCurrencytrueAuto-select the first supported currency (or defaultCurrency)
defaultCurrencyPreferred { symbol, blockchain } when present in the list
enabledtrueSkip currency fetch when false
resetAmountOnProviderChangefalseClear amount / touched when the exchange changes
adjustAmountOnCurrencyChangefalseWhen the currency changes and the current amount is above 0 but below the new minimum, bump the amount up to that minimum

Changing the selected exchange always clears the currency selection (then auto-selects again when enabled). Amount survives unless resetAmountOnProviderChange is true. Selection is uncontrolled: pass defaultProvider only as the initial value.

HookRole
useExchangePayProvidersAvailable exchanges + selected provider
useExchangePaySupportedCurrenciesCurrency list data
useExchangePayCurrencySelected currency
useExchangePayAmountAmount + minimum
useExchangePaySelectionFull selection snapshot
useExchangePayOrdercreateOrder() from context

Errors

CodeWhen
REACT_EXCHANGE_PAY_PROVIDER_REQUIREDA selection/data hook is used outside ExchangePayContextProvider

See Errors.