diff --git a/packages/api-v2/src/hooks/useIsHubRedirectionEnabled.ts b/packages/api-v2/src/hooks/useIsHubRedirectionEnabled.ts index 4690ed14ed0e..f2e88ff7887b 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,24 +11,17 @@ const useIsHubRedirectionEnabled = () => { featureFlag: 'hub_enabled_country_list', }); const { data: clientCountry } = useClientCountry(); - const { data: accountSettings } = useSettings(); - const { citizen } = accountSettings; + const { data: authorize } = useAuthorize(); + const country = authorize?.country ? authorize.country : clientCountry; const isHubRedirectionEnabled = typeof hubEnabledCountryList === 'object' && hubEnabledCountryList !== null && Array.isArray((hubEnabledCountryList as THubEnabledCountryList).hub_enabled_country_list) && - citizen && - (hubEnabledCountryList as THubEnabledCountryList).hub_enabled_country_list.includes(citizen); + country && + (hubEnabledCountryList as THubEnabledCountryList).hub_enabled_country_list.includes(country); - 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 }; + return { isHubRedirectionEnabled }; }; export default useIsHubRedirectionEnabled; diff --git a/packages/core/src/App/AppContent.tsx b/packages/core/src/App/AppContent.tsx index 343ace08d689..b605734c3b97 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 { isChangingToHubAppId } = useIsHubRedirectionEnabled(); + const { isHubRedirectionEnabled } = 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 (isChangingToHubAppId && !is_app_id_set) { + if (isHubRedirectionEnabled && !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'); - }, [isChangingToHubAppId, is_app_id_set, is_change_login_app_id_set]); + }, [isHubRedirectionEnabled, 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 08fe66855cfe..1c19b78fa0b9 100644 --- a/packages/core/src/App/Components/Layout/Header/platform-dropdown.jsx +++ b/packages/core/src/App/Components/Layout/Header/platform-dropdown.jsx @@ -1,14 +1,17 @@ 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 { useDevice } from '@deriv-com/ui'; + +import { Div100vhContainer, Icon, Text, useOnClickOutside } from '@deriv/components'; 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 } }) => ( @@ -54,15 +57,14 @@ const PlatformDropdown = ({ app_routing_history, closeDrawer, platform_config, s const { isDesktop } = useDevice(); const { isHubRedirectionEnabled } = useIsHubRedirectionEnabled(); const { client } = useStore(); - const { account_settings, has_wallet } = client; - const { trading_hub } = account_settings; + const { has_wallet } = client; const TradersHubRedirect = () => { return (
{ - if (isHubRedirectionEnabled && has_wallet && !!trading_hub) { + if (isHubRedirectionEnabled && has_wallet) { 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 58c779b9cb11..c642c7ba7e47 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,11 +1,14 @@ 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 = { @@ -18,9 +21,6 @@ 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 && !!trading_hub) { + if (isHubRedirectionEnabled) { 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 7d042fede426..156609a3cacd 100644 --- a/packages/core/src/App/Containers/AccountSwitcherWallet/account-switcher-wallet.tsx +++ b/packages/core/src/App/Containers/AccountSwitcherWallet/account-switcher-wallet.tsx @@ -1,11 +1,14 @@ 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, useStore } from '@deriv/stores'; +import { observer } 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 = { @@ -18,9 +21,6 @@ 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 && !!trading_hub) { + if (isHubRedirectionEnabled) { 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 594e1ad624dc..1640f573d9df 100644 --- a/packages/core/src/App/Containers/RootComponent/root-component.jsx +++ b/packages/core/src/App/Containers/RootComponent/root-component.jsx @@ -25,8 +25,7 @@ const RootComponent = observer(props => { setIsWalletsOnboardingTourGuideVisible, notification_messages_ui, } = ui; - const { has_wallet, logout, account_settings, prevent_redirect_to_hub } = client; - const { trading_hub } = account_settings; + const { has_wallet, logout, prevent_redirect_to_hub } = client; const { oAuthLogout } = useOauth2({ handleLogout: logout }); @@ -39,11 +38,11 @@ const RootComponent = observer(props => { const STAGING_REDIRECT_URL = 'https://staging-hub.deriv.com/tradershub/options'; useEffect(() => { - if (isHubRedirectionEnabled && has_wallet && !!trading_hub && !prevent_redirect_to_hub) { + if (isHubRedirectionEnabled && has_wallet && !prevent_redirect_to_hub) { const redirectUrl = process.env.NODE_ENV === 'production' ? PRODUCTION_REDIRECT_URL : STAGING_REDIRECT_URL; window.location.assign(redirectUrl); } - }, [isHubRedirectionEnabled, has_wallet, trading_hub, prevent_redirect_to_hub]); + }, [isHubRedirectionEnabled, has_wallet, prevent_redirect_to_hub]); return has_wallet ? ( { }} notificationMessagesUi={notification_messages_ui} onWalletsOnboardingTourGuideCloseHandler={onWalletsOnboardingTourGuideCloseHandler} - isHubRedirectionEnabled={isHubRedirectionEnabled && !!trading_hub} + isHubRedirectionEnabled={isHubRedirectionEnabled} /> ) : ( diff --git a/packages/hooks/src/__tests__/useIsHubRedirectionEnabled.spec.tsx b/packages/hooks/src/__tests__/useIsHubRedirectionEnabled.spec.tsx index 8068c675e8ea..9560ea0bc388 100644 --- a/packages/hooks/src/__tests__/useIsHubRedirectionEnabled.spec.tsx +++ b/packages/hooks/src/__tests__/useIsHubRedirectionEnabled.spec.tsx @@ -1,9 +1,11 @@ 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(() => [ @@ -13,22 +15,33 @@ 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: ['AU'], + hub_enabled_country_list: ['US', 'AU', 'UK'], }, ]); + (useAuthorize as jest.Mock).mockReturnValue({ + data: { + country: 'UK', + }, + }); }); const wrapper = ({ children }: { children: JSX.Element }) => ( @@ -36,42 +49,36 @@ describe('useIsHubRedirectionEnabled', () => { ); it('should return initial state correctly', () => { - const { result } = renderHook(() => useIsHubRedirectionEnabled(), { wrapper }); - - expect(result.current.isHubRedirectionEnabled).toBe(false); - expect(result.current.isChangingToHubAppId).toBe(false); - }); - - 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'], + hub_enabled_country_list: ['AU'], }, ]); const { result } = renderHook(() => useIsHubRedirectionEnabled(), { wrapper }); + expect(result.current.isHubRedirectionEnabled).toBe(false); }); - 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'], - }, - ]); + it('should return true if authorize country is in the hub enabled list', () => { const { result } = renderHook(() => useIsHubRedirectionEnabled(), { wrapper }); expect(result.current.isHubRedirectionEnabled).toBe(true); }); - 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'; + it('should return true if client country is in the hub enabled list and authorize is undefined', () => { + (useAuthorize as jest.Mock).mockReturnValue({ + data: undefined, + }); + 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', () => { (useGrowthbookGetFeatureValue as jest.Mock).mockReturnValue([ { - hub_enabled_country_list: ['US', 'AU', 'UK'], + hub_enabled_country_list: ['AU'], }, ]); const { result } = renderHook(() => useIsHubRedirectionEnabled(), { wrapper }); - expect(result.current.isChangingToHubAppId).toBe(true); + expect(result.current.isHubRedirectionEnabled).toBe(false); }); }); diff --git a/packages/hooks/src/useIsHubRedirectionEnabled.ts b/packages/hooks/src/useIsHubRedirectionEnabled.ts index 1f540a817ece..31327f0da4c9 100644 --- a/packages/hooks/src/useIsHubRedirectionEnabled.ts +++ b/packages/hooks/src/useIsHubRedirectionEnabled.ts @@ -1,5 +1,6 @@ import { useStore } from '@deriv/stores'; +import useAuthorize from './useAuthorize'; import useGrowthbookGetFeatureValue from './useGrowthbookGetFeatureValue'; type THubEnabledCountryList = { @@ -10,24 +11,19 @@ const useIsHubRedirectionEnabled = () => { const [hubEnabledCountryList] = useGrowthbookGetFeatureValue({ featureFlag: 'hub_enabled_country_list', }); + const { data: authorize } = useAuthorize(); const { client } = useStore(); - const { account_settings, clients_country } = client; + const { clients_country } = client; + const country = authorize?.country ? authorize.country : clients_country; const isHubRedirectionEnabled = typeof hubEnabledCountryList === 'object' && hubEnabledCountryList !== null && Array.isArray((hubEnabledCountryList as THubEnabledCountryList).hub_enabled_country_list) && - account_settings.citizen && - (hubEnabledCountryList as THubEnabledCountryList).hub_enabled_country_list.includes(account_settings.citizen); + country && + (hubEnabledCountryList as THubEnabledCountryList).hub_enabled_country_list.includes(country); - 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 }; + return { isHubRedirectionEnabled }; }; export default useIsHubRedirectionEnabled; diff --git a/packages/wallets/src/components/ModalProvider/ModalProvider.tsx b/packages/wallets/src/components/ModalProvider/ModalProvider.tsx index 0d3b8c51de96..7b59e74592fb 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,8 +48,6 @@ 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')); @@ -89,7 +87,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 && !!tradingHub) { + if (isHubRedirectionEnabled) { 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 7de75e29ed20..8b3222de82aa 100644 --- a/packages/wallets/src/components/WalletsAddMoreCardBanner/__tests__/WalletsAddMoreCardBanner.spec.tsx +++ b/packages/wallets/src/components/WalletsAddMoreCardBanner/__tests__/WalletsAddMoreCardBanner.spec.tsx @@ -4,10 +4,9 @@ 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'; @@ -44,11 +43,6 @@ jest.mock('@deriv/api-v2', () => ({ financial_company: { shortcode: 'svg' }, }, })), - useSettings: jest.fn(() => ({ - data: { - trading_hub: 0, - }, - })), useWalletAccountsList: jest.fn(), })); @@ -136,11 +130,6 @@ 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 4b7d29ac34f6..238f52723cdc 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,11 +24,6 @@ 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 30cb3d92153f..fe2dc66706c4 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,11 +29,6 @@ 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 83f951a81338..feb5e2d270dd 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,11 +11,6 @@ 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 056733308493..890f793abe6b 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,12 +1,7 @@ import React from 'react'; import { createMemoryHistory } from 'history'; import { Router } from 'react-router-dom'; -import { - useActiveWalletAccount, - useCreateOtherCFDAccount, - useIsHubRedirectionEnabled, - useSettings, -} from '@deriv/api-v2'; +import { useActiveWalletAccount, useCreateOtherCFDAccount, useIsHubRedirectionEnabled } from '@deriv/api-v2'; import { render, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import { ModalProvider } from '../../../../../../components/ModalProvider'; @@ -52,11 +47,6 @@ describe('AvailableCTraderAccountsList', () => { (useIsHubRedirectionEnabled as jest.Mock).mockReturnValue({ isHubRedirectionEnabled: false, }); - (useSettings as jest.Mock).mockReturnValue({ - data: { - trading_hub: 0, - }, - }); (useIsRtl as jest.Mock).mockReturnValue(false); }); @@ -81,7 +71,7 @@ describe('AvailableCTraderAccountsList', () => { expect(screen.getByText('CFDs on financial and derived instruments with copy trading.')).toBeInTheDocument(); }); - it('calls mutate function when card is clicked', () => { + it('calls mutate function when card is clicked', async () => { const mutateMock = jest.fn(); (useCreateOtherCFDAccount as jest.Mock).mockReturnValue({ isLoading: false, @@ -95,7 +85,7 @@ describe('AvailableCTraderAccountsList', () => { ); - userEvent.click(screen.getByTestId('dt_wallets_trading_account_card')); + await userEvent.click(screen.getByTestId('dt_wallets_trading_account_card')); expect(mutateMock).toHaveBeenCalledWith({ payload: { @@ -126,7 +116,7 @@ describe('AvailableCTraderAccountsList', () => { expect(screen.getByTestId('dt_ctrader_success_modal')).toBeInTheDocument(); }); - it('shows error modal when account creation fails', () => { + it('shows error modal when account creation fails', async () => { (useCreateOtherCFDAccount as jest.Mock).mockReturnValue({ error: { error: { message: 'Test error' } }, isLoading: false, @@ -147,7 +137,7 @@ describe('AvailableCTraderAccountsList', () => { expect(screen.getAllByText('Test error')[0]).toBeInTheDocument(); expect(screen.getByText('Try again')).toBeInTheDocument(); - userEvent.click(screen.getByText('Try again')); + await 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 b67e0599612e..8842125623f0 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,11 +11,6 @@ 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 d592b92925e1..192580fb04fc 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,11 +10,6 @@ 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 29cc8142fec5..03acca8f6da4 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,7 +5,6 @@ import { useCreateOtherCFDAccount, useDxtradeAccountsList, useIsHubRedirectionEnabled, - useSettings, } from '@deriv/api-v2'; import { useDevice } from '@deriv-com/ui'; import { render, screen, waitFor } from '@testing-library/react'; @@ -136,11 +135,6 @@ describe('DxtradeEnterPasswordModal', () => { (useIsHubRedirectionEnabled as jest.Mock).mockReturnValue({ isHubRedirectionEnabled: false, }); - (useSettings as jest.Mock).mockReturnValue({ - data: { - trading_hub: 0, - }, - }); }); afterEach(() => {