diff --git a/src/botPage/view/View.js b/src/botPage/view/View.js index 4eaa2bdac1..f9722b37ce 100644 --- a/src/botPage/view/View.js +++ b/src/botPage/view/View.js @@ -31,7 +31,7 @@ import { import { translate } from '../../common/i18n'; import { isEuCountry, showHideEuElements, hasEuAccount } from '../../common/footer-checks'; import googleDrive from '../../common/integrations/GoogleDrive'; -import { getLanguage } from '../../common/lang'; +import { getLanguage, showBanner } from '../../common/lang'; import { observer as globalObserver } from '../../common/utils/observer'; import { getTokenList, @@ -48,7 +48,7 @@ import { getUnattachedMandatoryPairs, saveBeforeUnload, } from './blockly/utils'; -import MovingBanner from './react-components/MovingBanner'; +import { moveToDeriv } from '../../common/utils/utility'; let realityCheckTimeout; let chart; @@ -206,6 +206,7 @@ const updateTokenList = () => { // If logged out, determine EU based on IP. isEuCountry(api).then(isEu => showHideEuElements(isEu)); + showBanner(); $('.account-id') .removeAttr('value') .text(''); @@ -219,6 +220,7 @@ const updateTokenList = () => { const activeToken = getActiveToken(tokenList, getStorage(AppConstants.STORAGE_ACTIVE_TOKEN)); showHideEuElements(hasEuAccount(tokenList)); + showBanner(); updateLogo(activeToken.token); addBalanceForToken(activeToken.token); @@ -298,7 +300,6 @@ const checkForRequiredBlocks = () => { return true; }; - export default class View { constructor() { logHandler(); @@ -309,8 +310,11 @@ export default class View { if ( isLoggedin() && - (localStorage.getItem('landingCompany') === 'maltainvest' || - isOptionsBlocked(localStorage.getItem('residence'))) + isOptionsBlocked( + localStorage.getItem('residence') + // localStorage.getItem('landingCompany') === 'maltainvest' + // this condition is commented because the MF accounts should be redirected to deriv)) + ) ) { this.showHeader(getStorage('showHeader') !== 'false'); this.setElementActions(); @@ -325,6 +329,7 @@ export default class View { this.setElementActions(); initRealityCheck(() => $('#stopButton').triggerHandler('click')); applyToolboxPermissions(); + moveToDeriv(); renderReactComponents(); if (!getTokenList().length) updateLogo(); this.showHeader(getStorage('showHeader') !== 'false'); @@ -850,5 +855,4 @@ function renderReactComponents() { document.getElementById('errorArea').remove(); ReactDOM.render(, $('#summaryPanel')[0]); ReactDOM.render(, $('#logTable')[0]); - ReactDOM.render(, $('#moving-banner')[0]); } diff --git a/src/botPage/view/react-components/MovingBanner.js b/src/botPage/view/react-components/MovingBanner.js index 7781d3faa3..8bd2ed9596 100644 --- a/src/botPage/view/react-components/MovingBanner.js +++ b/src/botPage/view/react-components/MovingBanner.js @@ -1,82 +1,18 @@ import React from 'react'; -import { isEuCountry, isUKCountry } from '../../../common/footer-checks'; -import { getTokenList, get as getStorage } from '../../../common/utils/storageManager'; -import { AppConstants } from '../../../common/appId'; import { translate } from '../../../common/i18n'; -import { showBanner } from '../../../common/lang'; -const MovingBanner = ({ api }) => { - const [showMovingBanner, setshowMovingBanner] = React.useState(false); - const tokenList = getTokenList(); - - React.useEffect(() => { - checkForshowMovingBanner(); - }, []); - - const getActiveToken = activeToken => { - const activeTokenObject = tokenList.filter(tokenObject => tokenObject.token === activeToken); - return activeTokenObject.length ? activeTokenObject[0] : tokenList[0]; - }; - - const checkForshowMovingBanner = () => { - if (!tokenList.length) { - isEuUK(api, true); - return; - } - const landingCompanyName = tokenList.map(token => token.loginInfo.landing_company_name); - const activeToken = getActiveToken(tokenList, getStorage(AppConstants.STORAGE_ACTIVE_TOKEN)); - - if (landingCompanyName.length === 1 && landingCompanyName.includes('virtual')) { - isEuUK(false); - return; - } - if (landingCompanyName.includes('maltainvest') && landingCompanyName.includes('virtual')) { - if (landingCompanyName.length === 2) { - setshowMovingBanner(true); - return; - } - if ( - (landingCompanyName.includes('malta') || landingCompanyName.includes('iom')) && - activeToken.loginInfo.landing_company_name === 'maltainvest' - ) { - setshowMovingBanner(true); - return; - } - } - showBanner(); - }; - - const isEuUK = checkLoggedin => { - isEuCountry(api, checkLoggedin).then(isEu => { - if (isEu) { - setshowMovingBanner(true); - return; - } - isUKCountry(api, checkLoggedin).then(isUk => { - if (isUk) { - setshowMovingBanner(true); - return; - } - showBanner(); - }); - }); - }; - - return ( - showMovingBanner && - document - .getElementsByClassName('dbot-banner')[0] - .parentNode.removeChild(document.getElementsByClassName('dbot-banner')[0]) && ( -
-
- -

{translate('Binary.com is moving to Deriv')}

- - {translate('Trade on Deriv')} - -
- ) +const MovingBanner = () => + document + .getElementsByClassName('dbot-banner')[0] + .parentNode.removeChild(document.getElementsByClassName('dbot-banner')[0]) && ( +
+
+ +

{translate('Binary.com is moving to Deriv')}

+ + {translate('Trade on Deriv')} + +
); -}; export default MovingBanner; diff --git a/src/common/footer-checks.js b/src/common/footer-checks.js index f9eecf1238..f97e7c91eb 100644 --- a/src/common/footer-checks.js +++ b/src/common/footer-checks.js @@ -27,12 +27,12 @@ export const isEuLandingCompany = landing_company => /^(maltainvest|malta|iom)$/ export const hasEuAccount = token_list => token_list.some(token_obj => isEuLandingCompany(token_obj.loginInfo.landing_company_name)); -export const isEuCountry = async (api = generateLiveApiInstance(), checkLoggedin = true) => { +export const isEuCountry = async (api = generateLiveApiInstance()) => { const { website_status } = await api.send({ website_status: 1 }); let { clients_country } = website_status; - if (checkLoggedin && getTokenList().length) { - // isLoggedin + // isLoggedin + if (getTokenList().length) { clients_country = localStorage.getItem('residence'); } const { landing_company } = await api.send({ landing_company: clients_country }); @@ -47,17 +47,4 @@ export const isEuCountry = async (api = generateLiveApiInstance(), checkLoggedin return eu_excluded_regexp.test(clients_country); }; -export const isUKCountry = async (api = generateLiveApiInstance(), checkLoggedin = true) => { - const { website_status } = await api.send({ website_status: 1 }); - let { clients_country } = website_status; - if (checkLoggedin && getTokenList().length) { - // isLoggedin - clients_country = localStorage.getItem('residence'); - } - if (clients_country === 'gb') { - return true; - } - return false; -}; - /* eslint-enable */ diff --git a/src/common/utils/utility.js b/src/common/utils/utility.js new file mode 100644 index 0000000000..baa88bd955 --- /dev/null +++ b/src/common/utils/utility.js @@ -0,0 +1,66 @@ +import { generateLiveApiInstance } from '../../common/appId'; +import { getTokenList } from '../../common/utils/storageManager'; + +const euCountries = [ + 'it', + 'de', + 'fr', + 'lu', + 'gr', + 'es', + 'sk', + 'lt', + 'nl', + 'at', + 'bg', + 'si', + 'cy', + 'be', + 'ro', + 'hr', + 'pt', + 'pl', + 'lv', + 'ee', + 'cz', + 'fi', + 'hu', + 'dk', + 'se', + 'ie', + 'gb', + 'mt', +]; + +export const isEuCountry = country => euCountries.includes(country); + +export const isUKCountry = country => country === 'gb'; + +/* eslint-disable camelcase */ +export const moveToDeriv = async () => { + const api = generateLiveApiInstance(); + console.log('api:', api); + const { website_status } = await api.send({ website_status: 1 }); + const { clients_country } = website_status; + const tokenList = getTokenList(); + const landingCompanyName = tokenList.map(token => token.loginInfo.landing_company_name); + + if (!tokenList.length) { + if (isEuCountry(clients_country) || isUKCountry(clients_country)) { + window.location.replace('https://binary.com/move-to-deriv'); + } + } + + if ( + (landingCompanyName.length === 1 && + landingCompanyName.includes('virtual') && + (isEuCountry(clients_country) || + isUKCountry(clients_country) || + isEuCountry(localStorage.getItem('residence')) || isUKCountry(localStorage.getItem('residence')))) || + landingCompanyName.includes('maltainvest') || + landingCompanyName.includes('malta') || + landingCompanyName.includes('iom') + ) { + window.location.replace('https://binary.com/move-to-deriv'); + } +}; diff --git a/src/indexPage/index.js b/src/indexPage/index.js index c322f77f89..44da8fb6dd 100644 --- a/src/indexPage/index.js +++ b/src/indexPage/index.js @@ -7,13 +7,12 @@ import { oauthLogin } from '../common/appId'; import { isEuCountry, showHideEuElements } from '../common/footer-checks'; import GTM from '../common/gtm'; import { load as loadLang, showBanner } from '../common/lang'; +import { moveToDeriv } from '../common/utils/utility'; import { getTokenList } from '../common/utils/storageManager'; import { createUrl } from '../common/utils/tools'; import '../common/binary-ui/dropdown'; -import NotificationBanner from './react-components/NotificationBanner.jsx'; const renderElements = () => { - ReactDOM.render(, document.getElementById('notification-banner')); ReactDOM.render(, document.getElementById('binary-logo')); ReactDOM.render(