Skip to content

Commit a393531

Browse files
committed
fix: Add_and_enter_password_modals
1 parent fe426fa commit a393531

5 files changed

+253
-124
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import React from 'react';
2+
import { Text } from '@deriv/components';
3+
import { getCFDPlatformNames, getCFDPlatformLabel } from '@deriv/shared';
4+
import { observer, useStore } from '@deriv/stores';
5+
import { Localize } from '@deriv/translations';
6+
import { CATEGORY, CFD_PLATFORMS } from '../Helpers/cfd-config';
7+
8+
type TCFDEnterPasswordModalTitleProps = { platform: typeof CFD_PLATFORMS[keyof typeof CFD_PLATFORMS] };
9+
10+
const CFDEnterPasswordModalTitle = observer(({ platform }: TCFDEnterPasswordModalTitleProps) => {
11+
const {
12+
modules: { cfd },
13+
} = useStore();
14+
const { account_title, account_type } = cfd;
15+
16+
const getAccountCardTitle = () => {
17+
switch (platform) {
18+
case CFD_PLATFORMS.CTRADER:
19+
case CFD_PLATFORMS.DXTRADE:
20+
return account_type.category === CATEGORY.REAL ? 'Real' : '';
21+
default:
22+
return account_title;
23+
}
24+
};
25+
26+
return (
27+
<Text size='xs' className='dc-modal__container_cfd-password-modal__account-title'>
28+
{platform === CFD_PLATFORMS.MT5 ? (
29+
<Localize
30+
i18n_default_text='Add an {{platform}} account to add an {{platform}} {{account}} account.'
31+
values={{
32+
platform: getCFDPlatformNames(platform),
33+
account: getAccountCardTitle(),
34+
}}
35+
/>
36+
) : (
37+
<Localize
38+
i18n_default_text='Enter your {{platform}} password to add a {{platform}} {{account}} account.'
39+
values={{
40+
platform: getCFDPlatformLabel(platform),
41+
account: getAccountCardTitle(),
42+
}}
43+
/>
44+
)}
45+
</Text>
46+
);
47+
});
48+
49+
export default CFDEnterPasswordModalTitle;

packages/cfd/src/Containers/cfd-password-modal-title.tsx

-45
This file was deleted.

packages/cfd/src/Containers/cfd-password-modal.tsx

