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

feat: derivx cfd account is displayed in dashboard along with syn & f… #2

Merged
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
4 changes: 3 additions & 1 deletion packages/cfd/src/Components/cfd-real-account-display.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type TCFDRealAccountDisplayProps = {
is_loading?: boolean;
is_logged_in: boolean;
isSyntheticCardVisible: (account_category: string) => boolean;
isDxtradeAllCardVisible: (account_category: string) => boolean;
is_virtual: boolean;
isFinancialCardVisible: () => boolean;
onSelectAccount: (objCFDAccount: TObjectCFDAccount) => void;
Expand Down Expand Up @@ -75,6 +76,7 @@ const CFDRealAccountDisplay = ({
is_virtual,
isSyntheticCardVisible,
isFinancialCardVisible,
isDxtradeAllCardVisible,
onSelectAccount,
realSyntheticAccountsExistingData,
realFinancialAccountsExistingData,
Expand Down Expand Up @@ -245,7 +247,7 @@ const CFDRealAccountDisplay = ({
/>
);

const derivx_all_account = platform === 'dxtrade' && (
const derivx_all_account = platform === 'dxtrade' && isDxtradeAllCardVisible('real') && (
<CFDAccountCard
commission_message={localize('No commission')}
descriptor={general_messages.getFinancialAccountDescriptor(platform)}
Expand Down
30 changes: 24 additions & 6 deletions packages/cfd/src/Containers/cfd-dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,9 @@ const CFDDashboard = (props: TCFDDashboardProps) => {
if (props.is_logged_in) {
['demo', 'real'].forEach(account_type => {
const should_enable_tab =
isDxtradeAllCardVisible() || isSyntheticCardVisible(account_type) || isFinancialCardVisible();
isDxtradeAllCardVisible(account_type) ||
isSyntheticCardVisible(account_type) ||
isFinancialCardVisible();

if (account_type === 'real' && is_real_enabled !== should_enable_tab) {
setIsRealEnabled(should_enable_tab);
Expand Down Expand Up @@ -324,9 +326,18 @@ const CFDDashboard = (props: TCFDDashboardProps) => {
props.openPasswordModal();
};

const isDxtradeAllCardVisible = () => {
const hasAccount = (category: string, type: string) => {
return Object.keys(current_list).some(key => key.startsWith(`${platform}.${category}.${type}`));
};

const isDxtradeAllCardVisible = (account_category: string) => {
const { platform, landing_companies } = props;

const has_synthetic_account = hasAccount(account_category, 'synthetic');
const has_financial_account = hasAccount(account_category, 'financial');

if (has_synthetic_account || has_financial_account) return false;

return isLandingCompanyEnabled({
landing_companies,
platform,
Expand All @@ -335,22 +346,28 @@ const CFDDashboard = (props: TCFDDashboardProps) => {
};

const isSyntheticCardVisible = (account_category: string) => {
const { current_list, platform, is_eu, is_eu_country, landing_companies, is_logged_in } = props;
const has_synthetic_account = Object.keys(current_list).some(key =>
key.startsWith(`${platform}.${account_category}.synthetic`)
);
const { platform, is_eu, is_eu_country, landing_companies, is_logged_in } = props;
const has_synthetic_account = hasAccount(account_category, 'synthetic');
const has_financial_account = hasAccount(account_category, 'financial');

// Hiding card for logged out EU users
if (!is_logged_in && is_eu_country) return false;

if (is_eu && !has_synthetic_account) return false;

if (!has_synthetic_account && !has_financial_account) return false;

return isLandingCompanyEnabled({ landing_companies, platform, type: 'gaming' }) || !is_logged_in;
};

const isFinancialCardVisible = () => {
const { platform, landing_companies, is_logged_in } = props;

const has_synthetic_account = hasAccount('real', 'synthetic');
const has_financial_account = hasAccount('real', 'financial');

if (!has_synthetic_account && !has_financial_account) return false;

return (
!is_logged_in ||
isLandingCompanyEnabled({
Expand Down Expand Up @@ -537,6 +554,7 @@ const CFDDashboard = (props: TCFDDashboardProps) => {
is_virtual={is_virtual}
isSyntheticCardVisible={isSyntheticCardVisible}
isFinancialCardVisible={isFinancialCardVisible}
isDxtradeAllCardVisible={isDxtradeAllCardVisible}
openAccountTransfer={openAccountTransfer}
openPasswordManager={togglePasswordManagerModal}
platform={platform}
Expand Down
2 changes: 1 addition & 1 deletion packages/components/stories/icon/icons.js
Original file line number Diff line number Diff line change
Expand Up @@ -885,4 +885,4 @@ export const icons =
'IcWalletZingpayDark',
'IcWalletZingpayLight',
],
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,14 @@ const AccountSwitcher = props => {
}

if (!is_demo && platform === CFD_PLATFORMS.DXTRADE) {
return [...gaming_config, ...financial_config, ...all_config];
const has_account = Object.keys(existing_cfd_accounts).some(
key =>
existing_cfd_accounts[key].market_type === 'synthetic' ||
existing_cfd_accounts[key].market_type === 'financial'
);

if (has_account) return [...gaming_config, ...financial_config];
return [...all_config];
}

return [...gaming_config, ...financial_config];
Expand Down