From e68cf7d41e2075215a5a0e5914be84cb830b9fcd Mon Sep 17 00:00:00 2001 From: vinu-deriv <100689171+vinu-deriv@users.noreply.github.com> Date: Fri, 17 Jan 2025 14:58:20 +0400 Subject: [PATCH] =?UTF-8?q?fix:=20reduce=20the=20authorize=20and=20getSett?= =?UTF-8?q?ings=20calls=20by=20adding=20refetchOnWi=E2=80=A6=20(#17973)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: reduce the authorize and getSettings calls by adding refetchOnWindowFocus as false * fix: avoid the get_account_status call when user is in dtrader --- packages/hooks/src/useAuthorize.ts | 3 ++- packages/hooks/src/useGetMFAccountStatus.ts | 9 ++++++--- packages/hooks/src/usePaymentAgentTransferVisible.ts | 4 +++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/hooks/src/useAuthorize.ts b/packages/hooks/src/useAuthorize.ts index e90502d3a06b..ba29ad634669 100644 --- a/packages/hooks/src/useAuthorize.ts +++ b/packages/hooks/src/useAuthorize.ts @@ -1,4 +1,5 @@ import { useMemo } from 'react'; + import { useFetch } from '@deriv/api'; import { useStore } from '@deriv/stores'; @@ -10,7 +11,7 @@ const useAuthorize = (token?: string) => { const { data, ...rest } = useFetch('authorize', { payload: { authorize: token ?? current_token }, - options: { enabled: Boolean(token ?? current_token) }, + options: { enabled: Boolean(token ?? current_token), refetchOnWindowFocus: false }, }); // Add additional information to the authorize response. diff --git a/packages/hooks/src/useGetMFAccountStatus.ts b/packages/hooks/src/useGetMFAccountStatus.ts index fef6abd73a0a..f5a20a9c9df0 100644 --- a/packages/hooks/src/useGetMFAccountStatus.ts +++ b/packages/hooks/src/useGetMFAccountStatus.ts @@ -1,6 +1,7 @@ import { useEffect } from 'react'; + +import { ACCOUNT_BADGE_STATUS, routes } from '@deriv/shared'; import { useStore } from '@deriv/stores'; -import { ACCOUNT_BADGE_STATUS } from '@deriv/shared'; const useGetMFAccountStatus = () => { const { client } = useStore(); @@ -8,9 +9,11 @@ const useGetMFAccountStatus = () => { useEffect(() => { async function fetchData() { - await updateAccountStatus(); + if (is_logged_in && (!account_status || !window.location.pathname.startsWith(routes.trade))) + await updateAccountStatus(); } - if (is_logged_in) fetchData(); + fetchData(); + // eslint-disable-next-line react-hooks/exhaustive-deps }, []); const authentication = account_status?.authentication; const poi_status = authentication?.identity?.status; diff --git a/packages/hooks/src/usePaymentAgentTransferVisible.ts b/packages/hooks/src/usePaymentAgentTransferVisible.ts index 957dc08ab6f0..c8d13d4623c9 100644 --- a/packages/hooks/src/usePaymentAgentTransferVisible.ts +++ b/packages/hooks/src/usePaymentAgentTransferVisible.ts @@ -21,7 +21,9 @@ const usePaymentAgentTransferVisible = () => { checkAuthorize(); }, [is_authorize, is_logged_in]); - const { data, ...rest } = useFetch('get_settings', { options: { enabled: Boolean(is_websocket_authorized) } }); + const { data, ...rest } = useFetch('get_settings', { + options: { enabled: Boolean(is_websocket_authorized), refetchOnWindowFocus: false }, + }); const is_payment_agent_transfer_visible = Boolean(data?.get_settings?.is_authenticated_payment_agent); return {