Skip to content

Commit

Permalink
Merge pull request #335 from ameerul-deriv/FEQ-2620-user-not-logging-…
Browse files Browse the repository at this point in the history
…out-after-disable-duplicate-status

Ameerul / FEQ-2620 User is not logging out from staging P2P after updating the client status to Duplicate/Disable from BO.
  • Loading branch information
farrah-deriv authored Sep 18, 2024
2 parents cf5e2f7 + 9e10f69 commit 17be272
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/constants/api-error-codes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const ERROR_CODES = {
ACCOUNT_DISABLED: 'AccountDisabled',
AD_EXCEEDS_BALANCE: 'advertiser_balance',
AD_EXCEEDS_DAILY_LIMIT: 'advertiser_daily_limit',
ADVERT_INACTIVE: 'advert_inactive',
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/api/account/useActiveAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useAccountList, useAuthData } from '@deriv-com/api-hooks';
/** A custom hook that returns the account object for the current active account. */
const useActiveAccount = () => {
const { data, ...rest } = useAccountList();
const { activeLoginid } = useAuthData();
const { activeLoginid, error } = useAuthData();
const { data: balanceData } = api.account.useBalance();
const activeAccount = useMemo(
() => data?.find(account => account.loginid === activeLoginid),
Expand All @@ -23,6 +23,7 @@ const useActiveAccount = () => {

return {
/** User's current active account. */
authError: error,
data: modifiedAccount,
...rest,
};
Expand Down
14 changes: 12 additions & 2 deletions src/routes/AppContent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useEffect, useRef, useState } from 'react';
import { useHistory, useLocation } from 'react-router-dom';
import { BlockedScenarios } from '@/components/BlockedScenarios';
import { BUY_SELL_URL, ERROR_CODES } from '@/constants';
import { api, useIsP2PBlocked, useLiveChat } from '@/hooks';
import { api, useIsP2PBlocked, useLiveChat, useOAuth } from '@/hooks';
import { GuideTooltip } from '@/pages/guide/components';
import { AdvertiserInfoStateProvider } from '@/providers/AdvertiserInfoStateProvider';
import { getCurrentRoute } from '@/utils';
Expand All @@ -17,10 +17,16 @@ const AppContent = () => {
const history = useHistory();
const location = useLocation();
const { isDesktop } = useDevice();
const { data: activeAccountData, isFetched, isLoading: isLoadingActiveAccount } = api.account.useActiveAccount();
const {
authError,
data: activeAccountData,
isFetched,
isLoading: isLoadingActiveAccount,
} = api.account.useActiveAccount();
const { init: initLiveChat } = useLiveChat();
const { isP2PBlocked, status } = useIsP2PBlocked();
const { localize } = useTranslations();
const { oAuthLogout } = useOAuth();
const routes = getRoutes(localize);

const tabRoutesConfiguration = routes.filter(
Expand Down Expand Up @@ -79,6 +85,10 @@ const AppContent = () => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [location]);

useEffect(() => {
if (authError?.code === ERROR_CODES.ACCOUNT_DISABLED) oAuthLogout();
}, [authError, oAuthLogout]);

useEffect(() => {
if (!isGtmTracking.current) {
window.dataLayer.push({ event: 'allow_tracking' });
Expand Down

0 comments on commit 17be272

Please sign in to comment.