Skip to content
This repository was archived by the owner on Feb 22, 2024. It is now read-only.

Commit 377bb8e

Browse files
authored
Merge pull request #3482 from sara-fs/banner-redirection
Sara / Redirect users to deriv
2 parents 1ac0217 + b639a06 commit 377bb8e

File tree

7 files changed

+115
-178
lines changed

7 files changed

+115
-178
lines changed

src/botPage/view/View.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131
import { translate } from '../../common/i18n';
3232
import { isEuCountry, showHideEuElements, hasEuAccount } from '../../common/footer-checks';
3333
import googleDrive from '../../common/integrations/GoogleDrive';
34-
import { getLanguage } from '../../common/lang';
34+
import { getLanguage, showBanner } from '../../common/lang';
3535
import { observer as globalObserver } from '../../common/utils/observer';
3636
import {
3737
getTokenList,
@@ -48,7 +48,7 @@ import {
4848
getUnattachedMandatoryPairs,
4949
saveBeforeUnload,
5050
} from './blockly/utils';
51-
import MovingBanner from './react-components/MovingBanner';
51+
import { moveToDeriv } from '../../common/utils/utility';
5252

5353
let realityCheckTimeout;
5454
let chart;
@@ -206,6 +206,7 @@ const updateTokenList = () => {
206206

207207
// If logged out, determine EU based on IP.
208208
isEuCountry(api).then(isEu => showHideEuElements(isEu));
209+
showBanner();
209210
$('.account-id')
210211
.removeAttr('value')
211212
.text('');
@@ -219,6 +220,7 @@ const updateTokenList = () => {
219220

220221
const activeToken = getActiveToken(tokenList, getStorage(AppConstants.STORAGE_ACTIVE_TOKEN));
221222
showHideEuElements(hasEuAccount(tokenList));
223+
showBanner();
222224
updateLogo(activeToken.token);
223225
addBalanceForToken(activeToken.token);
224226

@@ -298,7 +300,6 @@ const checkForRequiredBlocks = () => {
298300

299301
return true;
300302
};
301-
302303
export default class View {
303304
constructor() {
304305
logHandler();
@@ -309,8 +310,11 @@ export default class View {
309310

310311
if (
311312
isLoggedin() &&
312-
(localStorage.getItem('landingCompany') === 'maltainvest' ||
313-
isOptionsBlocked(localStorage.getItem('residence')))
313+
isOptionsBlocked(
314+
localStorage.getItem('residence')
315+
// localStorage.getItem('landingCompany') === 'maltainvest'
316+
// this condition is commented because the MF accounts should be redirected to deriv))
317+
)
314318
) {
315319
this.showHeader(getStorage('showHeader') !== 'false');
316320
this.setElementActions();
@@ -325,6 +329,7 @@ export default class View {
325329
this.setElementActions();
326330
initRealityCheck(() => $('#stopButton').triggerHandler('click'));
327331
applyToolboxPermissions();
332+
moveToDeriv();
328333
renderReactComponents();
329334
if (!getTokenList().length) updateLogo();
330335
this.showHeader(getStorage('showHeader') !== 'false');
@@ -850,5 +855,4 @@ function renderReactComponents() {
850855
document.getElementById('errorArea').remove();
851856
ReactDOM.render(<TradeInfoPanel api={api} />, $('#summaryPanel')[0]);
852857
ReactDOM.render(<LogTable />, $('#logTable')[0]);
853-
ReactDOM.render(<MovingBanner api={api} />, $('#moving-banner')[0]);
854858
}
Lines changed: 12 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,18 @@
11
import React from 'react';
2-
import { isEuCountry, isUKCountry } from '../../../common/footer-checks';
3-
import { getTokenList, get as getStorage } from '../../../common/utils/storageManager';
4-
import { AppConstants } from '../../../common/appId';
52
import { translate } from '../../../common/i18n';
6-
import { showBanner } from '../../../common/lang';
73

8-
const MovingBanner = ({ api }) => {
9-
const [showMovingBanner, setshowMovingBanner] = React.useState(false);
10-
const tokenList = getTokenList();
11-
12-
React.useEffect(() => {
13-
checkForshowMovingBanner();
14-
}, []);
15-
16-
const getActiveToken = activeToken => {
17-
const activeTokenObject = tokenList.filter(tokenObject => tokenObject.token === activeToken);
18-
return activeTokenObject.length ? activeTokenObject[0] : tokenList[0];
19-
};
20-
21-
const checkForshowMovingBanner = () => {
22-
if (!tokenList.length) {
23-
isEuUK(api, true);
24-
return;
25-
}
26-
const landingCompanyName = tokenList.map(token => token.loginInfo.landing_company_name);
27-
const activeToken = getActiveToken(tokenList, getStorage(AppConstants.STORAGE_ACTIVE_TOKEN));
28-
29-
if (landingCompanyName.length === 1 && landingCompanyName.includes('virtual')) {
30-
isEuUK(false);
31-
return;
32-
}
33-
if (landingCompanyName.includes('maltainvest') && landingCompanyName.includes('virtual')) {
34-
if (landingCompanyName.length === 2) {
35-
setshowMovingBanner(true);
36-
return;
37-
}
38-
if (
39-
(landingCompanyName.includes('malta') || landingCompanyName.includes('iom')) &&
40-
activeToken.loginInfo.landing_company_name === 'maltainvest'
41-
) {
42-
setshowMovingBanner(true);
43-
return;
44-
}
45-
}
46-
showBanner();
47-
};
48-
49-
const isEuUK = checkLoggedin => {
50-
isEuCountry(api, checkLoggedin).then(isEu => {
51-
if (isEu) {
52-
setshowMovingBanner(true);
53-
return;
54-
}
55-
isUKCountry(api, checkLoggedin).then(isUk => {
56-
if (isUk) {
57-
setshowMovingBanner(true);
58-
return;
59-
}
60-
showBanner();
61-
});
62-
});
63-
};
64-
65-
return (
66-
showMovingBanner &&
67-
document
68-
.getElementsByClassName('dbot-banner')[0]
69-
.parentNode.removeChild(document.getElementsByClassName('dbot-banner')[0]) && (
70-
<div className="moving-banner">
71-
<div class="moving-banner__separator" />
72-
<img src={'image/moving-banner.svg'} />
73-
<p className="moving-banner__text">{translate('Binary.com is moving to Deriv')}</p>
74-
<a className="moving-banner__button" href="http://deriv.com/">
75-
{translate('Trade on Deriv')}
76-
</a>
77-
</div>
78-
)
4+
const MovingBanner = () =>
5+
document
6+
.getElementsByClassName('dbot-banner')[0]
7+
.parentNode.removeChild(document.getElementsByClassName('dbot-banner')[0]) && (
8+
<div className="moving-banner">
9+
<div className="moving-banner__separator" />
10+
<img src={'image/moving-banner.svg'} />
11+
<p className="moving-banner__text">{translate('Binary.com is moving to Deriv')}</p>
12+
<a className="moving-banner__button" href="http://deriv.com/">
13+
{translate('Trade on Deriv')}
14+
</a>
15+
</div>
7916
);
80-
};
8117

8218
export default MovingBanner;

src/common/footer-checks.js

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ export const isEuLandingCompany = landing_company => /^(maltainvest|malta|iom)$/
2727
export const hasEuAccount = token_list =>
2828
token_list.some(token_obj => isEuLandingCompany(token_obj.loginInfo.landing_company_name));
2929

30-
export const isEuCountry = async (api = generateLiveApiInstance(), checkLoggedin = true) => {
30+
export const isEuCountry = async (api = generateLiveApiInstance()) => {
3131
const { website_status } = await api.send({ website_status: 1 });
3232
let { clients_country } = website_status;
3333

34-
if (checkLoggedin && getTokenList().length) {
35-
// isLoggedin
34+
// isLoggedin
35+
if (getTokenList().length) {
3636
clients_country = localStorage.getItem('residence');
3737
}
3838
const { landing_company } = await api.send({ landing_company: clients_country });
@@ -47,17 +47,4 @@ export const isEuCountry = async (api = generateLiveApiInstance(), checkLoggedin
4747
return eu_excluded_regexp.test(clients_country);
4848
};
4949

50-
export const isUKCountry = async (api = generateLiveApiInstance(), checkLoggedin = true) => {
51-
const { website_status } = await api.send({ website_status: 1 });
52-
let { clients_country } = website_status;
53-
if (checkLoggedin && getTokenList().length) {
54-
// isLoggedin
55-
clients_country = localStorage.getItem('residence');
56-
}
57-
if (clients_country === 'gb') {
58-
return true;
59-
}
60-
return false;
61-
};
62-
6350
/* eslint-enable */

src/common/utils/utility.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { generateLiveApiInstance } from '../../common/appId';
2+
import { getTokenList } from '../../common/utils/storageManager';
3+
4+
const euCountries = [
5+
'it',
6+
'de',
7+
'fr',
8+
'lu',
9+
'gr',
10+
'es',
11+
'sk',
12+
'lt',
13+
'nl',
14+
'at',
15+
'bg',
16+
'si',
17+
'cy',
18+
'be',
19+
'ro',
20+
'hr',
21+
'pt',
22+
'pl',
23+
'lv',
24+
'ee',
25+
'cz',
26+
'fi',
27+
'hu',
28+
'dk',
29+
'se',
30+
'ie',
31+
'gb',
32+
'mt',
33+
];
34+
35+
export const isEuCountry = country => euCountries.includes(country);
36+
37+
export const isUKCountry = country => country === 'gb';
38+
39+
/* eslint-disable camelcase */
40+
export const moveToDeriv = async () => {
41+
const api = generateLiveApiInstance();
42+
console.log('api:', api);
43+
const { website_status } = await api.send({ website_status: 1 });
44+
const { clients_country } = website_status;
45+
const tokenList = getTokenList();
46+
const landingCompanyName = tokenList.map(token => token.loginInfo.landing_company_name);
47+
48+
if (!tokenList.length) {
49+
if (isEuCountry(clients_country) || isUKCountry(clients_country)) {
50+
window.location.replace('https://binary.com/move-to-deriv');
51+
}
52+
}
53+
54+
if (
55+
(landingCompanyName.length === 1 &&
56+
landingCompanyName.includes('virtual') &&
57+
(isEuCountry(clients_country) ||
58+
isUKCountry(clients_country) ||
59+
isEuCountry(localStorage.getItem('residence')) || isUKCountry(localStorage.getItem('residence')))) ||
60+
landingCompanyName.includes('maltainvest') ||
61+
landingCompanyName.includes('malta') ||
62+
landingCompanyName.includes('iom')
63+
) {
64+
window.location.replace('https://binary.com/move-to-deriv');
65+
}
66+
};

src/indexPage/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@ import { oauthLogin } from '../common/appId';
77
import { isEuCountry, showHideEuElements } from '../common/footer-checks';
88
import GTM from '../common/gtm';
99
import { load as loadLang, showBanner } from '../common/lang';
10+
import { moveToDeriv } from '../common/utils/utility';
1011
import { getTokenList } from '../common/utils/storageManager';
1112
import { createUrl } from '../common/utils/tools';
1213
import '../common/binary-ui/dropdown';
13-
import NotificationBanner from './react-components/NotificationBanner.jsx';
1414

1515
const renderElements = () => {
16-
ReactDOM.render(<NotificationBanner />, document.getElementById('notification-banner'));
1716
ReactDOM.render(<Logo />, document.getElementById('binary-logo'));
1817
ReactDOM.render(<Footer />, document.getElementById('footer'));
1918
isEuCountry().then(isEu => showHideEuElements(isEu));
@@ -24,6 +23,7 @@ const renderElements = () => {
2423

2524
const loginCheck = () => {
2625
if (endpoint()) return;
26+
moveToDeriv();
2727
if (getTokenList().length) {
2828
window.location.pathname = `${window.location.pathname.replace(/\/+$/, '')}/bot.html`;
2929
} else {

src/indexPage/react-components/NotificationBanner.jsx

Lines changed: 17 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,37 @@
11
import React from 'react';
22
import { translate } from '../../common/i18n';
3-
import { isEuCountry, isUKCountry } from '../../common/footer-checks';
4-
import { getTokenList, get as getStorage } from '../../common/utils/storageManager';
5-
import { AppConstants } from '../../common/appId';
3+
import { getTokenList } from '../../common/utils/storageManager';
4+
import { isEuCountry, isUKCountry } from '../../common/utils/utility';
5+
import { generateLiveApiInstance } from '../../common/appId';
66

7-
const NotificationBanner = ({ api }) => {
7+
const NotificationBanner = () => {
88
const [showBanner, setShowBanner] = React.useState(false);
99
const tokenList = getTokenList();
1010

1111
React.useEffect(() => {
12-
checkForShowBanner();
12+
checkForShowBanner().then(show => {
13+
if(show){
14+
setShowBanner(true);
15+
}
16+
});
1317
}, []);
1418

15-
const getActiveToken = activeToken => {
16-
const activeTokenObject = tokenList.filter(tokenObject => tokenObject.token === activeToken);
17-
return activeTokenObject.length ? activeTokenObject[0] : tokenList[0];
18-
};
19+
const checkForShowBanner = async () => {
20+
const api = generateLiveApiInstance();
21+
const { website_status } = await api.send({ website_status: 1 });
22+
const { clients_country } = website_status;
1923

20-
const checkForShowBanner = () => {
2124
if (!tokenList.length) {
22-
isEuUK(api, true);
23-
return;
24-
}
25-
const landingCompanyName = tokenList.map(token => token.loginInfo.landing_company_name);
26-
const activeToken = getActiveToken(tokenList, getStorage(AppConstants.STORAGE_ACTIVE_TOKEN));
27-
28-
if (landingCompanyName.length === 1 && landingCompanyName.includes('virtual')) {
29-
isEuUK(false);
30-
return;
31-
}
32-
if (landingCompanyName.includes('maltainvest') && landingCompanyName.includes('virtual')) {
33-
if (landingCompanyName.length === 2) {
34-
setShowBanner(true);
35-
return;
36-
}
37-
if (
38-
(landingCompanyName.includes('malta') || landingCompanyName.includes('iom')) &&
39-
activeToken.loginInfo.landing_company_name === 'maltainvest'
40-
) {
41-
setShowBanner(true);
25+
if(isEuCountry(clients_country) || isUKCountry (clients_country)){
26+
return true;
4227
}
4328
}
44-
};
45-
46-
const isEuUK = checkLoggedin => {
47-
isEuCountry(api, checkLoggedin).then(isEu => {
48-
if (isEu) {
49-
setShowBanner(true);
50-
return;
51-
}
52-
isUKCountry(api, checkLoggedin).then(isUk => {
53-
setShowBanner(isUk);
54-
});
55-
});
29+
return false;
5630
};
5731

5832
return (
5933
showBanner && (
60-
<div className="notification-banner notification-banner-welcome">
34+
<div className="notification-banner">
6135
<img src={'image/notification-banner-icon-left.svg'} />
6236
<div className="notification-banner__orange-hexagon"></div>
6337
<div className="notification-banner__content">

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy