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

Commit 1450b42

Browse files
show banner for uk with mf/vitual account
1 parent dd4fac4 commit 1450b42

File tree

2 files changed

+89
-51
lines changed

2 files changed

+89
-51
lines changed

src/banners/banners.es6

Lines changed: 34 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,23 @@ import $banner from "text!./banners.html";
22
import liveapi from "../websockets/binary_websockets";
33
import "css!banners/banners.css";
44

5-
export const isEuCountry = (clients_country, landing_company) => {
6-
const eu_shortcode_regex = new RegExp("^(maltainvest|malta|iom)$");
7-
const eu_excluded_regex = new RegExp("^mt$");
8-
const financial_shortcode =
9-
(landing_company && landing_company.financial_company)
10-
? landing_company.financial_company.shortcode
11-
: "";
12-
const gaming_shortcode =
13-
(landing_company && landing_company.gaming_company)
14-
? landing_company.gaming_company.shortcode
15-
: "";
165

17-
return financial_shortcode || gaming_shortcode
18-
? eu_shortcode_regex.test(financial_shortcode) ||
19-
eu_shortcode_regex.test(gaming_shortcode)
20-
: eu_excluded_regex.test(clients_country);
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;
2120
};
2221

23-
export const isMFCountry = (landing_company) => {
24-
const mf_shortcode_regex = new RegExp("^(maltainvest)$");
25-
const gaming_shortcode =
26-
(landing_company && landing_company.gaming_company)
27-
? landing_company.gaming_company.shortcode
28-
: "";
29-
30-
return gaming_shortcode
31-
? mf_shortcode_regex.test(gaming_shortcode)
32-
: false;
33-
}
34-
3522
export const init = () => {
3623
const banner = $($banner).i18n();
3724
const nav = $("body").find("nav");
@@ -43,36 +30,33 @@ export const init = () => {
4330

4431
const showBanner = () => {
4532
const banner = document.getElementById("close_banner_container");
46-
if (local_storage.get("oauth")) {
47-
liveapi.cached.authorize().then(() => {
48-
const current_loginId = local_storage.get('authorize').loginid;
49-
const getLoginId = loginids().filter( item => item.id === current_loginId);
50-
const is_mf_account = getLoginId[0].is_mf;
51-
const is_virtual = getLoginId[0].is_virtual;
52-
const country = local_storage.get("authorize").country;
53-
liveapi.send({ landing_company: country }).then((data) => {
54-
const landing_company = data.landing_company;
55-
if (isEuCountry(country, landing_company) &&
56-
(is_mf_account || (isMFCountry(landing_company) && is_virtual))) {
57-
banner.classList.remove("invisible");
58-
} else {
59-
banner.classList.add("invisible");
60-
}
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+
});
6147
});
62-
});
63-
} else {
64-
liveapi.send({ website_status: 1 }).then((data) => {
65-
const country = data.website_status.clients_country;
66-
liveapi.send({ landing_company: country }).then((response) => {
48+
} else {
49+
liveapi.send({ landing_company: ip_country }).then((response) => {
6750
const landing_company = response.landing_company;
68-
if (isEuCountry(country, landing_company)) {
51+
if (isEuCountry(ip_country, landing_company)) {
6952
banner.classList.remove("invisible");
7053
} else {
7154
banner.classList.add("invisible");
7255
}
7356
});
74-
});
75-
}
57+
}
58+
})
59+
7660
};
7761

7862
liveapi.events.on("login", () => {
@@ -87,5 +71,4 @@ liveapi.events.on("switch_account", () => {
8771

8872
export default {
8973
init,
90-
isEuCountry
9174
};

src/common/util.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,3 +525,58 @@ function getDerivUrl(page) {
525525

526526
return deriv_url;
527527
}
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+
];

0 commit comments

Comments
 (0)