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

oskar/mt5_redirect #1974

Merged
merged 9 commits into from
Oct 20, 2020
13 changes: 8 additions & 5 deletions packages/core/src/Stores/client-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -553,9 +553,12 @@ export default class ClientStore extends BaseStore {

@computed
get is_mt5_allowed() {
if (!this.landing_companies || !Object.keys(this.landing_companies).length) return false;
const has_mt5 =
'mt_financial_company' in this.landing_companies || 'mt_gaming_company' in this.landing_companies;
return this.isMT5Allowed(this.landing_companies);
}

isMT5Allowed = landing_companies => {
if (!landing_companies || !Object.keys(landing_companies).length) return false;
const has_mt5 = 'mt_financial_company' in landing_companies || 'mt_gaming_company' in landing_companies;

// TODO: [deriv-eu] Remove the if statement once EU is enabled in dev
if (this.is_eu && !this.root_store.ui.is_eu_enabled) {
Expand All @@ -565,7 +568,7 @@ export default class ClientStore extends BaseStore {
}

if (has_mt5) {
const { gaming_company, financial_company } = this.landing_companies;
const { gaming_company, financial_company } = landing_companies;
// eslint-disable-next-line no-nested-ternary
return gaming_company
? gaming_company.shortcode === 'svg'
Expand All @@ -575,7 +578,7 @@ export default class ClientStore extends BaseStore {
}

return false;
}
};

@computed
get is_eu_country() {
Expand Down
16 changes: 12 additions & 4 deletions packages/trader/src/Modules/MT5/Containers/mt5-dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { DesktopWrapper, Icon, MobileWrapper, Tabs } from '@deriv/components';
import { isEmptyObject, routes } from '@deriv/shared';
import { Localize, localize } from '@deriv/translations';
import { connect } from 'Stores/connect';
import { WS } from 'Services/ws-methods';
import LoadingMT5RealAccountDisplay from './loading-mt5-real-account-display.jsx';
import MissingRealAccount from './missing-real-account.jsx';
import MT5AccountOpeningRealFinancialStpModal from './mt5-account-opening-real-financial-stp-modal.jsx';
Expand Down Expand Up @@ -47,10 +48,16 @@ class MT5Dashboard extends React.Component {
},
};

componentDidMount() {
if (!this.props.is_mt5_allowed) {
this.props.history.push(routes.trade);
async componentDidMount() {
if (this.props.is_logged_in) {
await WS.wait('get_settings');
const res = await WS.authorized.cache.landingCompany(this.props.residence);

if (!this.props.isMT5Allowed(res.landing_company)) {
this.props.history.push(routes.trade);
}
}

this.updateActiveIndex(this.getIndexToSet());
this.openResetPassword();
this.props.onMount();
Expand Down Expand Up @@ -400,7 +407,8 @@ export default withRouter(
openPasswordModal: modules.mt5.enableMt5PasswordModal,
openAccountNeededModal: ui.openAccountNeededModal,
is_loading: client.is_populating_mt5_account_list,
is_mt5_allowed: client.is_mt5_allowed,
residence: client.residence,
isMT5Allowed: client.isMT5Allowed,
has_mt5_account: modules.mt5.has_mt5_account,
has_real_account: client.has_active_real_account,
setAccountType: modules.mt5.setAccountType,
Expand Down