Skip to content

Commit

Permalink
Merge pull request binary-com#160 from amina-deriv/86737_total_assest…
Browse files Browse the repository at this point in the history
…s_based_on_tab

Amina/fix: total assets to be shown based on selected region
  • Loading branch information
mahdiyeh-deriv committed Jan 22, 2023
2 parents c6f9f7b + 3749e57 commit c3da57c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import { useStores } from 'Stores';
import './asset-summary.scss';

const AssetSummary = () => {
const { client, traders_hub } = useStores();
const { has_active_real_account } = client;
const { traders_hub } = useStores();
const {
selected_account_type,
platform_real_balance,
Expand All @@ -18,6 +17,8 @@ const AssetSummary = () => {
cfd_real_balance,
content_flag,
is_eu_user,
no_CR_account,
no_MF_account,
} = traders_hub;

const getTotalBalance = () => {
Expand All @@ -34,6 +35,8 @@ const AssetSummary = () => {
};
};

const has_active_related_deriv_account = !((no_CR_account && !is_eu_user) || (no_MF_account && is_eu_user)); // if selected region is non-eu, check active cr accounts, if selected region is eu- check active mf accounts

const eu_text = content_flag === ContentFlag.EU_REAL || is_eu_user;

const is_eu_popover_text = eu_text
Expand All @@ -44,7 +47,7 @@ const AssetSummary = () => {

return (
<div className='asset-summary'>
{has_active_real_account || selected_account_type === 'demo' ? (
{has_active_related_deriv_account || selected_account_type === 'demo' ? (
<React.Fragment>
{!isMobile() ? (
<Text align='right' size='xs' line_height='s'>
Expand Down
18 changes: 16 additions & 2 deletions packages/core/src/Stores/traders-hub-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,13 @@ export default class TradersHubStore extends BaseStore {
this.platform_demo_balance = { balance, currency };
}

const platform_real_accounts = account_list.filter(account => !account.is_virtual);
const platform_real_accounts = account_list.filter(
account =>
!account.is_virtual &&
(this.is_eu_user
? account.landing_company_shortcode === 'maltainvest'
: account.landing_company_shortcode !== 'maltainvest')
);
if (platform_real_accounts?.length) {
this.platform_real_balance = await this.getTotalBalance(
platform_real_accounts,
Expand All @@ -690,9 +696,17 @@ export default class TradersHubStore extends BaseStore {
cfd_accounts = [...cfd_accounts, ...dxtrade_accounts_list];
}

const cfd_real_accounts = cfd_accounts.filter(account => account.account_type === 'real');
const cfd_real_accounts = cfd_accounts.filter(
account =>
account.account_type === 'real' &&
(this.is_eu_user
? account.landing_company_short === 'maltainvest'
: account.landing_company_short !== 'maltainvest')
);
if (cfd_real_accounts?.length) {
this.cfd_real_balance = await this.getTotalBalance(cfd_real_accounts, cfd_real_accounts[0]?.currency);
} else {
this.cfd_real_balance = { balance: 0, currency: 'USD' };
}

const cfd_demo_accounts = cfd_accounts.filter(account => account.account_type === 'demo');
Expand Down

0 comments on commit c3da57c

Please sign in to comment.