forked from binary-com/binary-static
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpage.js
More file actions
221 lines (206 loc) · 9.91 KB
/
page.js
File metadata and controls
221 lines (206 loc) · 9.91 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
const Login = require('./login').Login;
const template = require('./utility').template;
const LocalStore = require('./storage').LocalStore;
const State = require('./storage').State;
const localizeForLang = require('./localize').localizeForLang;
const localize = require('./localize').localize;
const getLanguage = require('./language').getLanguage;
const setCookieLanguage = require('./language').setCookieLanguage;
const Url = require('./url').Url;
const url_for = require('./url').url_for;
const Client = require('./client').Client;
const Header = require('./header').Header;
const Menu = require('./menu').Menu;
const Contents = require('./contents').Contents;
const TrafficSource = require('../common_functions/traffic_source').TrafficSource;
const checkLanguage = require('../common_functions/country_base').checkLanguage;
const ViewBalance = require('../websocket_pages/user/viewbalance/viewbalance.init').ViewBalance;
const Cookies = require('../../lib/js-cookie');
const RealityCheck = require('../websocket_pages/user/reality_check/reality_check.init').RealityCheck;
const RealityCheckData = require('../websocket_pages/user/reality_check/reality_check.data').RealityCheckData;
require('../../lib/polyfills/array.includes');
require('../../lib/polyfills/string.includes');
require('../../lib/mmenu/jquery.mmenu.min.all.js');
const Page = function() {
State.set('is_loaded_by_pjax', false);
Client.init();
this.url = new Url();
Menu.init(this.url);
};
Page.prototype = {
on_load: function() {
Client.set_check_tnc();
this.url.reset();
localizeForLang(getLanguage());
Header.on_load();
this.record_affiliate_exposure();
Contents.on_load();
if (State.get('is_loaded_by_pjax')) {
this.show_authenticate_message();
if (RealityCheckData.get_value('delay_reality_init')) {
RealityCheck.init();
} else if (RealityCheckData.get_value('delay_reality_check')) {
BinarySocket.send({ reality_check: 1 });
}
}
if (Client.get_boolean('is_logged_in')) {
ViewBalance.init();
} else {
LocalStore.set('reality_check.ack', 0);
}
setCookieLanguage();
if (sessionStorage.getItem('showLoginPage')) {
sessionStorage.removeItem('showLoginPage');
Login.redirect_to_login();
}
checkLanguage();
TrafficSource.setData();
this.endpoint_notification();
BinarySocket.init();
this.show_notification_outdated_browser();
},
on_unload: function() {
Menu.on_unload();
Contents.on_unload();
},
record_affiliate_exposure: function() {
const token = this.url.param('t');
if (!token || token.length !== 32) {
return false;
}
const token_length = token.length;
const is_subsidiary = /\w{1}/.test(this.url.param('s'));
const cookie_token = Cookies.getJSON('affiliate_tracking');
if (cookie_token) {
// Already exposed to some other affiliate.
if (is_subsidiary && cookie_token && cookie_token.t) {
return false;
}
}
// Record the affiliate exposure. Overwrite existing cookie, if any.
const cookie_hash = {};
if (token_length === 32) {
cookie_hash.t = token.toString();
}
if (is_subsidiary) {
cookie_hash.s = '1';
}
Cookies.set('affiliate_tracking', cookie_hash, {
expires: 365, // expires in 365 days
path : '/',
domain : '.' + location.hostname.split('.').slice(-2).join('.'),
});
return true;
},
reload: function(forcedReload) {
window.location.reload(!!forcedReload);
},
endpoint_notification: function() {
const server = localStorage.getItem('config.server_url');
if (server && server.length > 0) {
const message = (/www\.binary\.com/i.test(window.location.hostname) ? '' :
localize('This is a staging server - For testing purposes only') + ' - ') +
localize('The server <a href="[_1]">endpoint</a> is: [_2]', [url_for('endpoint'), server]),
$end_note = $('#end-note');
$end_note.html(message).removeClass('invisible');
$('#footer').css('padding-bottom', $end_note.height());
}
},
show_authenticate_message: function() {
if ($('.authenticate-msg').length !== 0 || /authenticatews\.html/.test(window.location.pathname)) return;
const p = $('<p/>', { class: 'authenticate-msg notice-msg' });
let span;
if (Client.status_detected('unwelcome')) {
const purchase_button = $('.purchase_button');
if (purchase_button.length > 0 && !purchase_button.parent().hasClass('button-disabled')) {
$.each(purchase_button, function() {
$(this).off('click dblclick').removeAttr('data-balloon').parent()
.addClass('button-disabled');
});
}
}
if (Client.status_detected('unwelcome, cashier_locked', 'any')) {
const if_balance_zero = $('#if-balance-zero');
if (if_balance_zero.length > 0 && !if_balance_zero.hasClass('button-disabled')) {
if_balance_zero.removeAttr('href').addClass('button-disabled');
}
}
const href = window.location.href,
cashier_page = /cashier[\/\w]*\.html/.test(href),
withdrawal_page = cashier_page && !/(deposit|payment_agent_listws)/.test(href);
if (Client.status_detected('authenticated, unwelcome', 'all')) {
span = $('<span/>', { html: template(localize('Your account is currently suspended. Only withdrawals are now permitted. For further information, please contact [_1].', ['<a href="mailto:support@binary.com">support@binary.com</a>'])) });
} else if (Client.status_detected('unwelcome')) {
span = this.general_authentication_message();
} else if (Client.status_detected('authenticated, cashier_locked', 'all') && cashier_page) {
span = $('<span/>', { html: template(localize('Deposits and withdrawal for your account is not allowed at this moment. Please contact [_1] to unlock it.', ['<a href="mailto:support@binary.com">support@binary.com</a>'])) });
} else if (Client.status_detected('cashier_locked') && cashier_page) {
span = this.general_authentication_message();
} else if (Client.status_detected('authenticated, withdrawal_locked', 'all') && withdrawal_page) {
span = $('<span/>', { html: template(localize('Withdrawal for your account is not allowed at this moment. Please contact [_1] to unlock it.', ['<a href="mailto:support@binary.com">support@binary.com</a>'])) });
} else if (Client.status_detected('withdrawal_locked') && withdrawal_page) {
span = this.general_authentication_message();
}
if (span) {
$('#content').find('> .container').prepend(p.append(span));
}
},
general_authentication_message: function() {
const span = $('<span/>', { html: template(localize('To authenticate your account, kindly email the following to [_1]:', ['<a href="mailto:support@binary.com">support@binary.com</a>'])) });
const ul = $('<ul/>', { class: 'checked' });
const li1 = $('<li/>', { text: localize('A scanned copy of your passport, driving licence (provisional or full) or identity card, showing your name and date of birth. Your document must be valid for at least 6 months after this date.') });
const li2 = $('<li/>', { text: localize('A scanned copy of a utility bill or bank statement (no more than 3 months old)') });
return span.append(ul.append(li1, li2));
},
show_notification_outdated_browser: function() {
window.$buoop = {
vs : { i: 11, f: -4, o: -4, s: 9, c: -4 },
api: 4,
l : getLanguage().toLowerCase(),
url: 'https://whatbrowser.org/',
};
$(document).ready(function() {
$('body').append($('<script/>', { src: '//browser-update.org/update.min.js' }));
});
},
};
const page = new Page();
// LocalStorage can be used as a means of communication among
// different windows. The problem that is solved here is what
// happens if the user logs out or switches loginid in one
// window while keeping another window or tab open. This can
// lead to unintended trades. The solution is to reload the
// page in all windows after switching loginid or after logout.
// onLoad.queue does not work on the home page.
// jQuery's ready function works always.
$(document).ready(function () {
if ($('body').hasClass('BlueTopBack')) return; // exclude BO
// Cookies is not always available.
// So, fall back to a more basic solution.
let match = document.cookie.match(/\bloginid=(\w+)/);
match = match ? match[1] : '';
$(window).on('storage', function (jq_event) {
switch (jq_event.originalEvent.key) {
case 'active_loginid':
if (jq_event.originalEvent.newValue === match) return;
if (jq_event.originalEvent.newValue === '') {
// logged out
page.reload();
} else if (!window.is_logging_in) {
// loginid switch
page.reload();
}
break;
case 'new_release_reload_time':
if (jq_event.originalEvent.newValue !== jq_event.originalEvent.oldValue) {
page.reload(true);
}
break;
// no default
}
});
LocalStore.set('active_loginid', match);
});
module.exports = {
page: page,
};