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

Commit cab88d2

Browse files
authored
Merge pull request #1569 from mahdiyeh-fs/add_close_banner
Mahdiyeh/Feature: add close banner to EU and UK clients
2 parents 39055e6 + 1450b42 commit cab88d2

File tree

9 files changed

+247
-1
lines changed

9 files changed

+247
-1
lines changed

src/banners/banners.es6

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import $banner from "text!./banners.html";
2+
import liveapi from "../websockets/binary_websockets";
3+
import "css!banners/banners.css";
4+
5+
6+
const shouldShowBanner = (auth) => {
7+
const has_mf = auth.account_list.filter( item => item.landing_company_name === 'maltainvest').length;
8+
const has_mlt = auth.account_list.filter( item => item.landing_company_name === 'malta').length;
9+
const has_iom = auth.account_list.filter( item => item.landing_company_name === 'iom').length;
10+
const current_loginId = local_storage.get('authorize').loginid;
11+
const getLoginId = loginids().filter( item => item.id === current_loginId);
12+
const is_mf = getLoginId[0].is_mf;
13+
const is_virtual = getLoginId[0].is_virtual;
14+
if (is_mf) {
15+
return true;
16+
} else if (is_virtual && has_mf && !has_iom && !has_mlt) {
17+
return true;
18+
}
19+
return false;
20+
};
21+
22+
export const init = () => {
23+
const banner = $($banner).i18n();
24+
const nav = $("body").find("nav");
25+
nav.after(banner);
26+
const go_to_deriv_el = document.getElementById("close_banner_btn_iom");
27+
go_to_deriv_el.href = getDerivUrl("");
28+
showBanner();
29+
};
30+
31+
const showBanner = () => {
32+
const banner = document.getElementById("close_banner_container");
33+
liveapi.cached.send({ website_status: 1 }).then((status) => {
34+
const ip_country = status.website_status.clients_country;
35+
if (local_storage.get("oauth")) {
36+
liveapi.cached.authorize().then((res) => {
37+
const country = local_storage.get("authorize").country;
38+
liveapi.send({ landing_company: country }).then((data) => {
39+
const landing_company = data.landing_company;
40+
if ((isEuCountry(country, landing_company) && shouldShowBanner(res.authorize))
41+
|| (loginids().length == 1 && isEuCountrySelected(ip_country))) {
42+
banner.classList.remove("invisible");
43+
} else {
44+
banner.classList.add("invisible");
45+
}
46+
});
47+
});
48+
} else {
49+
liveapi.send({ landing_company: ip_country }).then((response) => {
50+
const landing_company = response.landing_company;
51+
if (isEuCountry(ip_country, landing_company)) {
52+
banner.classList.remove("invisible");
53+
} else {
54+
banner.classList.add("invisible");
55+
}
56+
});
57+
}
58+
})
59+
60+
};
61+
62+
liveapi.events.on("login", () => {
63+
showBanner();
64+
});
65+
liveapi.events.on("logout", () => {
66+
showBanner();
67+
});
68+
liveapi.events.on("switch_account", () => {
69+
showBanner()
70+
});
71+
72+
export default {
73+
init,
74+
};

src/banners/banners.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<div id='close_banner_container' class='container invisible'>
2+
<div class='close_banner_text'>
3+
<img class='close_banner_img' src="images/banner/icon_left.png"/>
4+
<div class='close_banner_text_wrapper'>
5+
<h3>Binary.com is moving to Deriv on 30 November</h3>
6+
<p>Start using Deriv with your Binary.com email and password.</p>
7+
</div>
8+
</div>
9+
<div class='close_banner_btn'>
10+
<a id='close_banner_btn_iom' target="_blank" href="#">Trade on Deriv</a>
11+
</div>
12+
</div>

src/banners/banners.scss

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#close_banner_container {
2+
display: flex;
3+
max-width: 960px;
4+
justify-content: space-between;
5+
position: relative;
6+
background-color: rgb(242, 242, 242);
7+
border-radius: 0px;
8+
padding-right: 0;
9+
padding-left: 0;
10+
margin: 30px auto;
11+
12+
.close_banner {
13+
display: flex;
14+
position: relative;
15+
16+
&_text {
17+
display: flex;
18+
justify-content: center;
19+
gap: 10px;
20+
21+
&_wrapper {
22+
display: flex;
23+
flex-direction: column;
24+
justify-content: center;
25+
}
26+
h3 {
27+
flex: none;
28+
font-size: 16px;
29+
margin-top: 8px;
30+
margin-bottom: 8px;
31+
font-weight: 700;
32+
line-height: 1;
33+
color: #000;
34+
}
35+
p {
36+
margin-top: 8px;
37+
margin-bottom: 8px;
38+
font-size: 16px;
39+
font-weight: normal;
40+
color: #000;
41+
}
42+
}
43+
&_btn {
44+
cursor: pointer;
45+
display: flex;
46+
align-items: center;
47+
justify-content: center;
48+
align-self: center;
49+
margin: 0 40px 0 auto;
50+
padding: 5px 16px;
51+
line-height: 32px;
52+
color: #fff;
53+
border-radius: 4px;
54+
background-color:#008000;
55+
font-weight: normal;
56+
text-align: center;
57+
a {
58+
display: flex;
59+
align-items: center;
60+
justify-content: center;
61+
color: #fff;
62+
text-decoration: none;
63+
font-weight: 400 ;
64+
}
65+
}
66+
}
67+
}

