@@ -151,8 +161,8 @@ const TradersHub = observer(() => {
diff --git a/packages/cfd/src/Containers/cfd-password-modal-info.tsx b/packages/cfd/src/Containers/cfd-password-modal-info.tsx
index 471556ea0cec..f0ec7c1de511 100644
--- a/packages/cfd/src/Containers/cfd-password-modal-info.tsx
+++ b/packages/cfd/src/Containers/cfd-password-modal-info.tsx
@@ -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 = {
diff --git a/packages/core/src/Stores/traders-hub-store.js b/packages/core/src/Stores/traders-hub-store.js
index 3e6e8d04642d..a44d32ee64cc 100644
--- a/packages/core/src/Stores/traders-hub-store.js
+++ b/packages/core/src/Stores/traders-hub-store.js
@@ -467,9 +467,20 @@ 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 || (this.no_CR_account && !this.is_eu_user)) {
+ 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]) {
@@ -477,16 +488,24 @@ export default class TradersHubStore extends BaseStore {
}
acc[product].push(item);
}
-
return acc;
}, {});
- const getFilteredAccounts = () =>
- this.root_store.client.is_logged_in
- ? getMT5Accounts.filter(account =>
- Object.prototype.hasOwnProperty.call(groupedByProduct, account.product)
- )
- : getMT5Accounts;
+ const getFilteredAccounts = () => {
+ if (this.is_low_risk_cr_eu_real) {
+ const existing_account = this.root_store.client.mt5_login_list.filter(
+ account => account.landing_company_short === this.root_store.client.landing_company_shortcode
+ );
+ return existing_account.length
+ ? getMT5Accounts.filter(account => account.product === existing_account[0].product)
+ : [];
+ } else if (this.root_store.client.is_logged_in) {
+ return getMT5Accounts.filter(account =>
+ Object.prototype.hasOwnProperty.call(groupedByProduct, account.product)
+ );
+ }
+ return getMT5Accounts;
+ };
const all_available_accounts = [...getCFDAvailableAccount(), ...getFilteredAccounts()];
this.available_cfd_accounts = all_available_accounts.map(account => {
@@ -534,6 +553,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
@@ -891,14 +911,20 @@ export default class TradersHubStore extends BaseStore {
);
const { mt5_login_list } = await WS.authorized.mt5LoginList();
const current_account = mt5_login_list?.filter(
- account => account.landing_company_short === jurisdiction_selected_shortcode && account.product === product
+ account =>
+ account.landing_company_short === jurisdiction_selected_shortcode &&
+ account.product === product &&
+ account.account_type === this.selected_account_type
);
if (current_account.length) {
this.setSelectedJurisdictionKYCStatus(current_account[0]?.client_kyc_status ?? {});
} else {
const selected_mt5_account = trading_platform_available_accounts?.filter(
- account => account.shortcode === jurisdiction_selected_shortcode && account.product === product
+ account =>
+ account.shortcode === jurisdiction_selected_shortcode &&
+ account.product === product &&
+ account.is_default_jurisdiction === 'true'
);
if (selected_mt5_account.length) {
this.setSelectedJurisdictionKYCStatus(selected_mt5_account[0]?.client_kyc_status ?? {});
diff --git a/packages/hooks/src/__tests__/useIsSelectedMT5AccountCreated.spec.tsx b/packages/hooks/src/__tests__/useIsSelectedMT5AccountCreated.spec.tsx
index f7912df8c47f..c98a3b6a6695 100644
--- a/packages/hooks/src/__tests__/useIsSelectedMT5AccountCreated.spec.tsx
+++ b/packages/hooks/src/__tests__/useIsSelectedMT5AccountCreated.spec.tsx
@@ -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' } },
});
@@ -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();
@@ -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' } },
});
@@ -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(),
},
@@ -81,6 +107,100 @@ describe('useIsSelectedMT5AccountCreated', () => {
product: 'standard',
},
},
+ traders_hub: {
+ selected_account_type: 'real',
+ },
+ });
+
+ const wrapper = ({ children }: { children: JSX.Element }) => (
+ {children}
+ );
+ 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 }) => (
+ {children}
+ );
+ 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 }) => (
@@ -88,7 +208,15 @@ describe('useIsSelectedMT5AccountCreated', () => {
);
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', () => {
@@ -104,6 +232,9 @@ describe('useIsSelectedMT5AccountCreated', () => {
product: 'standard',
},
},
+ traders_hub: {
+ selected_account_type: 'real',
+ },
});
const wrapper = ({ children }: { children: JSX.Element }) => (
diff --git a/packages/hooks/src/useIsSelectedMT5AccountCreated.ts b/packages/hooks/src/useIsSelectedMT5AccountCreated.ts
index 7a37a63af76b..6a698981a7f2 100644
--- a/packages/hooks/src/useIsSelectedMT5AccountCreated.ts
+++ b/packages/hooks/src/useIsSelectedMT5AccountCreated.ts
@@ -27,6 +27,7 @@ const useIsSelectedMT5AccountCreated = () => {
const {
client,
modules: { cfd },
+ traders_hub: { selected_account_type },
} = useStore();
const { mt5_login_list, trading_platform_available_accounts, updateMT5AccountDetails } = client;
@@ -39,17 +40,22 @@ const useIsSelectedMT5AccountCreated = () => {
const { jurisdiction_selected_shortcode, product } = cfd;
const created_account = mt5_login_list.filter(
- account => account.landing_company_short === jurisdiction_selected_shortcode && account.product === product
+ account =>
+ account.landing_company_short === jurisdiction_selected_shortcode &&
+ account.product === product &&
+ account.account_type === selected_account_type
);
const selected_account = trading_platform_available_accounts.filter(
- account => account.shortcode === jurisdiction_selected_shortcode && account.product === product
+ account =>
+ account.shortcode === jurisdiction_selected_shortcode &&
+ account.product === product &&
+ account.is_default_jurisdiction === 'true'
);
const is_selected_MT5_account_created = created_account && Object.keys(created_account).length > 0;
const existing_account = is_selected_MT5_account_created ? created_account[0] : null;
const existing_account_status = existing_account?.status ? getStatusBadge(existing_account?.status) : null;
-
const available_account_to_create = !is_selected_MT5_account_created ? selected_account[0] : null;
return {
is_selected_MT5_account_created,