diff --git a/packages/trader/src/AppV2/Containers/Trade/__tests__/trade.spec.tsx b/packages/trader/src/AppV2/Containers/Trade/__tests__/trade.spec.tsx index 68359ce4a2d4..e046bed06fa0 100644 --- a/packages/trader/src/AppV2/Containers/Trade/__tests__/trade.spec.tsx +++ b/packages/trader/src/AppV2/Containers/Trade/__tests__/trade.spec.tsx @@ -67,6 +67,7 @@ jest.mock('AppV2/Hooks/useContractsForCompany', () => ({ default: jest.fn(() => ({ is_fetching_ref: { current: false }, trade_types: mock_contract_data.contracts_for_company.available, + resetTradeTypes: jest.fn(), })), })); @@ -114,7 +115,7 @@ describe('Trade', () => { ], }, }, - client: { is_logged_in: true }, + client: { is_logged_in: true, is_switching: false }, common: { resetServicesError: jest.fn() }, }); localStorage.clear(); @@ -141,6 +142,13 @@ describe('Trade', () => { expect(screen.getByTestId('dt_trade_loader')).toBeInTheDocument(); }); + it('should show loader if we are switching from demo to real account', () => { + default_mock_store.client.is_switching = true; + render(mockTrade()); + + expect(screen.getByTestId('dt_trade_loader')).toBeInTheDocument(); + }); + it('should render trading page with all necessary components', () => { render(mockTrade()); diff --git a/packages/trader/src/AppV2/Containers/Trade/trade.tsx b/packages/trader/src/AppV2/Containers/Trade/trade.tsx index 7cbb18b8ae11..301f373edf0d 100644 --- a/packages/trader/src/AppV2/Containers/Trade/trade.tsx +++ b/packages/trader/src/AppV2/Containers/Trade/trade.tsx @@ -1,8 +1,8 @@ -import React from 'react'; +import React, { useEffect } from 'react'; import clsx from 'clsx'; import { observer } from 'mobx-react'; import { useStore } from '@deriv/stores'; -import { Loading } from '@deriv/components'; +import { Loading, Skeleton } from '@deriv/components'; import { useLocalStorageData } from '@deriv/hooks'; import ClosedMarketMessage from 'AppV2/Components/ClosedMarketMessage'; import { useTraderStore } from 'Stores/useTraderStores'; @@ -25,7 +25,7 @@ const Trade = observer(() => { const [is_minimized_params_visible, setIsMinimizedParamsVisible] = React.useState(false); const chart_ref = React.useRef(null); const { - client: { is_logged_in }, + client: { is_logged_in, is_switching }, ui: { is_dark_mode_on }, } = useStore(); const { @@ -39,7 +39,7 @@ const Trade = observer(() => { onChange, onUnmount, } = useTraderStore(); - const { trade_types } = useContractsForCompany(); + const { trade_types, resetTradeTypes } = useContractsForCompany(); const [guide_dtrader_v2] = useLocalStorageData>('guide_dtrader_v2', { trade_types_selection: false, trade_page: false, @@ -88,9 +88,16 @@ const Trade = observer(() => { // eslint-disable-next-line react-hooks/exhaustive-deps }, []); + useEffect(() => { + if (is_switching) { + resetTradeTypes(); + } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [is_switching]); + return ( - {symbols.length && trade_types.length ? ( + {symbols.length && trade_types.length && !is_switching ? (
{ // eslint-disable-next-line react-hooks/exhaustive-deps }, [response]); - return { trade_types, contract_types_list, available_contract_types, is_fetching_ref }; + const resetTradeTypes = () => { + setTradeTypes([]); + }; + + return { trade_types, contract_types_list, available_contract_types, is_fetching_ref, resetTradeTypes }; }; export default useContractsForCompany;