React Bindings

Providers, field components and hooks that mount the Wirex card frames and handle their lifecycle for you.

Before You Start

Read the following guides before proceeding:

GuideWhy
Web SDKIsolation model and package map
SDK SetupClient id (partner id), environments, installation, CSP
Collect a Top-Up CardTokenize parameters and results
Events and Error HandlingFailure modes shared with the vanilla packages

Overview

@wirexapp/card-react is the first-party React binding: providers and field components for card
collection, and self-contained components for reveal, 3DS and the Apple Pay / Google Pay checkout. It offers the same guarantees as the vanilla
packages — card data exists only inside Wirex-served iframes — with mounting and teardown handled for you.

npm install @wirexapp/card-react

react >= 18 is a peer dependency. Every component is client-only; 'use client' is compiled in, so in
the Next.js App Router they work inside your client components with no extra directive.

For frameworks other than React, integrate the vanilla packages directly. The binding adds convenience, not
capability.


Top-Up Collection

import {
  CardTopUpProvider,
  CardNumberField,
  CardExpiryField,
  CardCvvField,
  CardholderNameField,
  useCardTopUp,
} from '@wirexapp/card-react';

const sdk = { environment: 'uat', clientId: 'a4f6c1e2-9b03-4d77-8a51-2f0c6b8e4d19' };

export function AddCardScreen() {
  return (
    <CardTopUpProvider
      sdk={sdk}
      auth={{ getBearerToken: () => session.getAccessToken() }}
      appearance={{ theme: 'dark' }}
    >
      <CardNumberField />
      <div className="row">
        <CardExpiryField />
        <CardCvvField />
      </div>
      <CardholderNameField />
      <SubmitButton />
    </CardTopUpProvider>
  );
}

function SubmitButton() {
  const { ready, state, tokenizeTopUp } = useCardTopUp();

  const submit = async () => {
    const { cardId } = await tokenizeTopUp({ billingDetails: getBillingAddress() });
    // Continue with estimate, execute and 3DS.
  };

  return (
    <button disabled={!ready || !state?.complete} onClick={submit}>
      Continue
    </button>
  );
}

Provider Props

PropTypeRequiredDescription
sdkobjectYes{ environment?, clientId? } — the same config the vanilla creators take
authobjectYes{ getBearerToken } — returns a fresh user token
appearanceobjectNoWhitelisted styling tokens — see Appearance and Localization
stringsobjectNoTranslated labels and validation messages
onChange(state) => voidNoAggregated validity and detected brand
onReady() => voidNoFires once, when every field of the profile has mounted
onMountError(error) => voidNoA field iframe failed to load or initialize
childrennodeYesField components and your own layout

useCardTopUp()

ValueTypeDescription
readybooleantrue once all four fields have mounted
stateobject | nullLatest { complete, brand, fields } snapshot. null before the first change event
tokenizeTopUpfunctionSame parameters and result as the vanilla tokenizer

Field Components

ComponentField
CardNumberFieldnumber
CardExpiryFieldexpiry
CardCvvFieldcvv
CardholderNameFieldname

Each renders one iframe and accepts className and style for its container only. The field's own
appearance comes from the provider's appearance tokens, not from your CSS. Place them anywhere inside the
provider, in any layout. CardCvvField alone takes more: its masking props.

CVV Masking

CardCvvField takes the vanilla masking options as
props — on the field, not the provider.

// Self-contained: an eye inside the field.
<CardCvvField maskToggle="button" />

// Host-driven: your own button. Mirror the frame's report into your state,
// so the in-frame eye and a maskAfter re-mask flip your button too.
const [hidden, setHidden] = useState(true);

<CardCvvField
  masked={hidden}
  maskAfter={10000}
  onMaskedChange={({ masked }) => setHidden(masked)}
/>
<button onClick={() => setHidden(h => !h)}>{hidden ? 'Show' : 'Hide'}</button>
PropDescription
maskedboolean. Live: a change is forwarded to the mounted frame in place — the typed value, the caret and the focus stay. Omitted: the field starts masked and only its own toggle changes it
maskTogglebutton, text or none (default). Read at mount
maskAfterMilliseconds; default never. Read at mount
onMaskedChange{ masked, reason } — init, user, host, timeout

None of these props remounts the field. A new maskToggle or maskAfter after mount is ignored; a new
key on the field applies them at the price of a fresh, empty CVV frame.

masked is a command, not the truth. The in-frame toggle and the timer change the frame's state
without touching your prop, so mirror onMaskedChange into the state you render masked from. Mirroring
is safe: when a change of yours crosses a frame report within one round trip, the component resolves it
toward masked — the CVV can end hidden although your last word was "show", never shown although it was
"hide".


Payout Collection

The same model with the card-number field only. Recipient name and labels are non-sensitive — collect them
with your own inputs.

import { OctDestinationProvider, CardNumberField, useOctDestination } from '@wirexapp/card-react';

<OctDestinationProvider sdk={sdk} auth={auth}>
  <CardNumberField />
  {/* your own inputs for cardholder name, label, third-party flag */}
  <SendButton />
</OctDestinationProvider>;

// Inside SendButton:
const { ready, tokenizeOctDestination } = useOctDestination();
const { externalCardId, last4 } = await tokenizeOctDestination({
  cardholderName,
  cardLabel,
  isSaved: true,
  isThirdParty: true,
});

OctDestinationProvider takes the same props as CardTopUpProvider. useOctDestination() returns
{ ready, state, tokenizeOctDestination }. Rendering CardExpiryField, CardCvvField or
CardholderNameField under it throws — those fields are not part of the oct-destination profile.


Reveal

