Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion hooks/useCardSteps/__tests__/buildCardSteps.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { EndorsementStatus } from '@/components/BankTransfer/enums';
import { buildCardSteps } from '@/hooks/useCardSteps/stepHelpers';
import { CardProvider, KycStatus, RainApplicationStatus } from '@/lib/types';
import {
BridgeCustomerEndorsement,
CardProvider,
KycStatus,
RainApplicationStatus,
} from '@/lib/types';

const noop = () => {};

Expand Down Expand Up @@ -274,3 +280,34 @@ describe('buildCardSteps - a blocked activation', () => {
expect(activate?.onPress).toBeDefined();
});
});

describe('buildCardSteps - a retired Bridge endorsement', () => {
// An old bridge.xyz customer keeps their "cards" endorsement on Bridge's side.
const approvedBridgeEndorsement = {
name: 'cards',
status: EndorsementStatus.APPROVED,
} as unknown as BridgeCustomerEndorsement;

const kycStepFor = (kycStatus?: KycStatus) =>
buildCardSteps(approvedBridgeEndorsement, undefined, false, undefined, noop, noop, noop, {
cardIssuer: CardProvider.WIREX,
kycStatus,
depositRequired: false,
}).find(s => s.key === 'kyc');

it('does not complete KYC for a Wirex applicant who has not verified', () => {
// The backend reports a card customer, so its kycStatus is the answer —
// the Bridge approval is for a card that no longer exists.
const kyc = kycStepFor(KycStatus.NOT_STARTED);

expect(kyc?.completed).toBe(false);
expect(kyc?.buttonText).toBe('Continue verification');
expect(kyc?.onPress).toBeDefined();
});

it('still honours the endorsement for a Bridge-only user with no card customer', () => {
const kyc = kycStepFor(undefined);

expect(kyc?.completed).toBe(true);
});
});
16 changes: 11 additions & 5 deletions hooks/useCardSteps/stepHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ export function buildCardSteps(
isSubmittingPendingApplication?: boolean;
},
): Step[] {
// The Bridge endorsement is a fallback for Bridge-only users, who have no card
// customer and so no `kycStatus`. Once `/cards/status` reports one, the
// application is on Rain or Wirex and bridge.xyz has no say in it: an old
// Bridge "cards" approval would otherwise mark a Wirex applicant's KYC step
// done (and offer "Activate card") before they have verified with Sumsub.
const legacyEndorsement = options?.kycStatus != null ? undefined : cardsEndorsement;
const stepOptions =
options?.cardIssuer != null || options?.kycStatus != null
? {
Expand All @@ -72,9 +78,9 @@ export function buildCardSteps(
kycWarnings: options?.kycWarnings,
}
: undefined;
const description = getStepDescription(cardsEndorsement, customerRejectionReasons, stepOptions);
const buttonText = getStepButtonText(cardsEndorsement, stepOptions);
const isButtonDisabled = isStepButtonDisabled(cardsEndorsement, stepOptions);
const description = getStepDescription(legacyEndorsement, customerRejectionReasons, stepOptions);
const buttonText = getStepButtonText(legacyEndorsement, stepOptions);
const isButtonDisabled = isStepButtonDisabled(legacyEndorsement, stepOptions);

const isRainKycApproved =
options?.cardIssuer === CardProvider.RAIN &&
Expand All @@ -94,7 +100,7 @@ export function buildCardSteps(
// kycStatus is the canonical backend decision for every non-Rain issuer,
// with the Bridge endorsement kept as the legacy fallback.
options?.kycStatus === KycStatus.APPROVED ||
cardsEndorsement?.status === EndorsementStatus.APPROVED;
legacyEndorsement?.status === EndorsementStatus.APPROVED;

// Deliberately does NOT repeat the failure reason. `CardStatusBanner` already
// carries it — as a headline, with the detail and a support action — and
Expand Down Expand Up @@ -163,7 +169,7 @@ export function buildCardSteps(
: description,
completed: kycStepComplete,
status: kycStepComplete ? 'completed' : 'pending',
endorsementStatus: cardsEndorsement?.status,
endorsementStatus: legacyEndorsement?.status,
buttonText: showHoldStep ? undefined : buttonText,
onPress: showHoldStep || isButtonDisabled ? undefined : kycStepOnPress,
};
Expand Down
Loading