From 87fdb26189aebe30d2df2bfbc92e798576940eef Mon Sep 17 00:00:00 2001 From: Aum Bhatt <125039206+aum-deriv@users.noreply.github.com> Date: Mon, 16 Sep 2024 18:16:29 +0400 Subject: [PATCH] [WALL] aum / WALL-4794 / resubmission-required-for-fully-authenticated-clients (#16720) * fix: resubmission for fully authenticated clients * fix: added check for previous attempt status * refactor: make is_poi_required code readable --- packages/api-v2/src/hooks/usePOI.ts | 20 ++++++++++++++++++- .../ClientVerification/ClientVerification.tsx | 13 ++---------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/packages/api-v2/src/hooks/usePOI.ts b/packages/api-v2/src/hooks/usePOI.ts index f5ccfcb68304..daa6987808a9 100644 --- a/packages/api-v2/src/hooks/usePOI.ts +++ b/packages/api-v2/src/hooks/usePOI.ts @@ -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(); @@ -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. */ @@ -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, diff --git a/packages/wallets/src/features/cfd/flows/ClientVerification/ClientVerification.tsx b/packages/wallets/src/features/cfd/flows/ClientVerification/ClientVerification.tsx index b46df66c4257..34044ec0611f 100644 --- a/packages/wallets/src/features/cfd/flows/ClientVerification/ClientVerification.tsx +++ b/packages/wallets/src/features/cfd/flows/ClientVerification/ClientVerification.tsx @@ -12,7 +12,7 @@ type TClientVerificationProps = { onCompletion?: VoidFunction; selectedJurisdiction?: string; }; -type TStatusCodes = Exclude; +type TStatusCodes = Exclude; const isSubmissionRequired: Record = { expired: true, @@ -55,21 +55,12 @@ const ClientVerification: React.FC = ({ [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;