Skip to content

CashAppProvider

Owns Cash App deposit selection (asset, amount), the active order, and shared fetched data for the React hooks.

When to use

Wrap the Cash App deposit UI under SwappedConnectProvider. Selection hooks (useCashAppSupportedAssets, useCashAppAsset, useCashAppAmount, …) and useCashAppOrder require this provider.

Checkout / summary screens that call useCashAppOrder also need the provider (even when they do not show the form). Order state is shared across the tree, so the form and checkout see the same order.

Example

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

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

void client.loadSession()

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

Props

PropDefaultPurpose
autoSelectAssettrueAuto-select the default or first supported asset
defaultAssetPreferred { asset, chain } when present in the list
enabledtrueSkip asset fetch when false
adjustAmountOnAssetChangefalseWhen the asset changes and the current amount is above 0 but below the new minimum, bump the amount up to that minimum

Selection is uncontrolled: pass defaultAsset only as the initial value.

HookRole
useCashAppSupportedAssetsDestination asset list
useCashAppAssetSelected asset
useCashAppAmountAmount + minimum
useCashAppSelectionFull selection snapshot
useCashAppOrderShared order + createOrder() / createOrder(request)

Errors

CodeWhen
REACT_CASH_APP_PROVIDER_REQUIREDA selection/data hook is used outside CashAppProvider

See Errors.