diff --git a/packages/bot-skeleton/src/scratch/blocks/Binary/Trade Definition/trade_definition_multiplier.js b/packages/bot-skeleton/src/scratch/blocks/Binary/Trade Definition/trade_definition_multiplier.js index 8d7bde79eecb..2f95f7ea648e 100644 --- a/packages/bot-skeleton/src/scratch/blocks/Binary/Trade Definition/trade_definition_multiplier.js +++ b/packages/bot-skeleton/src/scratch/blocks/Binary/Trade Definition/trade_definition_multiplier.js @@ -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(), }); } diff --git a/packages/bot-web-ui/src/app/app.jsx b/packages/bot-web-ui/src/app/app.jsx index e0c3e9cda30b..e7cb64512773 100644 --- a/packages/bot-web-ui/src/app/app.jsx +++ b/packages/bot-web-ui/src/app/app.jsx @@ -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); diff --git a/packages/bot-web-ui/src/stores/app-store.js b/packages/bot-web-ui/src/stores/app-store.js index 210e2ec5de01..1016819cc827 100644 --- a/packages/bot-web-ui/src/stores/app-store.js +++ b/packages/bot-web-ui/src/stores/app-store.js @@ -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'; @@ -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(); @@ -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); @@ -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); @@ -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; @@ -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) || + 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.' @@ -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.' diff --git a/packages/cashier/src/_common/utility.js b/packages/cashier/src/_common/utility.js index dde91b5c4fe2..4ce3d73bd19c 100644 --- a/packages/cashier/src/_common/utility.js +++ b/packages/cashier/src/_common/utility.js @@ -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', @@ -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); diff --git a/packages/core/src/_common/utility.js b/packages/core/src/_common/utility.js index 5a76dfab5750..93cb341b62eb 100644 --- a/packages/core/src/_common/utility.js +++ b/packages/core/src/_common/utility.js @@ -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', @@ -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 diff --git a/packages/shared/src/utils/digital-options/digital-options.js b/packages/shared/src/utils/digital-options/digital-options.js index 899eb77ea634..671fb13c5ba0 100644 --- a/packages/shared/src/utils/digital-options/digital-options.js +++ b/packages/shared/src/utils/digital-options/digital-options.js @@ -1,3 +1,5 @@ +import { isEuCountry } from '../location'; + export const showDigitalOptionsUnavailableError = (showError, message) => { const { title, text, link } = message; showError({ @@ -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') + ); +}; diff --git a/packages/shared/src/utils/location/location.js b/packages/shared/src/utils/location/location.js index 49c175693984..100a521d70eb 100644 --- a/packages/shared/src/utils/location/location.js +++ b/packages/shared/src/utils/location/location.js @@ -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 = [ + '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);