Skip to content

Commit

Permalink
fix: loading
Browse files Browse the repository at this point in the history
  • Loading branch information
amina-deriv committed Nov 15, 2024
1 parent 5dd5b90 commit 38cde2b
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 17 deletions.
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 @@ -190,9 +190,11 @@ const CFDsListing = observer(() => {
updateMT5AccountDetails();
}, [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;
const is_cfd_accounts_supported =
combined_cfd_mt5_accounts.length || available_dxtrade_accounts.length || available_ctrader_accounts.length;

const is_mt5_list_loading = !is_landing_company_loaded || is_populating_mt5_account_list || is_switching;

return is_cfd_accounts_supported ? (
<ListingContainer
title={
Expand All @@ -215,7 +217,7 @@ const CFDsListing = observer(() => {
</Text>
</div>
{has_svg_accounts_to_migrate && is_landing_company_loaded && <MigrationBanner />}
{!is_mt5_list_loading ? (
{!is_mt5_list_loading && combined_cfd_mt5_accounts.length ? (
<React.Fragment>
{/* MT5 */}
{combined_cfd_mt5_accounts.map((existing_account, index: number) => {
Expand Down
24 changes: 17 additions & 7 deletions packages/appstore/src/modules/traders-hub/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,14 @@ const TradersHub = observer(() => {
} = client;

const { is_eu_demo, is_eu_real } = useContentFlag();
const { selected_platform_type, setTogglePlatformType, is_eu_user } = traders_hub;
const {
selected_platform_type,
setTogglePlatformType,
is_eu_user,
combined_cfd_mt5_accounts,
available_ctrader_accounts,
available_dxtrade_accounts,
} = traders_hub;
const traders_hub_ref = React.useRef<HTMLDivElement>(null);

const can_show_notify =
Expand Down Expand Up @@ -95,9 +102,12 @@ const TradersHub = observer(() => {
setTogglePlatformType(event.target.value);
};
if (!is_logged_in) return null;
const is_cfd_accounts_supported =
combined_cfd_mt5_accounts.length || available_dxtrade_accounts.length || available_ctrader_accounts.length;
const should_show_cfd_section = !!(is_mt5_allowed && is_cfd_accounts_supported);

const getOrderedPlatformSections = () => {
if (is_mt5_allowed) {
if (should_show_cfd_section) {
return (
<OrderedPlatformSections
is_cfd_visible={selected_platform_type === 'cfd'}
Expand All @@ -111,13 +121,13 @@ const TradersHub = observer(() => {
const desktopContent = !is_landing_company_loaded ? (
<OrderedPlatformSections />
) : (
<OrderedPlatformSections is_cfd_visible={is_mt5_allowed} />
<OrderedPlatformSections is_cfd_visible={should_show_cfd_section} />
);

const mobileTabletContent = (
<React.Fragment>
{is_landing_company_loaded ? (
is_mt5_allowed && (
should_show_cfd_section && (
<ButtonToggle
buttons_arr={is_eu_user ? platform_toggle_options_eu : platform_toggle_options}
className='traders-hub__button-toggle'
Expand All @@ -131,7 +141,7 @@ const TradersHub = observer(() => {
) : (
<ButtonToggleLoader />
)}
{is_landing_company_loaded && !is_mt5_allowed && (
{is_landing_company_loaded && !should_show_cfd_section && (
<div className='traders-hub--mt5-not-allowed'>
<Text size='s' weight='bold' color='prominent'>
<Localize i18n_default_text='Multipliers' />
Expand All @@ -151,8 +161,8 @@ const TradersHub = observer(() => {
<div
id='traders-hub'
className={classNames('traders-hub', {
'traders-hub--eu-user': is_eu_user && is_mt5_allowed,
'traders-hub--eu-user-without-mt5': is_eu_user && !is_mt5_allowed,
'traders-hub--eu-user': is_eu_user && should_show_cfd_section,
'traders-hub--eu-user-without-mt5': is_eu_user && !should_show_cfd_section,
})}
ref={traders_hub_ref}
>
Expand Down
31 changes: 23 additions & 8 deletions packages/core/src/Stores/traders-hub-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,12 +491,21 @@ export default class TradersHubStore extends BaseStore {
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 => {
Expand Down Expand Up @@ -902,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 ?? {});
Expand Down

0 comments on commit 38cde2b

Please sign in to comment.