forked from binary-com/binary-static
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.js
More file actions
143 lines (126 loc) · 5.64 KB
/
client.js
File metadata and controls
143 lines (126 loc) · 5.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
const BinarySocket = require('./socket');
const RealityCheckData = require('../pages/user/reality_check/reality_check.data');
const ClientBase = require('../../_common/base/client_base');
const GTM = require('../../_common/base/gtm');
const SocketCache = require('../../_common/base/socket_cache');
const getElementById = require('../../_common/common_functions').getElementById;
const removeCookies = require('../../_common/storage').removeCookies;
const urlFor = require('../../_common/url').urlFor;
const applyToAllElements = require('../../_common/utility').applyToAllElements;
const getPropertyValue = require('../../_common/utility').getPropertyValue;
const Client = (() => {
const processNewAccount = (options) => {
if (ClientBase.setNewAccount(options)) {
window.location.href = options.redirect_url || defaultRedirectUrl(); // need to redirect not using pjax
}
};
const activateByClientType = (section_id) => {
const topbar_class = getElementById('topbar').classList;
const el_section = section_id ? getElementById(section_id) : document.body;
const primary_bg_color_dark = 'primary-bg-color-dark';
const secondary_bg_color = 'secondary-bg-color';
if (ClientBase.isLoggedIn()) {
BinarySocket.wait('authorize', 'website_status', 'get_account_status').then(() => {
const client_logged_in = getElementById('client-logged-in');
client_logged_in.classList.add('gr-centered');
applyToAllElements('.client_logged_in', (el) => {
el.setVisibility(1);
});
if (ClientBase.get('is_virtual')) {
applyToAllElements('.client_virtual', (el) => { el.setVisibility(1); }, '', el_section);
topbar_class.add(secondary_bg_color);
topbar_class.remove(primary_bg_color_dark);
} else {
applyToAllElements('.client_real', (el) => {
el.setVisibility(1);
}, '', el_section);
topbar_class.add(primary_bg_color_dark);
topbar_class.remove(secondary_bg_color);
}
});
} else {
applyToAllElements('.client_logged_in', (el) => {
el.setVisibility(0);
}, '', el_section);
applyToAllElements('#client-logged-in', (el) => {
el.setVisibility(0);
}, '', el_section);
getElementById('topbar-msg').setVisibility(0);
getElementById('menu-top').classList.remove('smaller-font', 'top-nav-menu');
applyToAllElements('.client_logged_out', (el) => {
el.setVisibility(1);
}, '', el_section);
topbar_class.add(primary_bg_color_dark);
topbar_class.remove(secondary_bg_color);
}
};
const sendLogoutRequest = (show_login_page, redirect_to) => {
if (show_login_page) {
sessionStorage.setItem('showLoginPage', 1);
}
BinarySocket.send({ logout: '1', passthrough: { redirect_to } }).then((response) => {
if (response.logout === 1) {
GTM.pushDataLayer({ event: 'log_out' });
}
});
};
const doLogout = (response) => {
if (response.logout !== 1) return;
removeCookies('login', 'loginid', 'loginid_list', 'email', 'residence', 'settings'); // backward compatibility
removeCookies('reality_check', 'affiliate_token', 'affiliate_tracking', 'onfido_token');
// clear elev.io session storage
sessionStorage.removeItem('_elevaddon-6app');
sessionStorage.removeItem('_elevaddon-6create');
ClientBase.clearAllAccounts();
ClientBase.set('loginid', '');
SocketCache.clear();
RealityCheckData.clear();
const redirect_to = getPropertyValue(response, ['echo_req', 'passthrough', 'redirect_to']);
if (redirect_to) {
window.location.href = redirect_to;
} else {
window.location.reload();
}
};
const getUpgradeInfo = () => {
const upgrade_info = ClientBase.getBasicUpgradeInfo();
let upgrade_links = {};
if (upgrade_info.can_upgrade_to.length) {
const upgrade_link_map = {
realws : ['svg', 'iom', 'malta'],
maltainvestws: ['maltainvest'],
};
Object.keys(upgrade_link_map).forEach(link => {
const res = upgrade_link_map[link].find(lc => upgrade_info.can_upgrade_to.includes(lc));
if (res) {
upgrade_links = {
...upgrade_links,
[res]: link,
};
}
});
}
let transformed_upgrade_links = {};
Object.keys(upgrade_links).forEach(link => {
transformed_upgrade_links = {
...transformed_upgrade_links,
[link]: `new_account/${upgrade_links[link]}`,
};
});
return Object.assign(upgrade_info, {
upgrade_links : transformed_upgrade_links,
is_current_path: !!Object.values(upgrade_links)
.find(link => new RegExp(link, 'i').test(window.location.pathname)),
});
};
const defaultRedirectUrl = () => urlFor('trading');
return Object.assign({
processNewAccount,
activateByClientType,
sendLogoutRequest,
doLogout,
getUpgradeInfo,
defaultRedirectUrl,
}, ClientBase);
})();
module.exports = Client;