From 5bd20299a542260f732782cb6796640bf8c793a1 Mon Sep 17 00:00:00 2001 From: maryia-binary Date: Thu, 30 Jun 2022 13:34:55 +0300 Subject: [PATCH 1/2] Maryia/Feat: MF flow --- .../Components/cfd-real-account-display.tsx | 21 +++++-------------- .../AccountSwitcher/account-switcher.jsx | 7 ++----- 2 files changed, 7 insertions(+), 21 deletions(-) diff --git a/packages/cfd/src/Components/cfd-real-account-display.tsx b/packages/cfd/src/Components/cfd-real-account-display.tsx index 41adbfcad734..62d987c297e4 100644 --- a/packages/cfd/src/Components/cfd-real-account-display.tsx +++ b/packages/cfd/src/Components/cfd-real-account-display.tsx @@ -140,22 +140,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 }); } }; @@ -226,7 +215,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} @@ -253,7 +242,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} @@ -285,7 +274,7 @@ const CFDRealAccountDisplay = ({ ] } commission_message={localize('No commission')} - onSelectAccount={onSelectRealFinancial} + onSelectAccount={() => onSelectRealAccount('financial')} onPasswordManager={openPasswordManager} onClickFund={onClickFundReal} platform={platform} diff --git a/packages/core/src/App/Containers/AccountSwitcher/account-switcher.jsx b/packages/core/src/App/Containers/AccountSwitcher/account-switcher.jsx index 4820f09ff2b1..a485f1981365 100644 --- a/packages/core/src/App/Containers/AccountSwitcher/account-switcher.jsx +++ b/packages/core/src/App/Containers/AccountSwitcher/account-switcher.jsx @@ -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( @@ -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, From c3e31dc3911218cefdf782ecbbe7cf1fa19b7ce5 Mon Sep 17 00:00:00 2001 From: maryia-binary Date: Thu, 30 Jun 2022 14:10:52 +0300 Subject: [PATCH 2/2] fix: tests --- .../__tests__/cfd-real-account-display.spec.js | 11 +++++++---- .../cfd/src/Components/cfd-real-account-display.tsx | 2 -- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/cfd/src/Components/__tests__/cfd-real-account-display.spec.js b/packages/cfd/src/Components/__tests__/cfd-real-account-display.spec.js index be94227496ca..d63877fdb8c6 100644 --- a/packages/cfd/src/Components/__tests__/cfd-real-account-display.spec.js +++ b/packages/cfd/src/Components/__tests__/cfd-real-account-display.spec.js @@ -110,7 +110,7 @@ describe('', () => { virtual_company: 'virtual', }, onSelectAccount: jest.fn(), - openAccountNeededModal: jest.fn(), + openDerivRealAccountNeededModal: jest.fn(), openAccountTransfer: jest.fn(), openPasswordManager: jest.fn(), openPasswordModal: jest.fn(), @@ -131,6 +131,7 @@ describe('', () => { value: 'ax', }, ], + should_enable_add_button: false, standpoint: { financial_company: 'svg', gaming_company: 'svg', @@ -314,16 +315,18 @@ describe('', () => { 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(); + render( + + ); 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)', () => { diff --git a/packages/cfd/src/Components/cfd-real-account-display.tsx b/packages/cfd/src/Components/cfd-real-account-display.tsx index 62d987c297e4..0cbb74a81e5d 100644 --- a/packages/cfd/src/Components/cfd-real-account-display.tsx +++ b/packages/cfd/src/Components/cfd-real-account-display.tsx @@ -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; @@ -90,7 +89,6 @@ const CFDRealAccountDisplay = ({ has_cfd_account, openPasswordManager, account_settings, - openAccountNeededModal, platform, standpoint, is_logged_in,