+64-78
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {
1919
getCFDPlatformLabel,
2020
getCFDPlatformNames,
2121
getErrorMessages,
22-
getLegalEntityName,
2322
routes,
2423
validLength,
2524
validPassword,
@@ -31,13 +30,22 @@ import {
3130
import { observer, useStore } from '@deriv/stores';
3231
import { Localize, localize } from '@deriv/translations';
3332
import SuccessDialog from '../Components/success-dialog.jsx';
34-
import CFDPasswordModalTitle from './cfd-password-modal-title';
33+
import CFDEnterPasswordModalTitle from './cfd-enter-password-modal-title';
3534
import MigrationSuccessModal from '../Components/migration-success-modal';
3635
import { useCfdStore } from '../Stores/Modules/CFD/Helpers/useCfdStores';
37-
import { CFD_PLATFORMS, CATEGORY, PRODUCT } from '../Helpers/cfd-config';
36+
import { CFD_PLATFORMS, CATEGORY } from '../Helpers/cfd-config';
3837
import { getDxCompanies, getMtCompanies, TDxCompanies, TMtCompanies } from '../Stores/Modules/CFD/Helpers/cfd-config';
3938
import '../sass/cfd.scss';
40-
import CfdPasswordModalTnc from './cfd-password-modal-tnc';
39+
40+
const MT5CreatePassword = makeLazyLoader(
41+
() => moduleLoader(() => import('./mt5-create-password')),
42+
() => <div />
43+
)();
44+
45+
const CfdPasswordModalTnc = makeLazyLoader(
46+
() => moduleLoader(() => import('./cfd-password-modal-tnc')),
47+
() => <div />
48+
)();
4149

4250
const CFDPasswordChange = makeLazyLoader(
4351
() => moduleLoader(() => import('./cfd-password-change')),
@@ -79,14 +87,12 @@ type TCFDPasswordFormReusedProps = {
7987
type TCFDCreatePasswordProps = TCFDPasswordFormReusedProps & {
8088
password: string;
8189
onSubmit: TOnSubmitPassword;
82-
is_real_financial_stp: boolean;
8390
need_tnc: boolean;
8491
};
8592

8693
type TCFDCreatePasswordFormProps = TCFDPasswordFormReusedProps & {
8794
has_mt5_account: boolean;
8895
submitPassword: TOnSubmitPassword;
89-
is_real_financial_stp: boolean;
9096
need_tnc: boolean;
9197
};
9298

@@ -100,9 +106,7 @@ type TCFDPasswordFormProps = TCFDPasswordFormReusedProps & {
100106
error_type?: string;
101107
form_error?: string;
102108
has_mt5_account: boolean;
103-
is_bvi: boolean;
104109
is_dxtrade_allowed: boolean;
105-
is_real_financial_stp: boolean;
106110
onCancel: () => void;
107111
onForgotPassword: () => void;
108112
should_set_trading_password: boolean;
@@ -121,23 +125,46 @@ const PasswordModalHeader = ({
121125
platform,
122126
}: TPasswordModalHeaderProps) => {
123127
const { isDesktop } = useDevice();
128+
const is_mt5 = platform === CFD_PLATFORMS.MT5;
124129

125130
const element = !isDesktop ? 'p' : 'span';
126-
const alignment = 'center';
127-
const font_size = 's';
131+
128132
const style = !isDesktop
129133
? {
130134
padding: '2rem',
131135
}
132136
: {};
133137

138+
if (is_mt5 && !is_password_reset_error) {
139+
const platform_name = getCFDPlatformNames(platform);
140+
return (
141+
<Text styles={style} as={element} line_height='m' weight='bold' size='s' align='center'>
142+
{should_set_trading_password ? (
143+
<Localize
144+
i18n_default_text='Create an {{platform_name}} account'
145+
values={{
146+
platform_name,
147+
}}
148+
/>
149+
) : (
150+
<Localize
151+
i18n_default_text='Add an {{platform_name}} account'
152+
values={{
153+
platform_name,
154+
}}
155+
/>
156+
)}
157+
</Text>
158+
);
159+
}
160+
134161
return (
135-
<Text styles={style} as={element} line_height='m' weight='bold' size={font_size} align={alignment}>
162+
<Text styles={style} as={element} line_height='m' weight='bold' size='s' align='center'>
136163
{!should_set_trading_password && !is_password_reset_error && (
137164
<Localize
138-
i18n_default_text='Add a {{platform}} account'
165+
i18n_default_text='Enter your {{platform}} password'
139166
values={{
140-
platform: getCFDPlatformNames(platform),
167+
platform: getCFDPlatformLabel(platform),
141168
}}
142169
/>
143170
)}
@@ -170,21 +197,7 @@ const handlePasswordInputChange = (
170197
});
171198
};
172199

173-
// first MT5 password
174-
const CreatePassword = ({
175-
password,
176-
platform,
177-
validatePassword,
178-
onSubmit,
179-
error_message,
180-
is_real_financial_stp,
181-
need_tnc,
182-
}: TCFDCreatePasswordProps) => {
183-
const { product, account_type } = useCfdStore();
184-
const [checked, setChecked] = React.useState(
185-
!(product === PRODUCT.ZEROSPREAD && account_type.category === CATEGORY.REAL)
186-
);
187-
200+
const CreatePassword = ({ password, platform, validatePassword, onSubmit, error_message }: TCFDCreatePasswordProps) => {
188201
return (
189202
<Formik
190203
initialValues={{
@@ -210,11 +223,7 @@ const CreatePassword = ({
210223
className='cfd-password-modal__content dc-modal__container_cfd-password-modal__body cfd-password-modal__create-password-content'
211224
data-testid='dt_create_password'
212225
>
213-
<Icon
214-
icon={platform === CFD_PLATFORMS.MT5 ? 'IcMt5OnePassword' : 'IcDxtradeOnePassword'}
215-
width='122'
216-
height='108'
217-
/>
226+
<Icon icon='IcDxtradeOnePassword' width='122' height='108' />
218227
<Text
219228
size='s'
220229
align='center'
@@ -263,20 +272,8 @@ const CreatePassword = ({
263272
)}
264273
</PasswordMeter>
265274
</div>
266-
{is_real_financial_stp && (
267-
<div className='dc-modal__container_cfd-password-modal__description'>
268-
<Localize i18n_default_text='Your MT5 Financial STP account will be opened through Deriv (FX) Ltd. All trading in this account is subject to the regulations and guidelines of the Labuan Financial Service Authority (LFSA). None of your other accounts, including your Deriv account, is subject to the regulations and guidelines of the Labuan Financial Service Authority (LFSA).' />
269-
</div>
270-
)}
271-
{need_tnc && (
272-
<CfdPasswordModalTnc
273-
platform={platform}
274-
checked={checked}
275-
onCheck={() => setChecked(prev => !prev)}
276-
/>
277-
)}
278275
<FormSubmitButton
279-
is_disabled={!values.password || !checked || Object.keys(errors).length > 0}
276+
is_disabled={!values.password || Object.keys(errors).length > 0}
280277
is_loading={isSubmitting}
281278
label={localize('Create {{platform}} password', {
282279
platform: getCFDPlatformLabel(platform),
@@ -296,7 +293,6 @@ const CFDCreatePasswordForm = ({
296293
error_message,
297294
validatePassword,
298295
submitPassword,
299-
is_real_financial_stp,
300296
need_tnc,
301297
}: TCFDCreatePasswordFormProps) => {
302298
const multi_step_ref = React.useRef<TMultiStepRefProps>();
@@ -313,17 +309,26 @@ const CFDCreatePasswordForm = ({
313309

314310
const steps = [
315311
{
316-
component: (
317-
<CreatePassword
318-
password={password}
319-
platform={platform}
320-
error_message={error_message}
321-
validatePassword={validatePassword}
322-
onSubmit={onSubmit}
323-
is_real_financial_stp={is_real_financial_stp}
324-
need_tnc={need_tnc}
325-
/>
326-
),
312+
component:
313+
platform === CFD_PLATFORMS.MT5 ? (
314+
<MT5CreatePassword
315+
password={password}
316+
platform={platform}
317+
error_message={error_message}
318+
validatePassword={validatePassword}
319+
onSubmit={onSubmit}
320+
need_tnc={need_tnc}
321+
/>
322+
) : (
323+
<CreatePassword
324+
password={password}
325+
platform={platform}
326+
error_message={error_message}
327+
validatePassword={validatePassword}
328+
onSubmit={onSubmit}
329+
need_tnc={need_tnc}
330+
/>
331+
),
327332
},
328333
{
329334
component: (
@@ -349,7 +354,6 @@ const CFDPasswordForm = observer(
349354
error_type,
350355
form_error,
351356
has_mt5_account,
352-
is_real_financial_stp,
353357
onCancel,
354358
onForgotPassword,
355359
platform,
@@ -418,7 +422,6 @@ const CFDPasswordForm = observer(
418422
validatePassword={validatePassword}
419423
submitPassword={submitPassword}
420424
has_mt5_account={has_mt5_account}
421-
is_real_financial_stp={is_real_financial_stp}
422425
need_tnc={need_tnc}
423426
/>
424427
);
@@ -447,7 +450,7 @@ const CFDPasswordForm = observer(
447450
}) => (
448451
<form onSubmit={handleSubmit}>
449452
<div className='cfd-password-modal__content dc-modal__container_cfd-password-modal__body'>
450-
<CFDPasswordModalTitle platform={platform} />
453+
<CFDEnterPasswordModalTitle platform={platform} />
451454
<div className='input-element'>
452455
<PasswordInput
453456
autoComplete='new-password'
@@ -467,17 +470,6 @@ const CFDPasswordForm = observer(
467470
data_testId={`dt_${platform}_password`}
468471
/>
469472
</div>
470-
471-
{is_real_financial_stp && (
472-
<div className='dc-modal__container_cfd-password-modal__description'>
473-
<Localize
474-
i18n_default_text='Your MT5 Financial STP account will be opened through {{legal_entity_name}}. All trading in this account is subject to the regulations and guidelines of the Labuan Financial Service Authority (LFSA). None of your other accounts, including your Deriv account, is subject to the regulations and guidelines of the Labuan Financial Service Authority (LFSA).'
475-
values={{
476-
legal_entity_name: getLegalEntityName('fx'),
477-
}}
478-
/>
479-
</div>
480-
)}
481473
{error_type === 'PasswordError' && (
482474
<Text size='xs' as='p' className='dc-modal__container_mt5-password-modal__hint'>
483475
<Localize
@@ -488,7 +480,6 @@ const CFDPasswordForm = observer(
488480
/>
489481
</Text>
490482
)}
491-
{/* {product === PRODUCT.ZEROSPREAD && account_type.category === CATEGORY.REAL && ( */}
492483
{need_tnc && (
493484
<CfdPasswordModalTnc
494485
className='cfd-password-modal-tnc--bottom'
@@ -560,7 +551,6 @@ const CFDPasswordModal = observer(({ form_error, platform }: TCFDPasswordModalPr
560551
const history = useHistory();
561552

562553
const [is_password_modal_exited, setPasswordModalExited] = React.useState(true);
563-
const is_bvi = landing_companies?.mt_financial_company?.financial_stp?.shortcode === 'bvi';
564554
const has_mt5_account = Boolean(mt5_login_list?.length);
565555
const should_set_trading_password =
566556
Array.isArray(account_status?.status) &&
@@ -708,8 +698,6 @@ const CFDPasswordModal = observer(({ form_error, platform }: TCFDPasswordModalPr
708698

709699
const should_show_sent_email_modal = is_sent_email_modal_enabled && is_password_modal_exited;
710700

711-
const is_real_financial_stp = [account_type.category, account_type.type].join('_') === 'real_financial_stp';
712-
713701
const should_show_password_modal = React.useMemo(() => {
714702
if (should_show_password) {
715703
return should_set_trading_password ? true : isDesktop;
@@ -829,14 +817,12 @@ const CFDPasswordModal = observer(({ form_error, platform }: TCFDPasswordModalPr
829817

830818
const cfd_password_form = (
831819
<CFDPasswordForm
832-
is_bvi={is_bvi}
833820
closeModal={closeModal}
834821
error_type={error_type}
835822
error_message={error_type !== 'InvalidTradingPlatformPasswordFormat' ? error_message : ''}
836823
has_mt5_account={has_mt5_account}
837824
form_error={form_error}
838825
should_set_trading_password={should_set_trading_password}
839-
is_real_financial_stp={is_real_financial_stp}
840826
validatePassword={validatePassword}
841827
onForgotPassword={handleForgotPassword}
842828
submitPassword={submitPassword}

0 commit comments

Comments
 (0)