Skip to content
Open
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
2 changes: 1 addition & 1 deletion components/BuyCrypto/Transfi/TransfiKycConsent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const TransfiKycConsent = () => {
// TransFi found the shared verification incomplete — send the user
// back through identity verification rather than to a pending screen
// that will never resolve.
void routeToKyc(result.kycProvider);
void routeToKyc();
} else {
setModal(DEPOSIT_MODAL.OPEN_BUY_CRYPTO_KYC_PENDING);
}
Expand Down
4 changes: 2 additions & 2 deletions components/BuyCrypto/Transfi/TransfiKycPending.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ export const TransfiKycPending = () => {
// again rather than wait on a decision that will never come.
useEffect(() => {
if (status?.status === 'needs_kyc') {
void routeToKyc(status.kycProvider);
void routeToKyc();
}
}, [status?.status, status?.kycProvider, routeToKyc]);
}, [status?.status, routeToKyc]);

const handleRetry = useCallback(() => {
attemptsRef.current = 0;
Expand Down
2 changes: 1 addition & 1 deletion hooks/useBuyCryptoEntry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const useBuyCryptoEntry = () => {
break;
case 'needs_kyc':
default:
await routeToKyc(status?.kycProvider);
await routeToKyc();
break;
}
} catch (err) {
Expand Down
52 changes: 19 additions & 33 deletions hooks/useBuyCryptoKycRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,20 @@ import { DEPOSIT_MODAL } from '@/constants/modals';
import { path } from '@/constants/path';
import { TRACKING_EVENTS } from '@/constants/tracking-events';
import { track } from '@/lib/analytics';
import { getProviderRouting } from '@/lib/api';
import { KycProvider } from '@/lib/types';
import { withRefreshToken } from '@/lib/utils';
import { useCountryStore } from '@/store/useCountryStore';
import { useDepositStore } from '@/store/useDepositStore';
import { useKycStore } from '@/store/useKycStore';

/**
* Sends an unverified buy-crypto user to the identity provider their country
* routes to — Wirex countries → Sumsub, everywhere else → Didit — mirroring
* useCardSteps so a user only ever meets one provider.
* Sends an unverified buy-crypto user to Sumsub, regardless of jurisdiction.
*
* Falls back to Didit (available everywhere) when the country is unknown or the
* routing call fails. `fallbackProvider` accepts the backend's own suggestion
* from GET /transfi/status, used when the client has no country of its own.
* Buy-crypto does not follow the card flow's country routing (Wirex countries →
* Sumsub, everywhere else → Didit): TransFi is a Sumsub client, so a Sumsub
* applicant is imported by same-vendor share token, which is the path we want
* every *new* verification to take. Users who already hold a Didit verification
* never reach here — the backend reports them as `can_share` and forwards their
* existing session as documents instead of asking them to verify again.
*
* Shared by the entry point and by the mid-flow recovery paths — TransFi can
* reject a share as needs_kyc if the verification it received was incomplete.
Expand All @@ -31,33 +30,20 @@ export const useBuyCryptoKycRoute = () => {
const countryCode = useCountryStore(state => state.countryInfo?.countryCode);
const router = useRouter();

return useCallback(
async (fallbackProvider?: KycProvider) => {
setKycFlow('transfi');
return useCallback(async () => {
setKycFlow('transfi');
setKycProvider(KycProvider.SUMSUB);

let kycProvider = fallbackProvider ?? KycProvider.DIDIT;
if (countryCode) {
try {
const routing = await withRefreshToken(() => getProviderRouting(countryCode));
if (routing?.kycProvider) kycProvider = routing.kycProvider;
} catch {
// backend unavailable → keep the fallback
}
}
track(TRACKING_EVENTS.CARD_KYC_FLOW_TRIGGERED, {
action: 'route',
kycFlow: 'transfi',
kycProvider: KycProvider.SUMSUB,
countryCode,
});

setKycProvider(kycProvider);
track(TRACKING_EVENTS.CARD_KYC_FLOW_TRIGGERED, {
action: 'route',
kycFlow: 'transfi',
kycProvider,
countryCode,
});

setModal(DEPOSIT_MODAL.CLOSE);
router.push((kycProvider === KycProvider.SUMSUB ? path.SUMSUB_KYC : path.KYC) as any);
},
[countryCode, router, setKycFlow, setKycProvider, setModal],
);
setModal(DEPOSIT_MODAL.CLOSE);
router.push(path.SUMSUB_KYC as any);
}, [countryCode, router, setKycFlow, setKycProvider, setModal]);
};

export default useBuyCryptoKycRoute;
Loading