diff --git a/packages/api-v2/src/hooks/useIsHubRedirectionEnabled.ts b/packages/api-v2/src/hooks/useIsHubRedirectionEnabled.ts index f2e88ff7887b..4690ed14ed0e 100644 --- a/packages/api-v2/src/hooks/useIsHubRedirectionEnabled.ts +++ b/packages/api-v2/src/hooks/useIsHubRedirectionEnabled.ts @@ -1,6 +1,6 @@ -import useAuthorize from './useAuthorize'; import useClientCountry from './useClientCountry'; import useGrowthbookGetFeatureValue from './useGrowthbookGetFeatureValue'; +import useSettings from './useSettings'; type THubEnabledCountryList = { hub_enabled_country_list: string[]; @@ -11,17 +11,24 @@ const useIsHubRedirectionEnabled = () => { featureFlag: 'hub_enabled_country_list', }); const { data: clientCountry } = useClientCountry(); - const { data: authorize } = useAuthorize(); - const country = authorize?.country ? authorize.country : clientCountry; + const { data: accountSettings } = useSettings(); + const { citizen } = accountSettings; const isHubRedirectionEnabled = typeof hubEnabledCountryList === 'object' && hubEnabledCountryList !== null && Array.isArray((hubEnabledCountryList as THubEnabledCountryList).hub_enabled_country_list) && - country && - (hubEnabledCountryList as THubEnabledCountryList).hub_enabled_country_list.includes(country); + citizen && + (hubEnabledCountryList as THubEnabledCountryList).hub_enabled_country_list.includes(citizen); - return { isHubRedirectionEnabled }; + const isChangingToHubAppId = + typeof hubEnabledCountryList === 'object' && + hubEnabledCountryList !== null && + Array.isArray((hubEnabledCountryList as THubEnabledCountryList).hub_enabled_country_list) && + clientCountry && + (hubEnabledCountryList as THubEnabledCountryList).hub_enabled_country_list.includes(clientCountry); + + return { isHubRedirectionEnabled, isChangingToHubAppId }; }; export default useIsHubRedirectionEnabled; diff --git a/packages/core/src/App/AppContent.tsx b/packages/core/src/App/AppContent.tsx index b605734c3b97..343ace08d689 100644 --- a/packages/core/src/App/AppContent.tsx +++ b/packages/core/src/App/AppContent.tsx @@ -63,7 +63,7 @@ const AppContent: React.FC<{ passthrough: unknown }> = observer(({ passthrough } await logout(); }, }); - const { isHubRedirectionEnabled } = useIsHubRedirectionEnabled(); + const { isChangingToHubAppId } = useIsHubRedirectionEnabled(); const is_app_id_set = localStorage.getItem('config.app_id'); const is_change_login_app_id_set = localStorage.getItem('change_login_app_id'); @@ -110,13 +110,13 @@ const AppContent: React.FC<{ passthrough: unknown }> = observer(({ passthrough } useIntercom(token); React.useEffect(() => { - if (isHubRedirectionEnabled && !is_app_id_set) { + if (isChangingToHubAppId && !is_app_id_set) { const app_id = process.env.NODE_ENV === 'production' ? 61554 : 53503; localStorage.setItem('change_login_app_id', app_id.toString()); return; } is_change_login_app_id_set && localStorage.removeItem('change_login_app_id'); - }, [isHubRedirectionEnabled, is_app_id_set, is_change_login_app_id_set]); + }, [isChangingToHubAppId, is_app_id_set, is_change_login_app_id_set]); React.useEffect(() => { switchLanguage(current_language); diff --git a/packages/core/src/App/Components/Layout/Header/platform-dropdown.jsx b/packages/core/src/App/Components/Layout/Header/platform-dropdown.jsx index 1c19b78fa0b9..08fe66855cfe 100644 --- a/packages/core/src/App/Components/Layout/Header/platform-dropdown.jsx +++ b/packages/core/src/App/Components/Layout/Header/platform-dropdown.jsx @@ -1,17 +1,14 @@ import React from 'react'; import ReactDOM from 'react-dom'; +import { Div100vhContainer, Icon, useOnClickOutside, Text } from '@deriv/components'; +import { routes, getActivePlatform, platforms } from '@deriv/shared'; +import { BinaryLink } from 'App/Components/Routes'; +import 'Sass/app/_common/components/platform-dropdown.scss'; +import { Localize } from '@deriv/translations'; import { useHistory } from 'react-router'; - -import { Div100vhContainer, Icon, Text, useOnClickOutside } from '@deriv/components'; +import { useDevice } from '@deriv-com/ui'; import { useIsHubRedirectionEnabled } from '@deriv/hooks'; -import { getActivePlatform, platforms, routes } from '@deriv/shared'; import { useStore } from '@deriv/stores'; -import { Localize } from '@deriv/translations'; -import { useDevice } from '@deriv-com/ui'; - -import { BinaryLink } from 'App/Components/Routes'; - -import 'Sass/app/_common/components/platform-dropdown.scss'; const PlatformBox = ({ platform: { icon, description } }) => ( @@ -57,14 +54,15 @@ const PlatformDropdown = ({ app_routing_history, closeDrawer, platform_config, s const { isDesktop } = useDevice(); const { isHubRedirectionEnabled } = useIsHubRedirectionEnabled(); const { client } = useStore(); - const { has_wallet } = client; + const { account_settings, has_wallet } = client; + const { trading_hub } = account_settings; const TradersHubRedirect = () => { return (
{ - if (isHubRedirectionEnabled && has_wallet) { + if (isHubRedirectionEnabled && has_wallet && !!trading_hub) { window.location.assign(platforms.tradershub_os.url); return; } diff --git a/packages/core/src/App/Containers/AccountSwitcherWallet/account-switcher-wallet-mobile.tsx b/packages/core/src/App/Containers/AccountSwitcherWallet/account-switcher-wallet-mobile.tsx index c642c7ba7e47..58c779b9cb11 100644 --- a/packages/core/src/App/Containers/AccountSwitcherWallet/account-switcher-wallet-mobile.tsx +++ b/packages/core/src/App/Containers/AccountSwitcherWallet/account-switcher-wallet-mobile.tsx @@ -1,14 +1,11 @@ import React from 'react'; import { useHistory } from 'react-router'; - import { Button, Icon, MobileDialog, Text } from '@deriv/components'; -import { useIsHubRedirectionEnabled, useIsRtl, useStoreWalletAccountsList } from '@deriv/hooks'; import { platforms, routes } from '@deriv/shared'; -import { observer } from '@deriv/stores'; import { Localize } from '@deriv/translations'; - import { AccountSwitcherWalletList } from './account-switcher-wallet-list'; - +import { useIsHubRedirectionEnabled, useIsRtl, useStoreWalletAccountsList } from '@deriv/hooks'; +import { observer, useStore } from '@deriv/stores'; import './account-switcher-wallet-mobile.scss'; type TAccountSwitcherWalletMobile = { @@ -21,6 +18,9 @@ export const AccountSwitcherWalletMobile = observer(({ is_visible, toggle, login const history = useHistory(); const isRtl = useIsRtl(); const { data: wallet_list } = useStoreWalletAccountsList(); + const { client } = useStore(); + const { account_settings } = client; + const { trading_hub } = account_settings; const dtrade_account_wallets = wallet_list?.filter(wallet => wallet.dtrade_loginid); const { isHubRedirectionEnabled } = useIsHubRedirectionEnabled(); @@ -30,7 +30,7 @@ export const AccountSwitcherWalletMobile = observer(({ is_visible, toggle, login }, [toggle]); const handleTradersHubRedirect = () => { - if (isHubRedirectionEnabled) { + if (isHubRedirectionEnabled && !!trading_hub) { window.location.assign(platforms.tradershub_os.url); return; } diff --git a/packages/core/src/App/Containers/AccountSwitcherWallet/account-switcher-wallet.tsx b/packages/core/src/App/Containers/AccountSwitcherWallet/account-switcher-wallet.tsx index 156609a3cacd..7d042fede426 100644 --- a/packages/core/src/App/Containers/AccountSwitcherWallet/account-switcher-wallet.tsx +++ b/packages/core/src/App/Containers/AccountSwitcherWallet/account-switcher-wallet.tsx @@ -1,14 +1,11 @@ import React from 'react'; import { useHistory } from 'react-router'; - import { Icon, Text, ThemedScrollbars, useOnClickOutside } from '@deriv/components'; -import { useIsHubRedirectionEnabled, useStoreWalletAccountsList } from '@deriv/hooks'; import { platforms, routes } from '@deriv/shared'; -import { observer } from '@deriv/stores'; +import { observer, useStore } from '@deriv/stores'; import { Localize } from '@deriv/translations'; - +import { useIsHubRedirectionEnabled, useStoreWalletAccountsList } from '@deriv/hooks'; import { AccountSwitcherWalletList } from './account-switcher-wallet-list'; - import './account-switcher-wallet.scss'; type TAccountSwitcherWalletProps = { @@ -21,6 +18,9 @@ export const AccountSwitcherWallet = observer(({ is_visible, toggle }: TAccountS const dtrade_account_wallets = wallet_list?.filter(wallet => wallet.dtrade_loginid); const history = useHistory(); + const { client } = useStore(); + const { account_settings } = client; + const { trading_hub } = account_settings; const wrapper_ref = React.useRef(null); const { isHubRedirectionEnabled } = useIsHubRedirectionEnabled(); @@ -43,7 +43,7 @@ export const AccountSwitcherWallet = observer(({ is_visible, toggle }: TAccountS useOnClickOutside(wrapper_ref, closeAccountsDialog, validateClickOutside); const handleTradersHubRedirect = async () => { - if (isHubRedirectionEnabled) { + if (isHubRedirectionEnabled && !!trading_hub) { window.location.assign(platforms.tradershub_os.url); return; } diff --git a/packages/core/src/App/Containers/RootComponent/root-component.jsx b/packages/core/src/App/Containers/RootComponent/root-component.jsx index 1640f573d9df..594e1ad624dc 100644 --- a/packages/core/src/App/Containers/RootComponent/root-component.jsx +++ b/packages/core/src/App/Containers/RootComponent/root-component.jsx @@ -25,7 +25,8 @@ const RootComponent = observer(props => { setIsWalletsOnboardingTourGuideVisible, notification_messages_ui, } = ui; - const { has_wallet, logout, prevent_redirect_to_hub } = client; + const { has_wallet, logout, account_settings, prevent_redirect_to_hub } = client; + const { trading_hub } = account_settings; const { oAuthLogout } = useOauth2({ handleLogout: logout }); @@ -38,11 +39,11 @@ const RootComponent = observer(props => { const STAGING_REDIRECT_URL = 'https://staging-hub.deriv.com/tradershub/options'; useEffect(() => { - if (isHubRedirectionEnabled && has_wallet && !prevent_redirect_to_hub) { + if (isHubRedirectionEnabled && has_wallet && !!trading_hub && !prevent_redirect_to_hub) { const redirectUrl = process.env.NODE_ENV === 'production' ? PRODUCTION_REDIRECT_URL : STAGING_REDIRECT_URL; window.location.assign(redirectUrl); } - }, [isHubRedirectionEnabled, has_wallet, prevent_redirect_to_hub]); + }, [isHubRedirectionEnabled, has_wallet, trading_hub, prevent_redirect_to_hub]); return has_wallet ? ( { }} notificationMessagesUi={notification_messages_ui} onWalletsOnboardingTourGuideCloseHandler={onWalletsOnboardingTourGuideCloseHandler} - isHubRedirectionEnabled={isHubRedirectionEnabled} + isHubRedirectionEnabled={isHubRedirectionEnabled && !!trading_hub} /> ) : ( diff --git a/packages/hooks/src/__tests__/useIsHubRedirectionEnabled.spec.tsx b/packages/hooks/src/__tests__/useIsHubRedirectionEnabled.spec.tsx index 9560ea0bc388..8068c675e8ea 100644 --- a/packages/hooks/src/__tests__/useIsHubRedirectionEnabled.spec.tsx +++ b/packages/hooks/src/__tests__/useIsHubRedirectionEnabled.spec.tsx @@ -1,11 +1,9 @@ import React from 'react'; - -import { mockStore, StoreProvider } from '@deriv/stores'; import { renderHook } from '@testing-library/react-hooks'; -import useAuthorize from '../useAuthorize'; import useGrowthbookGetFeatureValue from '../useGrowthbookGetFeatureValue'; import useIsHubRedirectionEnabled from '../useIsHubRedirectionEnabled'; +import { mockStore, StoreProvider } from '@deriv/stores'; jest.mock('../useGrowthbookGetFeatureValue', () => jest.fn(() => [ @@ -15,33 +13,22 @@ jest.mock('../useGrowthbookGetFeatureValue', () => ]) ); -jest.mock('../useAuthorize', () => - jest.fn(() => ({ - data: { - country: 'UK', - }, - })) -); - describe('useIsHubRedirectionEnabled', () => { const mock_store = mockStore({ client: { + account_settings: { citizen: 'US' }, clients_country: 'US', }, }); beforeEach(() => { mock_store.client.clients_country = 'US'; + mock_store.client.account_settings.citizen = 'US'; (useGrowthbookGetFeatureValue as jest.Mock).mockReturnValue([ { - hub_enabled_country_list: ['US', 'AU', 'UK'], + hub_enabled_country_list: ['AU'], }, ]); - (useAuthorize as jest.Mock).mockReturnValue({ - data: { - country: 'UK', - }, - }); }); const wrapper = ({ children }: { children: JSX.Element }) => ( @@ -49,36 +36,42 @@ describe('useIsHubRedirectionEnabled', () => { ); it('should return initial state correctly', () => { - (useGrowthbookGetFeatureValue as jest.Mock).mockReturnValue([ - { - hub_enabled_country_list: ['AU'], - }, - ]); const { result } = renderHook(() => useIsHubRedirectionEnabled(), { wrapper }); expect(result.current.isHubRedirectionEnabled).toBe(false); + expect(result.current.isChangingToHubAppId).toBe(false); }); - it('should return true if authorize country is in the hub enabled list', () => { + it('should return false if client country is not in the hub enabled list', () => { + mock_store.client.account_settings.citizen = 'UK'; + (useGrowthbookGetFeatureValue as jest.Mock).mockReturnValue([ + { + hub_enabled_country_list: ['US', 'AU'], + }, + ]); const { result } = renderHook(() => useIsHubRedirectionEnabled(), { wrapper }); - expect(result.current.isHubRedirectionEnabled).toBe(true); + expect(result.current.isHubRedirectionEnabled).toBe(false); }); - it('should return true if client country is in the hub enabled list and authorize is undefined', () => { - (useAuthorize as jest.Mock).mockReturnValue({ - data: undefined, - }); + it('should return true if client country is in the hub enabled list', () => { + mock_store.client.clients_country = 'UK'; + (useGrowthbookGetFeatureValue as jest.Mock).mockReturnValue([ + { + hub_enabled_country_list: ['US', 'AU', 'UK'], + }, + ]); const { result } = renderHook(() => useIsHubRedirectionEnabled(), { wrapper }); expect(result.current.isHubRedirectionEnabled).toBe(true); }); - it('should return false if authorize and client country is not in the hub enabled list', () => { + it('should return isChangingToHubAppId true if client country is in the hub enabled list but not in the citizen list', () => { + mock_store.client.clients_country = 'UK'; (useGrowthbookGetFeatureValue as jest.Mock).mockReturnValue([ { - hub_enabled_country_list: ['AU'], + hub_enabled_country_list: ['US', 'AU', 'UK'], }, ]); const { result } = renderHook(() => useIsHubRedirectionEnabled(), { wrapper }); - expect(result.current.isHubRedirectionEnabled).toBe(false); + expect(result.current.isChangingToHubAppId).toBe(true); }); }); diff --git a/packages/hooks/src/useIsHubRedirectionEnabled.ts b/packages/hooks/src/useIsHubRedirectionEnabled.ts index 31327f0da4c9..1f540a817ece 100644 --- a/packages/hooks/src/useIsHubRedirectionEnabled.ts +++ b/packages/hooks/src/useIsHubRedirectionEnabled.ts @@ -1,6 +1,5 @@ import { useStore } from '@deriv/stores'; -import useAuthorize from './useAuthorize'; import useGrowthbookGetFeatureValue from './useGrowthbookGetFeatureValue'; type THubEnabledCountryList = { @@ -11,19 +10,24 @@ const useIsHubRedirectionEnabled = () => { const [hubEnabledCountryList] = useGrowthbookGetFeatureValue({ featureFlag: 'hub_enabled_country_list', }); - const { data: authorize } = useAuthorize(); const { client } = useStore(); - const { clients_country } = client; - const country = authorize?.country ? authorize.country : clients_country; + const { account_settings, clients_country } = client; const isHubRedirectionEnabled = typeof hubEnabledCountryList === 'object' && hubEnabledCountryList !== null && Array.isArray((hubEnabledCountryList as THubEnabledCountryList).hub_enabled_country_list) && - country && - (hubEnabledCountryList as THubEnabledCountryList).hub_enabled_country_list.includes(country); + account_settings.citizen && + (hubEnabledCountryList as THubEnabledCountryList).hub_enabled_country_list.includes(account_settings.citizen); - return { isHubRedirectionEnabled }; + const isChangingToHubAppId = + typeof hubEnabledCountryList === 'object' && + hubEnabledCountryList !== null && + Array.isArray((hubEnabledCountryList as THubEnabledCountryList).hub_enabled_country_list) && + clients_country && + (hubEnabledCountryList as THubEnabledCountryList).hub_enabled_country_list.includes(clients_country); + + return { isHubRedirectionEnabled, isChangingToHubAppId }; }; export default useIsHubRedirectionEnabled; diff --git a/packages/wallets/src/components/ModalProvider/ModalProvider.tsx b/packages/wallets/src/components/ModalProvider/ModalProvider.tsx index 7b59e74592fb..0d3b8c51de96 100644 --- a/packages/wallets/src/components/ModalProvider/ModalProvider.tsx +++ b/packages/wallets/src/components/ModalProvider/ModalProvider.tsx @@ -2,9 +2,9 @@ import React, { createContext, useContext, useEffect, useMemo, useRef, useState import { createPortal } from 'react-dom'; import { useHistory } from 'react-router-dom'; import { useOnClickOutside } from 'usehooks-ts'; -import { useIsHubRedirectionEnabled } from '@deriv/api-v2'; import { useDevice } from '@deriv-com/ui'; import { THooks, TMarketTypes, TPlatforms } from '../../types'; +import { useIsHubRedirectionEnabled, useSettings } from '@deriv/api-v2'; type TModalState = { accountId?: string; @@ -48,6 +48,8 @@ const ModalProvider = ({ children }: React.PropsWithChildren) => { const { isDesktop } = useDevice(); const history = useHistory(); const { isHubRedirectionEnabled } = useIsHubRedirectionEnabled(); + const { data: accountSettings } = useSettings(); + const { trading_hub: tradingHub } = accountSettings; const rootRef = useRef(document.getElementById('wallets_modal_root')); const rootHeaderRef = useRef(document.getElementById('wallets_modal_show_header_root')); @@ -87,7 +89,7 @@ const ModalProvider = ({ children }: React.PropsWithChildren) => { })); // We need to add this check here because wallets account is coming from Low-Code tradershub. // This condition is to reload the page when the modal is closed. - if (isHubRedirectionEnabled) { + if (isHubRedirectionEnabled && !!tradingHub) { window.location.reload(); } }; diff --git a/packages/wallets/src/components/WalletsAddMoreCardBanner/__tests__/WalletsAddMoreCardBanner.spec.tsx b/packages/wallets/src/components/WalletsAddMoreCardBanner/__tests__/WalletsAddMoreCardBanner.spec.tsx index 8b3222de82aa..7de75e29ed20 100644 --- a/packages/wallets/src/components/WalletsAddMoreCardBanner/__tests__/WalletsAddMoreCardBanner.spec.tsx +++ b/packages/wallets/src/components/WalletsAddMoreCardBanner/__tests__/WalletsAddMoreCardBanner.spec.tsx @@ -4,9 +4,10 @@ import { useActiveWalletAccount, useCreateWallet, useIsEuRegion, - useIsHubRedirectionEnabled, useLandingCompany, useWalletAccountsList, + useIsHubRedirectionEnabled, + useSettings, } from '@deriv/api-v2'; import { Analytics } from '@deriv-com/analytics'; import { useDevice } from '@deriv-com/ui'; @@ -43,6 +44,11 @@ jest.mock('@deriv/api-v2', () => ({ financial_company: { shortcode: 'svg' }, }, })), + useSettings: jest.fn(() => ({ + data: { + trading_hub: 0, + }, + })), useWalletAccountsList: jest.fn(), })); @@ -130,6 +136,11 @@ describe('WalletsAddMoreCardBanner', () => { (useIsHubRedirectionEnabled as jest.Mock).mockReturnValue({ isHubRedirectionEnabled: false, }); + (useSettings as jest.Mock).mockReturnValue({ + data: { + trading_hub: 0, + }, + }); (useWalletAccountSwitcher as jest.Mock).mockReturnValue(mockSwitchWalletAccount); (useHistory as jest.Mock).mockReturnValue({ push: mockHistoryPush }); $root = document.createElement('div'); diff --git a/packages/wallets/src/features/cashier/modules/TransactionStatus/components/CryptoTransaction/__tests__/CryptoTransaction.spec.tsx b/packages/wallets/src/features/cashier/modules/TransactionStatus/components/CryptoTransaction/__tests__/CryptoTransaction.spec.tsx index 238f52723cdc..4b7d29ac34f6 100644 --- a/packages/wallets/src/features/cashier/modules/TransactionStatus/components/CryptoTransaction/__tests__/CryptoTransaction.spec.tsx +++ b/packages/wallets/src/features/cashier/modules/TransactionStatus/components/CryptoTransaction/__tests__/CryptoTransaction.spec.tsx @@ -24,6 +24,11 @@ jest.mock('@deriv/api-v2', () => ({ useIsHubRedirectionEnabled: jest.fn(() => ({ isHubRedirectionEnabled: false, })), + useSettings: jest.fn(() => ({ + data: { + trading_hub: 0, + }, + })), })); const mockModalHide = jest.fn(); diff --git a/packages/wallets/src/features/cashier/modules/Transactions/components/TransactionsPendingRow/__tests__/TransactionsPendingRow.spec.tsx b/packages/wallets/src/features/cashier/modules/Transactions/components/TransactionsPendingRow/__tests__/TransactionsPendingRow.spec.tsx index fe2dc66706c4..30cb3d92153f 100644 --- a/packages/wallets/src/features/cashier/modules/Transactions/components/TransactionsPendingRow/__tests__/TransactionsPendingRow.spec.tsx +++ b/packages/wallets/src/features/cashier/modules/Transactions/components/TransactionsPendingRow/__tests__/TransactionsPendingRow.spec.tsx @@ -29,6 +29,11 @@ jest.mock('@deriv/api-v2', () => ({ useIsHubRedirectionEnabled: jest.fn(() => ({ isHubRedirectionEnabled: false, })), + useSettings: jest.fn(() => ({ + data: { + trading_hub: 0, + }, + })), })); jest.mock('react-router-dom', () => ({ diff --git a/packages/wallets/src/features/cfd/flows/CTrader/AddedCTraderAccountsList/__tests__/AddedCTraderAccountsList.spec.tsx b/packages/wallets/src/features/cfd/flows/CTrader/AddedCTraderAccountsList/__tests__/AddedCTraderAccountsList.spec.tsx index feb5e2d270dd..83f951a81338 100644 --- a/packages/wallets/src/features/cfd/flows/CTrader/AddedCTraderAccountsList/__tests__/AddedCTraderAccountsList.spec.tsx +++ b/packages/wallets/src/features/cfd/flows/CTrader/AddedCTraderAccountsList/__tests__/AddedCTraderAccountsList.spec.tsx @@ -11,6 +11,11 @@ jest.mock('@deriv/api-v2', () => ({ useIsHubRedirectionEnabled: jest.fn(() => ({ isHubRedirectionEnabled: false, })), + useSettings: jest.fn(() => ({ + data: { + trading_hub: 0, + }, + })), })); jest.mock('../../../../modals', () => ({ diff --git a/packages/wallets/src/features/cfd/flows/CTrader/AvailableCTraderAccountsList/__tests__/AvailableCtraderAccountsList.spec.tsx b/packages/wallets/src/features/cfd/flows/CTrader/AvailableCTraderAccountsList/__tests__/AvailableCtraderAccountsList.spec.tsx index 890f793abe6b..056733308493 100644 --- a/packages/wallets/src/features/cfd/flows/CTrader/AvailableCTraderAccountsList/__tests__/AvailableCtraderAccountsList.spec.tsx +++ b/packages/wallets/src/features/cfd/flows/CTrader/AvailableCTraderAccountsList/__tests__/AvailableCtraderAccountsList.spec.tsx @@ -1,7 +1,12 @@ import React from 'react'; import { createMemoryHistory } from 'history'; import { Router } from 'react-router-dom'; -import { useActiveWalletAccount, useCreateOtherCFDAccount, useIsHubRedirectionEnabled } from '@deriv/api-v2'; +import { + useActiveWalletAccount, + useCreateOtherCFDAccount, + useIsHubRedirectionEnabled, + useSettings, +} from '@deriv/api-v2'; import { render, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import { ModalProvider } from '../../../../../../components/ModalProvider'; @@ -47,6 +52,11 @@ describe('AvailableCTraderAccountsList', () => { (useIsHubRedirectionEnabled as jest.Mock).mockReturnValue({ isHubRedirectionEnabled: false, }); + (useSettings as jest.Mock).mockReturnValue({ + data: { + trading_hub: 0, + }, + }); (useIsRtl as jest.Mock).mockReturnValue(false); }); @@ -71,7 +81,7 @@ describe('AvailableCTraderAccountsList', () => { expect(screen.getByText('CFDs on financial and derived instruments with copy trading.')).toBeInTheDocument(); }); - it('calls mutate function when card is clicked', async () => { + it('calls mutate function when card is clicked', () => { const mutateMock = jest.fn(); (useCreateOtherCFDAccount as jest.Mock).mockReturnValue({ isLoading: false, @@ -85,7 +95,7 @@ describe('AvailableCTraderAccountsList', () => { ); - await userEvent.click(screen.getByTestId('dt_wallets_trading_account_card')); + userEvent.click(screen.getByTestId('dt_wallets_trading_account_card')); expect(mutateMock).toHaveBeenCalledWith({ payload: { @@ -116,7 +126,7 @@ describe('AvailableCTraderAccountsList', () => { expect(screen.getByTestId('dt_ctrader_success_modal')).toBeInTheDocument(); }); - it('shows error modal when account creation fails', async () => { + it('shows error modal when account creation fails', () => { (useCreateOtherCFDAccount as jest.Mock).mockReturnValue({ error: { error: { message: 'Test error' } }, isLoading: false, @@ -137,7 +147,7 @@ describe('AvailableCTraderAccountsList', () => { expect(screen.getAllByText('Test error')[0]).toBeInTheDocument(); expect(screen.getByText('Try again')).toBeInTheDocument(); - await userEvent.click(screen.getByText('Try again')); + userEvent.click(screen.getByText('Try again')); expect(screen.queryByTestId('dt_wallet_error')).not.toBeInTheDocument(); }); diff --git a/packages/wallets/src/features/cfd/flows/OtherCFDs/Dxtrade/AddedDxtradeAccountsList/__test__/AddedDxtradeAccountsList.spec.tsx b/packages/wallets/src/features/cfd/flows/OtherCFDs/Dxtrade/AddedDxtradeAccountsList/__test__/AddedDxtradeAccountsList.spec.tsx index 8842125623f0..b67e0599612e 100644 --- a/packages/wallets/src/features/cfd/flows/OtherCFDs/Dxtrade/AddedDxtradeAccountsList/__test__/AddedDxtradeAccountsList.spec.tsx +++ b/packages/wallets/src/features/cfd/flows/OtherCFDs/Dxtrade/AddedDxtradeAccountsList/__test__/AddedDxtradeAccountsList.spec.tsx @@ -11,6 +11,11 @@ jest.mock('@deriv/api-v2', () => ({ useIsHubRedirectionEnabled: jest.fn(() => ({ isHubRedirectionEnabled: false, })), + useSettings: jest.fn(() => ({ + data: { + trading_hub: 0, + }, + })), })); jest.mock('../../../../../modals/MT5TradeModal', () => ({ diff --git a/packages/wallets/src/features/cfd/modals/CTraderSuccessModal/__tests__/CtraderSuccessModal.spec.tsx b/packages/wallets/src/features/cfd/modals/CTraderSuccessModal/__tests__/CtraderSuccessModal.spec.tsx index 192580fb04fc..d592b92925e1 100644 --- a/packages/wallets/src/features/cfd/modals/CTraderSuccessModal/__tests__/CtraderSuccessModal.spec.tsx +++ b/packages/wallets/src/features/cfd/modals/CTraderSuccessModal/__tests__/CtraderSuccessModal.spec.tsx @@ -10,6 +10,11 @@ jest.mock('@deriv/api-v2', () => ({ useIsHubRedirectionEnabled: jest.fn(() => ({ isHubRedirectionEnabled: false, })), + useSettings: jest.fn(() => ({ + data: { + trading_hub: 0, + }, + })), })); jest.mock('@deriv-com/ui', () => ({ diff --git a/packages/wallets/src/features/cfd/modals/DxtradeEnterPasswordModal/__tests__/DxtradeEnterPasswordModal.spec.tsx b/packages/wallets/src/features/cfd/modals/DxtradeEnterPasswordModal/__tests__/DxtradeEnterPasswordModal.spec.tsx index 03acca8f6da4..29cc8142fec5 100644 --- a/packages/wallets/src/features/cfd/modals/DxtradeEnterPasswordModal/__tests__/DxtradeEnterPasswordModal.spec.tsx +++ b/packages/wallets/src/features/cfd/modals/DxtradeEnterPasswordModal/__tests__/DxtradeEnterPasswordModal.spec.tsx @@ -5,6 +5,7 @@ import { useCreateOtherCFDAccount, useDxtradeAccountsList, useIsHubRedirectionEnabled, + useSettings, } from '@deriv/api-v2'; import { useDevice } from '@deriv-com/ui'; import { render, screen, waitFor } from '@testing-library/react'; @@ -135,6 +136,11 @@ describe('DxtradeEnterPasswordModal', () => { (useIsHubRedirectionEnabled as jest.Mock).mockReturnValue({ isHubRedirectionEnabled: false, }); + (useSettings as jest.Mock).mockReturnValue({ + data: { + trading_hub: 0, + }, + }); }); afterEach(() => {