Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maryia/Feat: new MF flow for DMT5 #7

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ describe('<CFDRealAccountDisplay />', () => {
virtual_company: 'virtual',
},
onSelectAccount: jest.fn(),
openAccountNeededModal: jest.fn(),
openDerivRealAccountNeededModal: jest.fn(),
openAccountTransfer: jest.fn(),
openPasswordManager: jest.fn(),
openPasswordModal: jest.fn(),
Expand All @@ -131,6 +131,7 @@ describe('<CFDRealAccountDisplay />', () => {
value: 'ax',
},
],
should_enable_add_button: false,
standpoint: {
financial_company: 'svg',
gaming_company: 'svg',
Expand Down Expand Up @@ -314,16 +315,18 @@ describe('<CFDRealAccountDisplay />', () => {
expect(screen.queryAllByRole('button', { name: /add real account/i }).length).toBe(0);
});

it('should render a CFDs card only with enabled "Add real account" button on DMT5 when is_logged_in=true & is_eu=true', () => {
it('should render a CFDs card only with enabled "Add real account" button on DMT5 when is_logged_in=true, should_enable_add_button=true & is_eu=true', () => {
props.isSyntheticCardVisible = jest.fn(() => false);
render(<CFDRealAccountDisplay {...props} is_eu account_settings={account_settings_eu} />);
render(
<CFDRealAccountDisplay {...props} is_eu should_enable_add_button account_settings={account_settings_eu} />
);

checkAccountCardsRendering(TESTED_CASES.EU);
const add_real_account_button = screen.getByRole('button', { name: /add real account/i });
expect(add_real_account_button).toBeEnabled();

fireEvent.click(add_real_account_button);
expect(props.openAccountNeededModal).toHaveBeenCalledWith('maltainvest', 'Deriv Multipliers', 'real CFDs');
expect(props.openDerivRealAccountNeededModal).toHaveBeenCalledTimes(1);
});

it('should render a CFDs card only without "Add real account" button on DMT5 when is_logged_in=false & is_eu_country=true (also when redirected from Deriv X platform)', () => {
Expand Down
23 changes: 5 additions & 18 deletions packages/cfd/src/Components/cfd-real-account-display.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ type TCFDRealAccountDisplayProps = {
has_cfd_account_error: boolean;
is_fully_authenticated: boolean;
account_settings: GetSettings;
openAccountNeededModal: (target: string, target_label: string, target_dmt5_label: string) => void;
standpoint: TStandPoint;
is_loading?: boolean;
is_logged_in: boolean;
Expand Down Expand Up @@ -90,7 +89,6 @@ const CFDRealAccountDisplay = ({
has_cfd_account,
openPasswordManager,
account_settings,
openAccountNeededModal,
platform,
standpoint,
is_logged_in,
Expand Down Expand Up @@ -140,22 +138,11 @@ const CFDRealAccountDisplay = ({
return specifications[platform as keyof TSpecifications].real_financial_specs;
}, [residence, is_logged_in, is_eu, is_eu_country, platform]);

const onSelectRealSynthetic = () => {
const onSelectRealAccount = (type: string) => {
if (should_enable_add_button) {
openDerivRealAccountNeededModal();
} else if (is_eu && standpoint.malta && !has_malta_account) {
openAccountNeededModal('malta', localize('Deriv Synthetic'), localize('DMT5 Synthetic'));
} else {
onSelectAccount({ type: 'synthetic', category: 'real', platform });
}
};
const onSelectRealFinancial = () => {
if (should_enable_add_button) {
openDerivRealAccountNeededModal();
} else if (is_eu && !has_maltainvest_account) {
openAccountNeededModal('maltainvest', localize('Deriv Multipliers'), localize('real CFDs'));
} else {
onSelectAccount({ type: 'financial', category: 'real', platform });
onSelectAccount({ type, category: 'real', platform });
}
};

Expand Down Expand Up @@ -226,7 +213,7 @@ const CFDRealAccountDisplay = ({
should_show_trade_servers={should_show_trade_servers}
existing_data={acc}
commission_message={localize('No commission')}
onSelectAccount={onSelectRealSynthetic}
onSelectAccount={() => onSelectRealAccount('synthetic')}
onPasswordManager={openPasswordManager}
onClickFund={onClickFundReal}
platform={platform}
Expand All @@ -253,7 +240,7 @@ const CFDRealAccountDisplay = ({
should_show_trade_servers={should_show_trade_servers}
existing_data={undefined}
commission_message={localize('No commission')}
onSelectAccount={onSelectRealSynthetic}
onSelectAccount={() => onSelectRealAccount('synthetic')}
onPasswordManager={openPasswordManager}
onClickFund={onClickFundReal}
platform={platform}
Expand Down Expand Up @@ -285,7 +272,7 @@ const CFDRealAccountDisplay = ({
]
}
commission_message={localize('No commission')}
onSelectAccount={onSelectRealFinancial}
onSelectAccount={() => onSelectRealAccount('financial')}
onPasswordManager={openPasswordManager}
onClickFund={onClickFundReal}
platform={platform}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,7 @@ const AccountSwitcher = props => {

if (props.is_eu && !has_required_account) {
closeAccountsDialog();
props.openAccountNeededModal(
account_type === 'synthetic' ? props.standpoint.gaming_company : props.standpoint.financial_company,
account_type === 'synthetic' ? localize('Deriv Synthetic') : localize('Deriv Multipliers'),
account_type === 'synthetic' ? localize('DMT5 Synthetic') : localize('real CFDs')
);
props.openDerivRealAccountNeededModal();
} else {
if (should_redirect_fstp_password)
sessionStorage.setItem(
Expand Down Expand Up @@ -975,6 +971,7 @@ const account_switcher = withRouter(
has_maltainvest_account: client.has_maltainvest_account,
has_active_real_account: client.has_active_real_account,
openAccountNeededModal: ui.openAccountNeededModal,
openDerivRealAccountNeededModal: ui.openDerivRealAccountNeededModal,
logoutClient: client.logout,
landing_companies: client.landing_companies,
upgradeable_landing_companies: client.upgradeable_landing_companies,
Expand Down