Skip to content

Commit

Permalink
yashim/fix: usepoi hook (binary-com#10758)
Browse files Browse the repository at this point in the history
* fix: use poi hook

* fix: forwarded data so it can be extended
  • Loading branch information
yashim-deriv committed Oct 18, 2023
1 parent 66bab21 commit 1f23f54
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
2 changes: 0 additions & 2 deletions packages/api/src/hooks/useAccountStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ const useAccountStatus = () => {
is_authenticated_with_idv_photoid: status.has('authenticated_with_idv_photoid'),
/** the client used to be fully authenticated by IDV but it was taken away due to compliance criteria. */
is_idv_revoked: status.has('idv_revoked'),
/** the client is disallowed from verifying using the IDV service */
is_idv_disallowed: status.has('idv_disallowed'),
};
}, [get_account_status_data?.status]);

Expand Down
20 changes: 10 additions & 10 deletions packages/api/src/hooks/usePOI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@ import { useMemo } from 'react';
import useResidenceList from './useResidenceList';
import useGetAccountStatus from './useGetAccountStatus';
import useSettings from './useSettings';
import useAccountStatus from './useAccountStatus';

type TVerificationService = 'onfido' | 'idv' | 'manual';

/** A custom hook to get the user's identity verification status. */
const usePOI = () => {
const { data: get_account_status_data } = useGetAccountStatus();
const { data: account_status } = useAccountStatus();
const { data: get_account_status_data, ...rest } = useGetAccountStatus();
const { data: residence_list_data } = useResidenceList();
const { data: get_settings_data } = useSettings();

const previous_service = useMemo(() => {
const latest_poi_attempt = get_account_status_data?.authentication?.attempts?.latest;
return latest_poi_attempt?.service as TVerificationService;
return latest_poi_attempt?.service;
}, [get_account_status_data?.authentication?.attempts?.latest]);

/**
Expand Down Expand Up @@ -55,7 +51,7 @@ const usePOI = () => {
const services = get_account_status_data?.authentication?.identity?.services;
const idv_submission_left = services?.idv?.submissions_left ?? 0;
const onfido_submission_left = services?.onfido?.submissions_left ?? 0;
if (is_idv_supported && idv_submission_left && !account_status?.is_idv_disallowed) {
if (is_idv_supported && idv_submission_left && !get_account_status_data?.status?.includes('idv_disallowed')) {
return {
service: 'idv',
submission_left: idv_submission_left,
Expand All @@ -72,16 +68,20 @@ const usePOI = () => {
service: 'manual',
};
}, [
account_status?.is_idv_disallowed,
get_account_status_data?.authentication?.identity?.services,
get_account_status_data?.status,
get_settings_data?.citizen,
get_settings_data?.country_code,
residence_list_data,
]);

return {
previous: previous_poi,
next: next_poi,
data: {
...get_account_status_data?.authentication?.identity,
previous: previous_poi,
next: next_poi,
},
...rest,
};
};

Expand Down

0 comments on commit 1f23f54

Please sign in to comment.