Skip to content

Commit c7eb068

Browse files
authored
[DTRA] / Kate / DTRA-680 / Add popup for "Turbos" launch (#12761)
* refactor: launch modal for turbos * refactor: remove unused images * feat: add functionality for opening description * refactor: test cases * chore: remove unused icon * fix: add check for popup * fix: add one more setter
1 parent 8872a9b commit c7eb068

File tree

20 files changed

+262
-134
lines changed

20 files changed

+262
-134
lines changed

packages/core/src/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@
245245
</div>
246246
<div id="wallets_modal_root" class="modal-root"></div>
247247
<div id="v2_modal_root" class="modal-root"></div>
248+
<div id="launch_modal_root" class="launch-modal-root"></div>
248249
<div id="modal_root" class="modal-root"></div>
249250
<div id="modal_root_absolute" class="modal-root modal-root--absolute"></div>
250251
<!-- modal_root has background color. So, it cannot be used for toast messages. For those cases popup_root is used -->

packages/core/src/sass/app/_common/layout/modal-root.scss

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
.modal-root {
1+
.modal-root,
2+
.launch-modal-root {
23
width: 100vw;
34
height: 100vh;
45
align-items: center;
@@ -22,3 +23,7 @@
2223
z-index: 9999;
2324
}
2425
}
26+
27+
.launch-modal-root:not(:empty) + .modal-root:not(:empty) {
28+
display: none;
29+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import React from 'react';
2+
import { render, screen } from '@testing-library/react';
3+
import userEvent from '@testing-library/user-event';
4+
import LaunchModalButton from '../launch-modal-button';
5+
6+
const default_props = {
7+
handleOpen: jest.fn(),
8+
setShowDescription: jest.fn(),
9+
};
10+
11+
const confirm_button = 'Ok';
12+
const learn_more_button = 'Learn more';
13+
14+
describe('<LaunchModalButton />', () => {
15+
it('should render LaunchModalButton', () => {
16+
render(<LaunchModalButton {...default_props} />);
17+
18+
expect(screen.getByText(confirm_button)).toBeInTheDocument();
19+
expect(screen.getByText(learn_more_button)).toBeInTheDocument();
20+
});
21+
22+
it('should call only handleOpen function if user click on OK button', () => {
23+
render(<LaunchModalButton {...default_props} />);
24+
25+
userEvent.click(screen.getByText(confirm_button));
26+
expect(default_props.handleOpen).toBeCalled();
27+
expect(default_props.setShowDescription).not.toBeCalled();
28+
});
29+
30+
it('should call both handleOpen and setShowDescription function if user click on Learn more button', () => {
31+
render(<LaunchModalButton {...default_props} />);
32+
33+
userEvent.click(screen.getByText(learn_more_button));
34+
expect(default_props.handleOpen).toBeCalled();
35+
expect(default_props.setShowDescription).toBeCalled();
36+
});
37+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React from 'react';
2+
import LaunchModalInfo from '../launch-modal-info';
3+
import { render, screen } from '@testing-library/react';
4+
5+
jest.mock('Assets/SvgComponents/trade_explanations/img-turbos.svg', () => jest.fn(() => <div>Turbos Image</div>));
6+
7+
describe('<LaunchModalInfo />', () => {
8+
it('should render component', () => {
9+
render(<LaunchModalInfo is_mobile />);
10+
11+
expect(screen.getByText('Turbos Image')).toBeInTheDocument();
12+
expect(screen.getByText('Turbos — a new trade type for you!')).toBeInTheDocument();
13+
});
14+
});
Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@ import LaunchModal from '../launch-modal';
77

88
const mocked_default_props = {
99
handleChange: jest.fn(() => LocalStore.set('launchModalShown', JSON.stringify(true))),
10+
setShowDescription: jest.fn(),
1011
open: true,
1112
};
13+
const launch_modal_id = 'launch-modal';
14+
15+
jest.mock('Assets/SvgComponents/trade_explanations/img-turbos.svg', () => jest.fn(() => <div>Turbos Image</div>));
1216

1317
describe('<LaunchModal />', () => {
1418
beforeAll(() => {
@@ -28,22 +32,23 @@ describe('<LaunchModal />', () => {
2832
it('should render launch modal ', () => {
2933
render(<LaunchModal {...mocked_default_props} />);
3034

31-
expect(screen.getByTestId('launch-modal')).toBeInTheDocument();
35+
expect(screen.getByTestId(launch_modal_id)).toBeInTheDocument();
3236
});
3337

34-
it('should set the localStorage key launchModalShown to true on clicking the continue button', async () => {
38+
it('should set the localStorage key launchModalShown to true on clicking the Ok button', async () => {
3539
render(<LaunchModal {...mocked_default_props} />);
36-
expect(screen.getByTestId('launch-modal')).toBeInTheDocument();
40+
expect(screen.getByTestId(launch_modal_id)).toBeInTheDocument();
3741

38-
const continue_btn = screen.getByRole('button', { name: 'Continue' });
42+
const continue_btn = screen.getByRole('button', { name: 'Ok' });
3943
userEvent.click(continue_btn);
4044
const value = JSON.parse(LocalStore.get('launchModalShown') ?? 'false');
4145

4246
expect(value).toBe(true);
4347
});
48+
4449
it('should not display launch modal if open is equal to false', () => {
4550
render(<LaunchModal {...mocked_default_props} open={false} />);
4651

47-
expect(screen.queryByTestId('launch-modal')).not.toBeInTheDocument();
52+
expect(screen.queryByTestId(launch_modal_id)).not.toBeInTheDocument();
4853
});
4954
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import LaunchModal from './launch-modal';
2+
3+
export default LaunchModal;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import React from 'react';
2+
import { Button, Modal } from '@deriv/components';
3+
import { Localize } from '@deriv/translations';
4+
5+
const LaunchModalButton = ({
6+
handleOpen,
7+
setShowDescription,
8+
}: {
9+
handleOpen: () => void;
10+
setShowDescription: (status: boolean) => void;
11+
}) => (
12+
<Modal.Footer has_separator>
13+
<Button
14+
className='launch-button'
15+
has_effect
16+
onClick={() => {
17+
handleOpen();
18+
setShowDescription(true);
19+
}}
20+
secondary
21+
large
22+
>
23+
<Localize i18n_default_text='Learn more' />
24+
</Button>
25+
<Button className='launch-button' has_effect onClick={handleOpen} primary large>
26+
<Localize i18n_default_text='Ok' />
27+
</Button>
28+
</Modal.Footer>
29+
);
30+
31+
export default LaunchModalButton;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import React from 'react';
2+
import ImageTurbos from 'Assets/SvgComponents/trade_explanations/img-turbos.svg';
3+
import { Text } from '@deriv/components';
4+
import { Localize } from '@deriv/translations';
5+
6+
const LaunchModalInfo = ({ is_mobile }: { is_mobile?: boolean }) => {
7+
return (
8+
<div className='modal_content' data-testid='launch-modal'>
9+
<ImageTurbos className='modal_image' viewBox={is_mobile ? '0 0 328 164' : '56 18 216 128'} />
10+
<Text as='h1' weight='bold' align='center' size={is_mobile ? 'xsm' : 'sm'}>
11+
<Localize i18n_default_text='Turbos — a new trade type for you!' />
12+
</Text>
13+
<Text as='p' align='center'>
14+
<Localize i18n_default_text='Power up your market view.' />
15+
</Text>
16+
<Text as='p' align='center'>
17+
<Localize i18n_default_text='High potential payout. Limited risk.' />
18+
</Text>
19+
<Text as='p' align='center'>
20+
<Localize i18n_default_text='Available on both demo and real accounts.' />
21+
</Text>
22+
</div>
23+
);
24+
};
25+
26+
export default LaunchModalInfo;
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// For Web Modal
2+
.dc-modal__container_launch-modal-root {
3+
text-align: center;
4+
5+
.dc-modal-body {
6+
justify-content: center;
7+
display: flex;
8+
height: 100%;
9+
10+
.modal {
11+
&_image {
12+
margin: 2.4rem 0rem;
13+
width: 21.6rem;
14+
height: 12.8rem;
15+
border-radius: 0.6rem;
16+
}
17+
}
18+
}
19+
20+
.dc-modal-footer {
21+
.launch-button {
22+
min-width: 5.1rem;
23+
}
24+
}
25+
}
26+
27+
// For Mobile
28+
.launch-page-mobile {
29+
text-align: center;
30+
display: flex;
31+
flex-direction: column;
32+
height: 100%;
33+
34+
.modal {
35+
&_content {
36+
height: 100%;
37+
display: flex;
38+
flex-direction: column;
39+
justify-content: center;
40+
align-items: center;
41+
padding: 1rem;
42+
}
43+
44+
&_image {
45+
margin-bottom: 2.4rem;
46+
border-radius: 0.6rem;
47+
}
48+
}
49+
50+
.dc-modal-footer {
51+
border-top: 0.2rem solid var(--general-section-5);
52+
padding: 1.6rem;
53+
54+
.launch-button {
55+
height: 4rem;
56+
width: 100%;
57+
}
58+
}
59+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import React from 'react';
2+
import { DesktopWrapper, MobileWrapper, Modal, UILoader } from '@deriv/components';
3+
import LaunchModalInfo from './launch-modal-info';
4+
import LaunchModalButton from './launch-modal-button';
5+
import './launch-modal.scss';
6+
7+
type LaunchModalProps = {
8+
handleChange: () => void;
9+
open: boolean;
10+
setShowDescription: (status: boolean) => void;
11+
};
12+
13+
const LaunchModal = ({ handleChange, open, setShowDescription }: LaunchModalProps) => (
14+
<React.Suspense fallback={<UILoader />}>
15+
<DesktopWrapper>
16+
<Modal
17+
is_open={open}
18+
className='launch-modal-root'
19+
height='440px'
20+
width='440px'
21+
toggleModal={handleChange}
22+
should_close_on_click_outside
23+
portalId='launch_modal_root'
24+
>
25+
<Modal.Body>
26+
<LaunchModalInfo />
27+
</Modal.Body>
28+
<LaunchModalButton handleOpen={handleChange} setShowDescription={setShowDescription} />
29+
</Modal>
30+
</DesktopWrapper>
31+
<MobileWrapper>
32+
<div className='launch-page-mobile'>
33+
<LaunchModalInfo is_mobile />
34+
<LaunchModalButton handleOpen={handleChange} setShowDescription={setShowDescription} />
35+
</div>
36+
</MobileWrapper>
37+
</React.Suspense>
38+
);
39+
40+
export default LaunchModal;
Lines changed: 1 addition & 0 deletions
Loading

packages/trader/src/Modules/SmartChartBeta/Components/LaunchModal/__tests__/launch-modal-continue-button.spec.tsx

Lines changed: 0 additions & 10 deletions
This file was deleted.

packages/trader/src/Modules/SmartChartBeta/Components/LaunchModal/__tests__/launch-modal-info.spec.tsx

Lines changed: 0 additions & 10 deletions
This file was deleted.

packages/trader/src/Modules/SmartChartBeta/Components/LaunchModal/launch-modal-continue-button.tsx

Lines changed: 0 additions & 13 deletions
This file was deleted.

packages/trader/src/Modules/SmartChartBeta/Components/LaunchModal/launch-modal-info.tsx

Lines changed: 0 additions & 16 deletions
This file was deleted.

packages/trader/src/Modules/SmartChartBeta/Components/LaunchModal/launch-modal.scss

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)