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

Amina/cfd 4813 diel #17474

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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 @@ -55,33 +55,74 @@ mockUseTradingPlatformStatus.mockReturnValue({
getPlatformStatus: jest.fn(),
});
describe('CFDsListing', () => {
const mock = mockStore({
traders_hub: {
selected_region: 'Non-EU',
has_any_real_account: true,
is_real: true,
no_MF_account: true,
is_demo_low_risk: true,
},
client: {
is_landing_company_loaded: true,
real_account_creation_unlock_date: '2022-02-02',
},
modules: {
cfd: {
toggleCompareAccountsModal: jest.fn(),
setAccountType: jest.fn(),
current_list: {},
it('should not render the component when cfd accounts are not supported', () => {
const mock = mockStore({
traders_hub: {
selected_region: 'Non-EU',
has_any_real_account: true,
is_real: true,
no_MF_account: true,
is_demo_low_risk: true,
available_dxtrade_accounts: [],
available_ctrader_accounts: [],
combined_cfd_mt5_accounts: [],
},
},
client: {
is_landing_company_loaded: true,
real_account_creation_unlock_date: '2022-02-02',
},
modules: {
cfd: {
toggleCompareAccountsModal: jest.fn(),
setAccountType: jest.fn(),
current_list: {},
},
},
});
const wrapper = ({ children }: { children: JSX.Element }) => (
<StoreProvider store={mock}>{children}</StoreProvider>
);

render(<CFDsListing />, { wrapper });
expect(screen.queryByTestId('listing-container')).not.toBeInTheDocument();
});

it('should render the component', () => {
it('should render the component when cfd accounts are supported', () => {
const mock = mockStore({
traders_hub: {
selected_region: 'Non-EU',
has_any_real_account: true,
is_real: true,
no_MF_account: true,
is_demo_low_risk: true,
available_dxtrade_accounts: [],
available_ctrader_accounts: [],
combined_cfd_mt5_accounts: [
{
landing_company_short: 'svg',
product: 'financial',
status: 'proof_failed',
login: '123',
},
],
},
client: {
is_landing_company_loaded: true,
real_account_creation_unlock_date: '2022-02-02',
},
modules: {
cfd: {
toggleCompareAccountsModal: jest.fn(),
setAccountType: jest.fn(),
current_list: {},
},
},
});
const wrapper = ({ children }: { children: JSX.Element }) => (
<StoreProvider store={mock}>{children}</StoreProvider>
);

render(<CFDsListing />, { wrapper });
expect(screen.getByTestId('listing-container')).toBeInTheDocument();
expect(screen.queryByTestId('listing-container')).toBeInTheDocument();
});
});
6 changes: 4 additions & 2 deletions packages/appstore/src/components/cfds-listing/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ const CFDsListing = observer(() => {
}, [is_landing_company_loaded, is_populating_mt5_account_list]);

const is_mt5_list_loading = !is_landing_company_loaded || is_populating_mt5_account_list || is_switching;
return (
const is_cfd_accounts_supported =
combined_cfd_mt5_accounts.length || available_dxtrade_accounts.length || available_ctrader_accounts.length;
return is_cfd_accounts_supported ? (
<ListingContainer
title={
isDesktop && (
Expand Down Expand Up @@ -553,7 +555,7 @@ const CFDsListing = observer(() => {
</Fragment>
)}
</ListingContainer>
);
) : null;
});

export default CFDsListing;
1 change: 0 additions & 1 deletion packages/cfd/src/Containers/cfd-password-modal-info.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react';
import { Icon, Text } from '@deriv/components';
import { Localize } from '@deriv/translations';
import { DBVI_COMPANY_NAMES } from '@deriv/shared';
import { useIsSelectedMT5AccountCreated } from '@deriv/hooks';

type CfdPasswordModalInfoProps = {
Expand Down
19 changes: 15 additions & 4 deletions packages/core/src/Stores/traders-hub-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,17 +467,27 @@ export default class TradersHubStore extends BaseStore {
];

const groupedByProduct = trading_platform_available_accounts.reduce((acc, item) => {
const { product, is_default_jurisdiction } = item;
if (
is_default_jurisdiction === 'true' ||
const { product, is_default_jurisdiction, linkable_landing_companies } = item;
if (this.is_demo) {
if (
is_default_jurisdiction === 'true' ||
(acc[product] && acc[product].some(i => i.is_default_jurisdiction === 'true'))
) {
if (!acc[product]) {
acc[product] = [];
}
acc[product].push(item);
}
} else if (
(linkable_landing_companies.includes(this.root_store.client.landing_company_shortcode) &&
is_default_jurisdiction === 'true') ||
(acc[product] && acc[product].some(i => i.is_default_jurisdiction === 'true'))
) {
if (!acc[product]) {
acc[product] = [];
}
acc[product].push(item);
}

return acc;
}, {});

Expand Down Expand Up @@ -534,6 +544,7 @@ export default class TradersHubStore extends BaseStore {
);
return;
}

if (this.financial_restricted_countries) {
this.available_mt5_accounts = this.available_cfd_accounts.filter(
account => account.market_type === 'financial' && account.platform === CFD_PLATFORMS.MT5
Expand Down
141 changes: 136 additions & 5 deletions packages/hooks/src/__tests__/useIsSelectedMT5AccountCreated.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,20 @@ describe('useIsSelectedMT5AccountCreated', () => {
common: { platform: CFD_PLATFORMS.MT5 },
client: {
mt5_login_list: [
{ landing_company_short: 'svg', product: 'financial', status: 'proof_failed', login: '123' },
{
landing_company_short: 'svg',
product: 'financial',
status: 'proof_failed',
login: '123',
account_type: 'real',
},
],
updateMT5AccountDetails: jest.fn(),
trading_platform_available_accounts: [{ shortcode: 'svg', product: 'financial' }],
},

traders_hub: {
selected_account_type: 'real',
},
modules: { cfd: { jurisdiction_selected_shortcode: 'svg', product: 'financial' } },
});

Expand All @@ -33,6 +41,7 @@ describe('useIsSelectedMT5AccountCreated', () => {
product: 'financial',
status: 'proof_failed',
login: '123',
account_type: 'real',
});
expect(result.current.existing_account_status).toBe(MT5_ACCOUNT_STATUS.FAILED);
expect(result.current.available_account_to_create).toBeNull();
Expand All @@ -42,14 +51,23 @@ describe('useIsSelectedMT5AccountCreated', () => {
common: { platform: CFD_PLATFORMS.MT5 },
client: {
mt5_login_list: [
{ landing_company_short: 'svg', product: 'financial', status: 'proof_failed', login: '123' },
{
landing_company_short: 'svg',
product: 'financial',
status: 'proof_failed',
login: '123',
account_type: 'real',
},
],
updateMT5AccountDetails: jest.fn(),
trading_platform_available_accounts: [
{ shortcode: 'svg', product: 'financial' },
{ shortcode: 'bvi', product: 'zero_spread' },
{ shortcode: 'bvi', product: 'zero_spread', is_default_jurisdiction: 'true' },
],
},
traders_hub: {
selected_account_type: 'real',
},

modules: { cfd: { jurisdiction_selected_shortcode: 'bvi', product: 'zero_spread' } },
});
Expand All @@ -65,13 +83,21 @@ describe('useIsSelectedMT5AccountCreated', () => {
expect(result.current.available_account_to_create).toEqual({
shortcode: 'bvi',
product: 'zero_spread',
is_default_jurisdiction: 'true',
});
});

it('should return the correct status when account status "verification_pending"', () => {
const mock = mockStore({
client: {
mt5_login_list: [{ landing_company_short: 'svg', product: 'standard', status: 'verification_pending' }],
mt5_login_list: [
{
landing_company_short: 'svg',
product: 'standard',
status: 'verification_pending',
account_type: 'real',
},
],
trading_platform_available_accounts: [{ shortcode: 'svg', product: 'standard' }],
updateMT5AccountDetails: jest.fn(),
},
Expand All @@ -81,14 +107,116 @@ describe('useIsSelectedMT5AccountCreated', () => {
product: 'standard',
},
},
traders_hub: {
selected_account_type: 'real',
},
});

const wrapper = ({ children }: { children: JSX.Element }) => (
<StoreProvider store={mock}>{children}</StoreProvider>
);
const { result } = renderHook(() => useIsSelectedMT5AccountCreated(), { wrapper });

expect(result.current.existing_account_status).toBe(MT5_ACCOUNT_STATUS.PENDING);
});

it('should return available accounts based on real/demo account type', () => {
const mock = mockStore({
client: {
mt5_login_list: [
{
landing_company_short: 'svg',
product: 'standard',
status: 'verification_pending',
account_type: 'real',
},
{
landing_company_short: 'svg',
product: 'financial',
status: 'proof_failed',
account_type: 'real',
},
],
trading_platform_available_accounts: [
{ shortcode: 'svg', product: 'standard', is_default_jurisdiction: 'true' },
{ shortcode: 'bvi', product: 'financial', is_default_jurisdiction: 'true' },
],
updateMT5AccountDetails: jest.fn(),
},
modules: {
cfd: {
jurisdiction_selected_shortcode: 'svg',
product: 'standard',
},
},
traders_hub: {
selected_account_type: 'demo',
},
});

const wrapper = ({ children }: { children: JSX.Element }) => (
<StoreProvider store={mock}>{children}</StoreProvider>
);
const { result } = renderHook(() => useIsSelectedMT5AccountCreated(), { wrapper });

expect(result.current.is_selected_MT5_account_created).toBe(false);
expect(result.current.existing_account).toBeNull();
expect(result.current.existing_account_status).toBeNull();
expect(result.current.available_account_to_create).toEqual({
shortcode: 'svg',
product: 'standard',
is_default_jurisdiction: 'true',
});
});

it('should return available accounts based on real/demo account type', () => {
const mock = mockStore({
client: {
mt5_login_list: [
{
landing_company_short: 'svg',
product: 'standard',
status: 'verification_pending',
account_type: 'real',
},
{
landing_company_short: 'svg',
product: 'financial',
status: 'proof_failed',
account_type: 'real',
},
],
trading_platform_available_accounts: [
{ shortcode: 'svg', product: 'standard', is_default_jurisdiction: 'true' },
{ shortcode: 'bvi', product: 'financial', is_default_jurisdiction: 'true' },
],
updateMT5AccountDetails: jest.fn(),
},
modules: {
cfd: {
jurisdiction_selected_shortcode: 'svg',
product: 'standard',
},
},
traders_hub: {
selected_account_type: 'real',
},
});

const wrapper = ({ children }: { children: JSX.Element }) => (
<StoreProvider store={mock}>{children}</StoreProvider>
);
const { result } = renderHook(() => useIsSelectedMT5AccountCreated(), { wrapper });

expect(result.current.is_selected_MT5_account_created).toBe(true);
expect(result.current.existing_account).toEqual({
landing_company_short: 'svg',
product: 'standard',
status: 'verification_pending',
account_type: 'real',
});
expect(result.current.existing_account_status).toBe(MT5_ACCOUNT_STATUS.PENDING);
expect(result.current.available_account_to_create).toBeNull();
});

it('should handle cases where mt5_login_list and trading_platform_available_accounts are empty', () => {
Expand All @@ -104,6 +232,9 @@ describe('useIsSelectedMT5AccountCreated', () => {
product: 'standard',
},
},
traders_hub: {
selected_account_type: 'real',
},
});

const wrapper = ({ children }: { children: JSX.Element }) => (
Expand Down
Loading
Loading