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

salar / Hotfix/multiplier eu #4989

Merged
merged 10 commits into from
Mar 10, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ Blockly.Blocks.trade_definition_multiplier = {
return [option, option];
});

multiplier_list_dropdown.updateOptions(multiplier_options, {
multiplier_list_dropdown?.updateOptions(multiplier_options, {
default_value: should_use_default_value ? undefined : multiplier_list_dropdown.getValue(),
});
}
Expand Down
2 changes: 1 addition & 1 deletion packages/bot-web-ui/src/app/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const App = ({ passthrough }) => {
React.useEffect(() => {
showDigitalOptionsMaltainvestError(core.client, common);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [core.client.is_options_blocked]);
}, [core.client.is_options_blocked, core.client.account_settings.country_code]);

React.useEffect(() => {
GTM.init(root_store_instance.current);
Expand Down
56 changes: 47 additions & 9 deletions packages/bot-web-ui/src/stores/app-store.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { action, reaction } from 'mobx';
import { showDigitalOptionsUnavailableError } from '@deriv/shared';
import { isEuResidenceWithOnlyVRTC, showDigitalOptionsUnavailableError } from '@deriv/shared';
import { localize } from '@deriv/translations';
import { runIrreversibleEvents, ApiHelpers, DBot } from '@deriv/bot-skeleton';

Expand All @@ -14,7 +14,6 @@ export default class AppStore {
onMount() {
const { blockly_store, core, main_content } = this.root_store;
const { client, common, ui } = core;

this.showDigitalOptionsMaltainvestError(client, common);

blockly_store.startLoading();
Expand All @@ -26,6 +25,7 @@ export default class AppStore {
this.registerCurrencyReaction.call(this);
this.registerOnAccountSwitch.call(this);
this.registerLandingCompanyChangeReaction.call(this);
this.registerResidenceChangeReaction.call(this);

window.addEventListener('click', this.onClickOutsideBlockly);
window.addEventListener('beforeunload', this.onBeforeUnload);
Expand Down Expand Up @@ -53,6 +53,9 @@ export default class AppStore {
if (typeof this.disposeLandingCompanyChangeReaction === 'function') {
this.disposeLandingCompanyChangeReaction();
}
if (typeof this.disposeResidenceChangeReaction === 'function') {
this.disposeResidenceChangeReaction();
}

window.removeEventListener('click', this.onClickOutsideBlockly);
window.removeEventListener('beforeunload', this.onBeforeUnload);
Expand Down Expand Up @@ -112,7 +115,6 @@ export default class AppStore {
() => client.switch_broadcast,
switch_broadcast => {
if (!switch_broadcast) return;

this.showDigitalOptionsMaltainvestError(client, common);

const { active_symbols, contracts_for } = ApiHelpers.instance;
Expand Down Expand Up @@ -141,7 +143,36 @@ export default class AppStore {
this.disposeLandingCompanyChangeReaction = reaction(
() => client.landing_company_shortcode,
() => {
if (client.has_maltainvest_account || client.is_options_blocked) {
if (
(!client.is_logged_in && client.is_eu_country) ||
salarhfz-fs marked this conversation as resolved.
Show resolved Hide resolved
client.has_maltainvest_account ||
isEuResidenceWithOnlyVRTC(client.active_accounts) ||
client.is_options_blocked
) {
showDigitalOptionsUnavailableError(common.showError, {
text: localize(
'We’re working to have this available for you soon. If you have another account, switch to that account to continue trading. You may add a DMT5 Financial.'
),
title: localize('DBot is not available for this account'),
link: localize('Go to DMT5 dashboard'),
});
}
}
);
}

registerResidenceChangeReaction() {
const { client, common } = this.root_store.core;

this.disposeResidenceChangeReaction = reaction(
() => client.account_settings.country_code,
() => {
if (
(!client.is_logged_in && client.is_eu_country) ||
client.has_maltainvest_account ||
isEuResidenceWithOnlyVRTC(client.active_accounts) ||
client.is_options_blocked
) {
showDigitalOptionsUnavailableError(common.showError, {
text: localize(
'We’re working to have this available for you soon. If you have another account, switch to that account to continue trading. You may add a DMT5 Financial.'
Expand Down Expand Up @@ -192,16 +223,23 @@ export default class AppStore {
}

onClickOutsideBlockly = event => {
const path = event.path || (event.composedPath && event.composedPath());
const is_click_outside_blockly = !path.some(el => el.classList && el.classList.contains('injectionDiv'));
if (document.querySelector('.injectionDiv')) {
const path = event.path || (event.composedPath && event.composedPath());
const is_click_outside_blockly = !path.some(el => el.classList && el.classList.contains('injectionDiv'));

if (is_click_outside_blockly) {
Blockly.hideChaff(/* allowToolbox */ false);
if (is_click_outside_blockly) {
Blockly?.hideChaff(/* allowToolbox */ false);
}
}
};

showDigitalOptionsMaltainvestError = (client, common) => {
if (client.has_maltainvest_account || client.is_options_blocked) {
if (
(!client.is_logged_in && client.is_eu_country) ||
client.has_maltainvest_account ||
isEuResidenceWithOnlyVRTC(client.active_accounts) ||
client.is_options_blocked
) {
showDigitalOptionsUnavailableError(common.showError, {
text: localize(
'We’re working to have this available for you soon. If you have another account, switch to that account to continue trading. You may add a DMT5 Financial.'
Expand Down
2 changes: 2 additions & 0 deletions packages/cashier/src/_common/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const copyToClipboard = text => {
document.execCommand('copy');
textField.remove();
};
// TODO: [duplicate_code] - Move this to shared package
// eu countries to support
const eu_countries = [
'it',
Expand Down Expand Up @@ -87,6 +88,7 @@ const eu_countries = [
'gb',
'mt',
];
// TODO: [duplicate_code] - Move this to shared package
// check if client is from EU
const isEuCountry = country => eu_countries.includes(country);

Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/_common/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const copyToClipboard = text => {
document.execCommand('copy');
textField.remove();
};
// TODO: [duplicate_code] - Move this to shared package
// eu countries to support
const eu_countries = [
'it',
Expand Down Expand Up @@ -85,6 +86,7 @@ const eu_countries = [
'gb',
'mt',
];
// TODO: [duplicate_code] - Move this to shared package
// check if client is from EU
const isEuCountry = country => eu_countries.includes(country);
// countries where synthetics are not offered
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { isEuCountry } from '../location';

export const showDigitalOptionsUnavailableError = (showError, message) => {
const { title, text, link } = message;
showError({
Expand All @@ -10,3 +12,10 @@ export const showDigitalOptionsUnavailableError = (showError, message) => {
should_clear_error_on_click: true,
});
};

export const isEuResidenceWithOnlyVRTC = accounts => {
return (
accounts?.length === 1 &&
accounts.every(acc => isEuCountry(acc.residence) && acc.landing_company_shortcode === 'virtual')
);
};
36 changes: 36 additions & 0 deletions packages/shared/src/utils/location/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,39 @@ export const getLocation = (location_list, value, type) => {
if (location_obj) return location_obj[type];
return '';
};

// eu countries to support
const eu_countries = [
matin-deriv marked this conversation as resolved.
Show resolved Hide resolved
'it',
'de',
'fr',
'lu',
'gr',
'mf',
'es',
'sk',
'lt',
'nl',
'at',
'bg',
'si',
'cy',
'be',
'ro',
'hr',
'pt',
'pl',
'lv',
'ee',
'cz',
'fi',
'hu',
'dk',
'se',
'ie',
'im',
'gb',
'mt',
];
// check if client is from EU
export const isEuCountry = country => eu_countries.includes(country);
salarhfz-fs marked this conversation as resolved.
Show resolved Hide resolved