Appearance
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
| Prop | Default | Purpose |
|---|---|---|
defaultProvider | — | Initial selected exchange (uncontrolled after mount) |
autoSelectCurrency | true | Auto-select the first supported currency (or defaultCurrency) |
defaultCurrency | — | Preferred { symbol, blockchain } when present in the list |
enabled | true | Skip currency fetch when false |
resetAmountOnProviderChange | false | Clear amount / touched when the exchange changes |
adjustAmountOnCurrencyChange | false | When 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.
Related hooks
| Hook | Role |
|---|---|
| useExchangePayProviders | Available exchanges + selected provider |
| useExchangePaySupportedCurrencies | Currency list data |
| useExchangePayCurrency | Selected currency |
| useExchangePayAmount | Amount + minimum |
| useExchangePaySelection | Full selection snapshot |
| useExchangePayOrder | createOrder() from context |
Errors
| Code | When |
|---|---|
REACT_EXCHANGE_PAY_PROVIDER_REQUIRED | A selection/data hook is used outside ExchangePayContextProvider |
See Errors.