forked from deriv-com/p2p
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuseIsP2PBlocked.ts
35 lines (27 loc) · 1.2 KB
/
useIsP2PBlocked.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { useMemo } from 'react';
import { getBlockedType } from '@/utils';
import { useGetAccountStatus } from '@deriv-com/api-hooks';
import { api } from '..';
// TODO: add other blocked statuses when implementing high risk scenarios
/**
* A custom hook that returns the P2P blocked status and the status type.
* @returns {object} { isP2PBlocked: boolean, status: string }
*/
const useIsP2PBlocked = () => {
const { data: accountStatus } = useGetAccountStatus();
const { data: activeAccountData } = api.account.useActiveAccount();
const accountBlockStatus = useMemo(() => {
if (!accountStatus) return '';
if (accountStatus?.cashier_validation?.includes('system_maintenance')) return 'systemMaintenance';
if (accountStatus.p2p_status === 'perm_ban') return 'p2pBlocked';
return '';
}, [accountStatus]);
const blockedType = useMemo(
() => (activeAccountData ? getBlockedType(activeAccountData) : ''),
[activeAccountData]
);
const isP2PBlocked = Boolean(accountBlockStatus || blockedType);
const status = blockedType ?? accountBlockStatus;
return { isP2PBlocked, status: status || 'p2pBlocked' };
};
export default useIsP2PBlocked;