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:
| Guide | Why |
|---|---|
| Web SDK | Isolation model and package map |
| SDK Setup | Client id (partner id), environments, installation, CSP |
| Collect a Top-Up Card | Tokenize parameters and results |
| Events and Error Handling | Failure 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-reactreact >= 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
| Prop | Type | Required | Description |
|---|---|---|---|
sdk | object | Yes | { environment?, clientId? } — the same config the vanilla creators take |
auth | object | Yes | { getBearerToken } — returns a fresh user token |
appearance | object | No | Whitelisted styling tokens — see Appearance and Localization |
strings | object | No | Translated labels and validation messages |
onChange | (state) => void | No | Aggregated validity and detected brand |
onReady | () => void | No | Fires once, when every field of the profile has mounted |
onMountError | (error) => void | No | A field iframe failed to load or initialize |
children | node | Yes | Field components and your own layout |
useCardTopUp()
useCardTopUp()| Value | Type | Description |
|---|---|---|
ready | boolean | true once all four fields have mounted |
state | object | null | Latest { complete, brand, fields } snapshot. null before the first change event |
tokenizeTopUp | function | Same parameters and result as the vanilla tokenizer |
Field Components
| Component | Field |
|---|---|
CardNumberField | number |
CardExpiryField | expiry |
CardCvvField | cvv |
CardholderNameField | name |
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>| Prop | Description |
|---|---|
masked | boolean. 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 |
maskToggle | button, text or none (default). Read at mount |
maskAfter | Milliseconds; 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.
maskedis a command, not the truth. The in-frame toggle and the timer change the frame's state
without touching your prop, so mirroronMaskedChangeinto the state you rendermaskedfrom. 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()}
/>
);
}| Export | Description |
|---|---|
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 |
WalletTopUpForm | Props 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:
| Input | Effect on the frames |
|---|---|
sdk.environment, sdk.clientId, sdk.frameOrigin, sdk.framePath | The group is destroyed and recreated. The user's input is lost |
Provider profile — swapping CardTopUpProvider for OctDestinationProvider | The group is destroyed and recreated |
auth, appearance, strings, onChange, onReady, onMountError identity | No remount. The latest value is used at the next call |
CardCvvField masked | Forwarded in place. No remount |
CardCvvField maskToggle, maskAfter | Ignored 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
| Export | Kind |
|---|---|
CardTopUpProvider, useCardTopUp | Top-up collect context and hook |
OctDestinationProvider, useOctDestination | Payout collect context and hook |
CardNumberField, CardExpiryField, CardCvvField, CardholderNameField | Field components. CardCvvField adds masked, maskToggle, maskAfter, onMaskedChange |
CardReveal | Own-card reveal element |
ThreeDsChallenge | 3DS step-up element |
WalletTopUpForm, useWalletAvailability | Apple Pay / Google Pay checkout and availability probe |
PciFrameRequestError | Error 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.
Updated about 12 hours ago

