Skip to content

Commit

Permalink
fix: reduce the authorize and getSettings calls by adding refetchOnWi… (
Browse files Browse the repository at this point in the history
#17973)

* fix: reduce the authorize and getSettings calls by adding refetchOnWindowFocus as false

* fix: avoid the get_account_status call when user is in dtrader
  • Loading branch information
vinu-deriv authored Jan 17, 2025
1 parent 598e68f commit e68cf7d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
3 changes: 2 additions & 1 deletion packages/hooks/src/useAuthorize.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useMemo } from 'react';

import { useFetch } from '@deriv/api';
import { useStore } from '@deriv/stores';

Expand All @@ -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.
Expand Down
9 changes: 6 additions & 3 deletions packages/hooks/src/useGetMFAccountStatus.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
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();
const { account_status, is_logged_in, updateAccountStatus } = client || {};

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;
Expand Down
4 changes: 3 additions & 1 deletion packages/hooks/src/usePaymentAgentTransferVisible.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit e68cf7d

Please sign in to comment.