Skip to content

Commit 4e9ceda

Browse files
authored
[TRAH-5056] Suisin/chore: change app ID based on FF value (#17889)
* chore: change app ID based on FF value * chore: add a check to not set app id if its exists * chore: add staging app id * chore: add hooks for hub redirection * chore: check app id on AppContent instead of app * chore: update hooks to have own App ID check logic * chore: remove test const variable
1 parent ac6d910 commit 4e9ceda

File tree

5 files changed

+123
-8
lines changed

5 files changed

+123
-8
lines changed

packages/core/src/App/AppContent.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
useGrowthbookGetFeatureValue,
77
useGrowthbookIsOn,
88
useIntercom,
9+
useIsHubRedirectionEnabled,
910
useLiveChat,
1011
useOauth2,
1112
useSilentLoginAndLogout,
@@ -62,6 +63,9 @@ const AppContent: React.FC<{ passthrough: unknown }> = observer(({ passthrough }
6263
await logout();
6364
},
6465
});
66+
const { isChangingToHubAppId } = useIsHubRedirectionEnabled();
67+
68+
const is_app_id_set = localStorage.getItem('config.app_id');
6569

6670
const [isWebPasskeysFFEnabled, isGBLoaded] = useGrowthbookIsOn({
6771
featureFlag: 'web_passkeys',
@@ -108,6 +112,13 @@ const AppContent: React.FC<{ passthrough: unknown }> = observer(({ passthrough }
108112
useFreshChat(token);
109113
useIntercom(token);
110114

115+
React.useEffect(() => {
116+
if (isChangingToHubAppId && !is_app_id_set) {
117+
const app_id = process.env.NODE_ENV === 'production' ? 61554 : 53503;
118+
localStorage.setItem('config.app_id', app_id.toString());
119+
}
120+
}, [isChangingToHubAppId, is_app_id_set]);
121+
111122
React.useEffect(() => {
112123
switchLanguage(current_language);
113124
}, [current_language, switchLanguage]);

packages/core/src/App/app.jsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,33 @@
11
import React from 'react';
2-
import WS from 'Services/ws-methods';
3-
import PropTypes from 'prop-types';
2+
import { useTranslation, withTranslation } from 'react-i18next';
43
import { BrowserRouter as Router } from 'react-router-dom';
5-
import { Analytics } from '@deriv-com/analytics';
6-
import { BreakpointProvider } from '@deriv-com/quill-ui';
4+
import PropTypes from 'prop-types';
5+
76
import { APIProvider } from '@deriv/api';
87
import { CashierStore } from '@deriv/cashier';
98
import { CFDStore } from '@deriv/cfd';
109
import { Loading } from '@deriv/components';
1110
import {
12-
POIProvider,
1311
initFormErrorMessages,
12+
POIProvider,
1413
setSharedCFDText,
1514
setUrlLanguage,
1615
setWebsocket,
1716
useOnLoadTranslation,
1817
} from '@deriv/shared';
19-
import { StoreProvider, P2PSettingsProvider } from '@deriv/stores';
18+
import { P2PSettingsProvider, StoreProvider } from '@deriv/stores';
2019
import { getLanguage, initializeTranslations } from '@deriv/translations';
21-
import { withTranslation, useTranslation } from 'react-i18next';
22-
import { initializeI18n, TranslationProvider, getInitialLanguage } from '@deriv-com/translations';
20+
import { Analytics } from '@deriv-com/analytics';
21+
import { BreakpointProvider } from '@deriv-com/quill-ui';
22+
import { getInitialLanguage, initializeI18n, TranslationProvider } from '@deriv-com/translations';
23+
24+
import WS from 'Services/ws-methods';
25+
2326
import { CFD_TEXT } from '../Constants/cfd-text';
2427
import { FORM_ERROR_MESSAGES } from '../Constants/form-error-messages';
28+
2529
import AppContent from './AppContent';
30+
2631
import 'Sass/app.scss';
2732

2833
const AppWithoutTranslation = ({ root_store }) => {
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { useClientCountry, useSettings } from '@deriv/api';
2+
import { renderHook } from '@testing-library/react-hooks';
3+
4+
import useGrowthbookGetFeatureValue from '../useGrowthbookGetFeatureValue';
5+
import useIsHubRedirectionEnabled from '../useIsHubRedirectionEnabled';
6+
7+
jest.mock('@deriv/api', () => ({
8+
...jest.requireActual('@deriv/api'),
9+
useClientCountry: jest.fn(() => ({ data: 'US' })),
10+
useSettings: jest.fn(() => ({ data: { citizen: 'US' } })),
11+
}));
12+
13+
jest.mock('../useGrowthbookGetFeatureValue', () =>
14+
jest.fn(() => [
15+
{
16+
hub_enabled_country_list: [''],
17+
},
18+
])
19+
);
20+
21+
describe('useIsHubRedirectionEnabled', () => {
22+
it('should return initial state correctly', () => {
23+
const { result } = renderHook(() => useIsHubRedirectionEnabled());
24+
25+
expect(result.current.isHubRedirectionEnabled).toBe(false);
26+
expect(result.current.isChangingToHubAppId).toBe(false);
27+
});
28+
29+
it('should return false if client country is not in the hub enabled list', () => {
30+
(useClientCountry as jest.Mock).mockReturnValue({ data: 'UK' });
31+
(useSettings as jest.Mock).mockReturnValue({ data: { citizen: 'UK' } });
32+
(useGrowthbookGetFeatureValue as jest.Mock).mockReturnValue([
33+
{
34+
hub_enabled_country_list: ['US', 'AU'],
35+
},
36+
]);
37+
const { result } = renderHook(() => useIsHubRedirectionEnabled());
38+
expect(result.current.isHubRedirectionEnabled).toBe(false);
39+
});
40+
41+
it('should return true if client country is in the hub enabled list', () => {
42+
(useClientCountry as jest.Mock).mockReturnValue({ data: 'UK' });
43+
(useSettings as jest.Mock).mockReturnValue({ data: { citizen: 'UK' } });
44+
(useGrowthbookGetFeatureValue as jest.Mock).mockReturnValue([
45+
{
46+
hub_enabled_country_list: ['US', 'AU', 'UK'],
47+
},
48+
]);
49+
const { result } = renderHook(() => useIsHubRedirectionEnabled());
50+
expect(result.current.isHubRedirectionEnabled).toBe(true);
51+
});
52+
53+
it('should return isChangingToHubAppId true if client country is in the hub enabled list but not in the citizen list', () => {
54+
(useClientCountry as jest.Mock).mockReturnValue({ data: 'UK' });
55+
(useSettings as jest.Mock).mockReturnValue({ data: { citizen: 'MY' } });
56+
(useGrowthbookGetFeatureValue as jest.Mock).mockReturnValue([
57+
{
58+
hub_enabled_country_list: ['US', 'AU', 'UK'],
59+
},
60+
]);
61+
const { result } = renderHook(() => useIsHubRedirectionEnabled());
62+
expect(result.current.isChangingToHubAppId).toBe(true);
63+
});
64+
});

packages/hooks/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export { default as useInputATMFormatter } from './useInputATMFormatter';
3939
export { default as useInputDecimalFormatter } from './useInputDecimalFormatter';
4040
export { default as useIsAccountStatusPresent } from './useIsAccountStatusPresent';
4141
export { default as useIsClientHighRiskForMT5 } from './useIsClientHighRiskForMT5';
42+
export { default as useIsHubRedirectionEnabled } from './useIsHubRedirectionEnabled';
4243
export { default as useIsP2PEnabled } from './useIsP2PEnabled';
4344
export { default as useIsRealAccountNeededForCashier } from './useIsRealAccountNeededForCashier';
4445
export { default as useIsRtl } from './useIsRtl';
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { useClientCountry, useSettings } from '@deriv/api';
2+
3+
import useGrowthbookGetFeatureValue from './useGrowthbookGetFeatureValue';
4+
5+
type THubEnabledCountryList = {
6+
hub_enabled_country_list: string[];
7+
};
8+
9+
const useIsHubRedirectionEnabled = () => {
10+
const [hubEnabledCountryList] = useGrowthbookGetFeatureValue({
11+
featureFlag: 'hub_enabled_country_list',
12+
});
13+
const { data: clientCountry } = useClientCountry();
14+
const { data: accountSettings } = useSettings();
15+
const { citizen } = accountSettings;
16+
17+
const isHubRedirectionEnabled =
18+
typeof hubEnabledCountryList === 'object' &&
19+
hubEnabledCountryList !== null &&
20+
Array.isArray((hubEnabledCountryList as THubEnabledCountryList).hub_enabled_country_list) &&
21+
citizen &&
22+
(hubEnabledCountryList as THubEnabledCountryList).hub_enabled_country_list.includes(citizen);
23+
24+
const isChangingToHubAppId =
25+
typeof hubEnabledCountryList === 'object' &&
26+
hubEnabledCountryList !== null &&
27+
Array.isArray((hubEnabledCountryList as THubEnabledCountryList).hub_enabled_country_list) &&
28+
clientCountry &&
29+
(hubEnabledCountryList as THubEnabledCountryList).hub_enabled_country_list.includes(clientCountry);
30+
31+
return { isHubRedirectionEnabled, isChangingToHubAppId };
32+
};
33+
34+
export default useIsHubRedirectionEnabled;

0 commit comments

Comments
 (0)