From 67dd686c7b56298ffad4a66fbe6aa0ecde3c61a6 Mon Sep 17 00:00:00 2001 From: Salar Hafezi Date: Tue, 8 Mar 2022 12:00:52 +0330 Subject: [PATCH 01/10] Add helper function for EU countries --- .../shared/src/utils/location/location.js | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) 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); From d2cf6822fa743ede01a8d6a3c32ab239ba2b3321 Mon Sep 17 00:00:00 2001 From: Salar Hafezi Date: Tue, 8 Mar 2022 12:03:19 +0330 Subject: [PATCH 02/10] Show digital options banner to VRTC-only EU clients --- packages/bot-web-ui/src/stores/app-store.js | 8 ++++++-- .../src/utils/digital-options/digital-options.js | 10 ++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/bot-web-ui/src/stores/app-store.js b/packages/bot-web-ui/src/stores/app-store.js index 210e2ec5de01..c33f816b1868 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'; @@ -201,7 +201,11 @@ export default class AppStore { }; showDigitalOptionsMaltainvestError = (client, common) => { - if (client.has_maltainvest_account || client.is_options_blocked) { + if ( + client.has_maltainvest_account || + isEuResidenceWithOnlyVRTC(client.residence, 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/shared/src/utils/digital-options/digital-options.js b/packages/shared/src/utils/digital-options/digital-options.js index 899eb77ea634..c44223d5bdd6 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,11 @@ export const showDigitalOptionsUnavailableError = (showError, message) => { should_clear_error_on_click: true, }); }; + +export const isEuResidenceWithOnlyVRTC = (residence, accounts) => { + return ( + isEuCountry(residence) && + accounts?.length === 1 && + accounts.every(acc => acc.landing_company_shortcode === 'virtual') + ); +}; From 397855aaf020f62cd7f6c2c7fae688578144a3c6 Mon Sep 17 00:00:00 2001 From: Salar Hafezi Date: Tue, 8 Mar 2022 12:46:49 +0330 Subject: [PATCH 03/10] Add comment to remove duplicate code --- packages/cashier/src/_common/utility.js | 2 ++ packages/core/src/_common/utility.js | 2 ++ 2 files changed, 4 insertions(+) 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 From 64e921f1a572b0ffa4b646577163bb59f7d9c70b Mon Sep 17 00:00:00 2001 From: Salar Hafezi Date: Wed, 9 Mar 2022 10:12:53 +0330 Subject: [PATCH 04/10] Fix: apply more compliance conditions --- packages/bot-web-ui/src/stores/app-store.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/bot-web-ui/src/stores/app-store.js b/packages/bot-web-ui/src/stores/app-store.js index c33f816b1868..26d9b5572bd6 100644 --- a/packages/bot-web-ui/src/stores/app-store.js +++ b/packages/bot-web-ui/src/stores/app-store.js @@ -141,7 +141,12 @@ 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.residence, 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.' @@ -202,6 +207,7 @@ export default class AppStore { showDigitalOptionsMaltainvestError = (client, common) => { if ( + (!client.is_logged_in && client.is_eu_country) || client.has_maltainvest_account || isEuResidenceWithOnlyVRTC(client.residence, client.active_accounts) || client.is_options_blocked From 7ce417a887eccce6ffc83de8be8c5466a0fb80d1 Mon Sep 17 00:00:00 2001 From: Salar Hafezi Date: Wed, 9 Mar 2022 12:31:08 +0330 Subject: [PATCH 05/10] Fix issue for EU residence --- packages/bot-web-ui/src/stores/app-store.js | 28 +++++++++++++++++++ .../utils/digital-options/digital-options.js | 5 ++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/packages/bot-web-ui/src/stores/app-store.js b/packages/bot-web-ui/src/stores/app-store.js index 26d9b5572bd6..5bc4f579e85b 100644 --- a/packages/bot-web-ui/src/stores/app-store.js +++ b/packages/bot-web-ui/src/stores/app-store.js @@ -26,6 +26,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 +54,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); @@ -159,6 +163,30 @@ export default class AppStore { ); } + 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.' + ), + title: localize('DBot is not available for this account'), + link: localize('Go to DMT5 dashboard'), + }); + } + } + ); + } + setDBotEngineStores() { // DO NOT pass the rootstore in, if you need a prop define it in dbot-skeleton-store ans pass it through. const { diff --git a/packages/shared/src/utils/digital-options/digital-options.js b/packages/shared/src/utils/digital-options/digital-options.js index c44223d5bdd6..5c52c39aec0d 100644 --- a/packages/shared/src/utils/digital-options/digital-options.js +++ b/packages/shared/src/utils/digital-options/digital-options.js @@ -13,10 +13,9 @@ export const showDigitalOptionsUnavailableError = (showError, message) => { }); }; -export const isEuResidenceWithOnlyVRTC = (residence, accounts) => { +export const isEuResidenceWithOnlyVRTC = (accounts) => { return ( - isEuCountry(residence) && accounts?.length === 1 && - accounts.every(acc => acc.landing_company_shortcode === 'virtual') + accounts.every(acc => isEuCountry(acc.residence) && acc.landing_company_shortcode === 'virtual') ); }; From a7be878ad2623746dae58dd04e714e8f4205b711 Mon Sep 17 00:00:00 2001 From: Salar Hafezi Date: Wed, 9 Mar 2022 12:31:47 +0330 Subject: [PATCH 06/10] Apply prettier --- packages/shared/src/utils/digital-options/digital-options.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/shared/src/utils/digital-options/digital-options.js b/packages/shared/src/utils/digital-options/digital-options.js index 5c52c39aec0d..671fb13c5ba0 100644 --- a/packages/shared/src/utils/digital-options/digital-options.js +++ b/packages/shared/src/utils/digital-options/digital-options.js @@ -13,7 +13,7 @@ export const showDigitalOptionsUnavailableError = (showError, message) => { }); }; -export const isEuResidenceWithOnlyVRTC = (accounts) => { +export const isEuResidenceWithOnlyVRTC = accounts => { return ( accounts?.length === 1 && accounts.every(acc => isEuCountry(acc.residence) && acc.landing_company_shortcode === 'virtual') From 43a8ef8dbe3fe532ea14241791ad7feac21286cd Mon Sep 17 00:00:00 2001 From: Salar Hafezi Date: Thu, 10 Mar 2022 09:33:30 +0330 Subject: [PATCH 07/10] Fix mobx issue for residence --- packages/bot-web-ui/src/app/app.jsx | 2 +- packages/bot-web-ui/src/stores/app-store.js | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) 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 5bc4f579e85b..812231821a30 100644 --- a/packages/bot-web-ui/src/stores/app-store.js +++ b/packages/bot-web-ui/src/stores/app-store.js @@ -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(); @@ -116,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; @@ -148,7 +146,7 @@ export default class AppStore { if ( (!client.is_logged_in && client.is_eu_country) || client.has_maltainvest_account || - isEuResidenceWithOnlyVRTC(client.residence, client.active_accounts) || + isEuResidenceWithOnlyVRTC(client.active_accounts) || client.is_options_blocked ) { showDigitalOptionsUnavailableError(common.showError, { @@ -237,7 +235,7 @@ export default class AppStore { if ( (!client.is_logged_in && client.is_eu_country) || client.has_maltainvest_account || - isEuResidenceWithOnlyVRTC(client.residence, client.active_accounts) || + isEuResidenceWithOnlyVRTC(client.active_accounts) || client.is_options_blocked ) { showDigitalOptionsUnavailableError(common.showError, { From fb39aa4707c035f796bc8c472e77fd28d9c70915 Mon Sep 17 00:00:00 2001 From: Salar Hafezi Date: Thu, 10 Mar 2022 10:10:39 +0330 Subject: [PATCH 08/10] Fix: prevent calls on undefined --- .../Binary/Trade Definition/trade_definition_multiplier.js | 2 +- packages/bot-web-ui/src/stores/app-store.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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/stores/app-store.js b/packages/bot-web-ui/src/stores/app-store.js index 812231821a30..3deee0296a8b 100644 --- a/packages/bot-web-ui/src/stores/app-store.js +++ b/packages/bot-web-ui/src/stores/app-store.js @@ -227,7 +227,7 @@ export default class AppStore { const is_click_outside_blockly = !path.some(el => el.classList && el.classList.contains('injectionDiv')); if (is_click_outside_blockly) { - Blockly.hideChaff(/* allowToolbox */ false); + Blockly?.hideChaff(/* allowToolbox */ false); } }; From cc9d894c5ec7cb10cc5212e822df663d1f3d27ca Mon Sep 17 00:00:00 2001 From: Salar Hafezi Date: Thu, 10 Mar 2022 10:45:58 +0330 Subject: [PATCH 09/10] Fix: check for blockly div first --- packages/bot-web-ui/src/stores/app-store.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/bot-web-ui/src/stores/app-store.js b/packages/bot-web-ui/src/stores/app-store.js index 3deee0296a8b..546298c8758e 100644 --- a/packages/bot-web-ui/src/stores/app-store.js +++ b/packages/bot-web-ui/src/stores/app-store.js @@ -223,11 +223,13 @@ 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 (is_click_outside_blockly) { - Blockly?.hideChaff(/* allowToolbox */ false); + 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); + } } }; From 63c1ef12b3c63ea74d5f79ec1e1ff62c33108b4d Mon Sep 17 00:00:00 2001 From: Salar Hafezi Date: Thu, 10 Mar 2022 10:47:43 +0330 Subject: [PATCH 10/10] Apply prettier --- packages/bot-web-ui/src/stores/app-store.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/bot-web-ui/src/stores/app-store.js b/packages/bot-web-ui/src/stores/app-store.js index 546298c8758e..1016819cc827 100644 --- a/packages/bot-web-ui/src/stores/app-store.js +++ b/packages/bot-web-ui/src/stores/app-store.js @@ -226,7 +226,7 @@ export default class AppStore { 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); }