Skip to content

Commit

Permalink
[WALL] aum / WALL-4794 / resubmission-required-for-fully-authenticate…
Browse files Browse the repository at this point in the history
…d-clients (deriv-com#16720)

* fix: resubmission for fully authenticated clients

* fix: added check for previous attempt status

* refactor: make is_poi_required code readable
  • Loading branch information
aum-deriv authored Sep 16, 2024
1 parent cc46d20 commit 87fdb26
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
20 changes: 19 additions & 1 deletion packages/api-v2/src/hooks/usePOI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import useAuthentication from './useAuthentication';
import useResidenceList from './useResidenceList';
import useSettings from './useSettings';

const acknowledged_statuses = ['pending', 'verified'];
const failed_statuses = ['rejected', 'expired', 'suspected'];

/** A custom hook to get the proof of identity verification info of the current user. */
const usePOI = () => {
const { data: authentication_data, isSuccess: isAuthenticationSuccess, ...rest } = useAuthentication();
Expand All @@ -17,6 +20,20 @@ const usePOI = () => {
return latest_poi_attempt;
}, [authentication_data?.attempts?.latest]);

const is_poi_required = useMemo(() => {
const { services = {} } = authentication_data?.identity || {};
const statuses = [services.idv?.status, services.onfido?.status, services.manual?.status];

if (statuses.some(status => !status)) {
return null;
}

const hasAcknowledgedStatus = statuses.some(status => status && acknowledged_statuses.includes(status));
const isPreviousStatusFailed = failed_statuses.includes(previous_service?.status as string);

return !hasAcknowledgedStatus || isPreviousStatusFailed;
}, [authentication_data?.identity, previous_service?.status]);

/**
* @description Get the current step based on a few checks. Returns configuration for document validation as well.
*/
Expand Down Expand Up @@ -80,13 +97,14 @@ const usePOI = () => {
...authentication_data?.identity,
previous: previous_service,
current: current_poi,
is_poi_required,
is_pending: authentication_data?.identity?.status === 'pending',
is_rejected: authentication_data?.identity?.status === 'rejected',
is_expired: authentication_data?.identity?.status === 'expired',
is_suspected: authentication_data?.identity?.status === 'suspected',
is_verified: authentication_data?.identity?.status === 'verified',
};
}, [authentication_data, current_poi, previous_service]);
}, [authentication_data, current_poi, is_poi_required, previous_service]);

return {
data: modified_verification_data,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type TClientVerificationProps = {
onCompletion?: VoidFunction;
selectedJurisdiction?: string;
};
type TStatusCodes = Exclude<THooks.POA['status'] | THooks.POI['current']['status'], undefined>;
type TStatusCodes = Exclude<THooks.POA['status'], undefined>;

const isSubmissionRequired: Record<TStatusCodes, boolean> = {
expired: true,
Expand Down Expand Up @@ -55,21 +55,12 @@ const ClientVerification: React.FC<TClientVerificationProps> = ({
[poaData?.status, poaData?.verified_jurisdiction, selectedJurisdiction]
);

const isPoiRequired = useMemo(
() =>
(poiData?.current.status && isSubmissionRequired[poiData?.current.status]) ||
(poiData?.previous?.status &&
// @ts-expect-error broken api-types for attempts/latest key in get_account_settings
isSubmissionRequired[poiData.previous.status]),
[poiData]
);

const isTaxInformationRequired = useMemo(
() => !accountSettings.has_submitted_personal_details,
[accountSettings.has_submitted_personal_details]
);

const shouldSubmitPoi = isPoiRequired && !isPoiJustCompleted;
const shouldSubmitPoi = poiData?.is_poi_required && !isPoiJustCompleted;

const shouldSubmitPoa = isPoaRequired && !isPoaJustCompleted;

Expand Down

0 comments on commit 87fdb26

Please sign in to comment.