src/common/util.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ function loginids() {
384384
is_mlt: /MLT/gi.test(parts.loginid),
385385
is_mx: /MX/gi.test(parts.loginid),
386386
is_cr: /CR/gi.test(parts.loginid),
387+
is_virtual: /VRTC/gi.test(parts.loginid),
387388
};
388389
});
389390
}
@@ -515,3 +516,67 @@ function getBinaryUrl(page) {
515516

516517
return binary_url;
517518
}
519+
520+
function getDerivUrl(page) {
521+
var hostname = new URL(window.location.href).hostname;
522+
var lang = (local_storage.get('i18n') || {value: 'en'}).value;
523+
var domain = hostname.includes('binary.me') ? '.me' : '.com';
524+
var deriv_url = 'https://deriv' + domain + '/' + lang + '/' + page;
525+
526+
return deriv_url;
527+
}
528+
529+
function isEuCountry(clients_country, landing_company) {
530+
var eu_shortcode_regex = new RegExp("^(maltainvest|malta|iom)$");
531+
var eu_excluded_regex = new RegExp("^mt$");
532+
var financial_shortcode =
533+
(landing_company && landing_company.financial_company)
534+
? landing_company.financial_company.shortcode
535+
: "";
536+
var gaming_shortcode =
537+
(landing_company && landing_company.gaming_company)
538+
? landing_company.gaming_company.shortcode
539+
: "";
540+
541+
return financial_shortcode || gaming_shortcode
542+
? eu_shortcode_regex.test(financial_shortcode) ||
543+
eu_shortcode_regex.test(gaming_shortcode)
544+
: eu_excluded_regex.test(clients_country);
545+
}
546+
547+
function isEuCountrySelected(selected_country) {
548+
return eu_countries.includes(selected_country)
549+
}
550+
551+
var eu_countries = [
552+
'it',
553+
'de',
554+
'fr',
555+
'lu',
556+
'gr',
557+
'mf',
558+
'es',
559+
'sk',
560+
'lt',
561+
'nl',
562+
'at',
563+
'bg',
564+
'si',
565+
'cy',
566+
'be',
567+
'ro',
568+
'hr',
569+
'pt',
570+
'pl',
571+
'lv',
572+
'ee',
573+
'cz',
574+
'fi',
575+
'hu',
576+
'dk',
577+
'se',
578+
'ie',
579+
'im',
580+
'gb',
581+
'mt',
582+
];

src/images/banner/icon_left.png

3.4 KB
Loading

src/images/banner/orange-bg.png

668 Bytes
Loading

src/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
<link rel="stylesheet" type="text/css" href="v<version>/lib/@binary-com/binary-style/binary.css">
3838
<link rel="stylesheet" type="text/css" href="v<version>/index.css">
39+
<link rel="stylesheet" type="text/css" href="v<version>/banners/banners.css">
3940

4041
</head>
4142

@@ -78,6 +79,18 @@
7879
</div>
7980
</div>
8081
</div>
82+
<div id='close_banner_container' class='container invisible'>
83+
<div class='close_banner_text'>
84+
<img class='close_banner_img' src="v<version>/images/banner/icon_left.png"/>
85+
<div class='close_banner_text_wrapper'>
86+
<h3>Binary.com is moving to Deriv on 30 November</h3>
87+
<p>Start using Deriv with your Binary.com email and password.</p>
88+
</div>
89+
</div>
90+
<div class='close_banner_btn'>
91+
<a id='close_banner_btn_iom' target="_blank" href="#">Trade on Deriv</a>
92+
</div>
93+
</div>
8194
<div id="content">
8295
<div class="container">
8396
<div class="text">

src/index.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ function processFooter(selected_language_name) {
225225
var isEu = isEuCountry(data.landing_company);
226226
var FOOTER_TEXT = isEu ? FOOTER_TEXT_EU : FOOTER_TEXT_NON_EU;
227227

228+
showBanner(isEu);
228229
isEu ? footer_eu_el.classList.add('data-show') : footer_non_eu_el.classList.add('data-show');
229230

230231
for (var key in FOOTER_TEXT) {
@@ -259,4 +260,14 @@ function processFooter(selected_language_name) {
259260
}
260261
}
261262
})
262-
}
263+
}
264+
265+
function showBanner(isEu){
266+
var go_to_deriv_el = document.getElementById("close_banner_btn_iom");
267+
go_to_deriv_el.href = getDerivUrl("");
268+
if (isEu) {
269+
document.getElementById('close_banner_container').classList.remove('invisible')
270+
} else {
271+
document.getElementById('close_banner_container').classList.add('invisible')
272+
}
273+
}

src/main.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,10 @@ require(["jquery", "text!i18n/" + i18n_name + ".json"], function($, lang_json) {
293293
$(".sk-spinner-container").parent().hide();
294294
$("body > .footer").show();
295295
});
296+
297+
require(["banners/banners"], function(banner) {
298+
banner.init();
299+
});
296300
});
297301

298302
/*Trigger T&C check, self-exclusion, reality check, csr_tax_information check*/

0 commit comments

Comments
 (0)