import { CardReveal } from '@wirexapp/card-react';

<CardReveal
  sdk={sdk}
  cardId={card.id}
  actionToken={actionToken}
  fetchDetails
  fetchCvv
  fields={['cardholder', 'number', 'expiry', 'cvv']}
  cardholderName=USER.DISPLAYNAME
  auth={{
    getBearerToken: () => session.getAccessToken(),
    userEmail: user.email,
    userWallet: user.walletAddress,
  }}
  onStateChange={({ status, errorMessage }) => status === 'error' && toast.error(errorMessage)}
/>;

Props mirror the vanilla config plus sdk, className, style
and onMountError. The component remounts — and refetches — when cardId or actionToken change. A fresh
token is a fresh reveal.

Every other prop is read at mount, with one exception: masked is live — forwarded to the mounted
element in place, with no remount and no refetch. A per-field map is compared by value, in any key order.
Pass onRevealRequested from the first render: whether it exists is read at mount, because it sets the
frame's reveal gate.

// Host-driven: your own button; the report keeps it in sync with maskAfter.
const [hidden, setHidden] = useState(true);

<CardReveal
  {...props}
  masked={hidden}
  onMaskedChange={({ masked }) => setHidden(Object.values(masked).every(Boolean))}
/>

// Gated: the eye asks; reveal after your own check.
const [masked, setMasked] = useState({ number: true, expiry: true, cvv: true, pin: true });

<CardReveal
  {...props}
  masked={masked}
  maskToggle="button"
  onMaskedChange={({ masked }) => setMasked(masked)}
  onRevealRequested={async ({ field }) => {
    if (await biometrics.verify()) setMasked(m => ({ ...m, [field]: false }));
  }}
/>

A command equal to the last one you rendered is not sent again. Mirroring onMaskedChange into your state
keeps "approve, hide, approve again" working — each approval differs from the state the eye or maskAfter
left behind.


Apple Pay and Google Pay Top-Up

React bindings over @wirexapp/card-wallet-topup-web — read that
page first for the modes, the Apple Pay domain rules and the token handling. The bindings ship inside
@wirexapp/card-react.

import { useWalletAvailability, WalletTopUpForm } from '@wirexapp/card-react';

function AddFundsMethods({ topupConfig }) {
  const { availability } = useWalletAvailability(sdk, {
    config: topupConfig.providers[topupConfig.default_provider],
  });
  if (!availability?.applePay) return null;
  return <ApplePayRow />;
}

function ReviewAndPay({ quote, walletConfig, provider, checkoutToken }) {
  return (
    <WalletTopUpForm
      sdk={sdk}
      quote={quote}
      walletConfig={walletConfig}
      provider={provider}
      auth={{ checkoutToken }}
      applePayHandoff="popup"
      onExecuted={({ status }) => showResult(status)}
      onExecuteFailed={({ reason }) => showError(reason)}
      onEstimationExpired={() => reEstimate()}
    />
  );
}
ExportDescription
useWalletAvailability(sdk, { config?, enabled? }){ availability, loading, error }. One probe per page session, shared across components. availability is null while loading; enabled: false skips the probe
WalletTopUpFormProps mirror the vanilla config plus sdk, className, style and onMountError. The container needs no fixed height

Changing quote.estimationId re-arms the mounted frame in place — no remount. After
onEstimationExpired, pass the fresh quote (and a fresh auth in token mode) and the user keeps the
screen.


3DS Challenge

import { ThreeDsChallenge } from '@wirexapp/card-react';

<ThreeDsChallenge
  url={execute.three_ds_state.url}
  onComplete={status => finishTopUp(status)}
  onError={() => finishTopUp('Failed')}
  style={{ height: 480, background: '#fff', borderRadius: 8 }}
/>;

Props mirror the vanilla config plus className and style.
Give the container real dimensions — issuer pages assume 500×480 pixels or larger and a light background.
Render your own cancel control and unmount the component; treat a user-cancelled challenge as Pending,
not Failed.


Re-Render Rules

The collect group is recreated only when one of these changes:

InputEffect on the frames
sdk.environment, sdk.clientId, sdk.frameOrigin, sdk.framePathThe group is destroyed and recreated. The user's input is lost
Provider profile — swapping CardTopUpProvider for OctDestinationProviderThe group is destroyed and recreated
auth, appearance, strings, onChange, onReady, onMountError identityNo remount. The latest value is used at the next call
CardCvvField maskedForwarded in place. No remount
CardCvvField maskToggle, maskAfterIgnored after mount. A new key remounts an empty CVV frame

The comparison is on the values inside sdk, not on the object's identity, so an inline sdk={{ … }}
literal does not remount on every render. Passing a new appearance object does not re-theme a mounted
frame — appearance is read at mount.

Every component is safe under React 18 StrictMode. Fields mount, unmount and remount without leaking
iframes or message listeners.


Exports

ExportKind
CardTopUpProvider, useCardTopUpTop-up collect context and hook
OctDestinationProvider, useOctDestinationPayout collect context and hook
CardNumberField, CardExpiryField, CardCvvField, CardholderNameFieldField components. CardCvvField adds masked, maskToggle, maskAfter, onMaskedChange
CardRevealOwn-card reveal element
ThreeDsChallenge3DS step-up element
WalletTopUpForm, useWalletAvailabilityApple Pay / Google Pay checkout and availability probe
PciFrameRequestErrorError class, re-exported for instanceof checks

All shared types — PciAppearance, PciCollectChangeState, PciRevealElementConfig, PciRevealAuth,
tokenize parameter and result types — are re-exported from this package, so a React integration needs no
direct dependency on the vanilla packages.


Did this page help you?