-
Notifications
You must be signed in to change notification settings - Fork 2
/
booster.js
97 lines (92 loc) · 3.13 KB
/
booster.js
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
var booster_account='invest.viz.plus';
var booster_effective_shares=0;
var booster_percent=1.5;
var booster_ltmp={
'en':{
'ok':'Code successfully activated',
},
'ru':{
'ok':'Код успешно активирован',
},
};
var booster_update_timer=0;
var booster_update_timeout=60000;//60 sec
function booster_update_valuation(){
let valuation_el=$('.page-booster .booster-valuation');
let valuation=0;
valuation_el.html('…');
viz.api.getAccount(booster_account,'',function(err,response){
if(err){
console.log(err);
booster_update_timer=setTimeout(function(){
booster_update_valuation();
},booster_update_timeout);
}
else{
valuation=parseInt(parseFloat(response.vesting_shares)-parseFloat(response.delegated_vesting_shares));
valuation=valuation*booster_percent/100;
valuation=Math.ceil(valuation/100)*100;
valuation_el.html(valuation);
booster_update_timer=setTimeout(function(){
booster_update_valuation();
},booster_update_timeout);
}
});
}
function stop_booster_updates(){
clearTimeout(booster_update_timer);
}
function booster_init(){
let page=$('.page-booster');
page.find('input[name="booster-account"]').val(current_user);
page.find('.booster_set_account').each(function(i,el){
let href=$(el).attr('href');
href=href.replace(/account=.*$/g,'account=');
$(el).attr('href',href+current_user);
});
setTimeout(function(){
booster_update_valuation();
},100);
}
function booster_code(code,login){
let page=$('.page-booster');
page.find('.activate-booster-action').attr('disabled','disabled');
page.find('.icon-check').css('display','none');
page.find('.submit-button-ring').css('display','inline-block');
page.find('.activate-booster-error').html('');
page.find('.activate-booster-success').html('');
let xhr = new XMLHttpRequest();
xhr.overrideMimeType('text/plain');
xhr.open('POST','/booster_api.php');
xhr.setRequestHeader('accept','application/json, text/plain, */*');
xhr.setRequestHeader('content-type','application/x-www-form-urlencoded');
xhr.onreadystatechange = function() {
if(4==xhr.readyState && 200==xhr.status){
try{
let json=JSON.parse(xhr.response);
}
catch(e){
console.log('booster api error');
page.find('.activate-booster-error').html(ltmp(ltmp_arr.default_error,{text:ltmp_arr.default_api_error}));
page.find('.activate-booster-action').removeAttr('disabled');
page.find('.submit-button-ring').css('display','none');
}
finally{
let json=JSON.parse(xhr.response);
console.log('booster api response',json);
if(json.error !== null){
page.find('.activate-booster-error').html(ltmp(ltmp_arr.default_error,{text:json.error}));
page.find('.activate-booster-action').removeAttr('disabled');
page.find('.submit-button-ring').css('display','none');
}
else{
page.find('input[name="booster-code"]').val('');
page.find('.activate-booster-success').html(booster_ltmp[selected_lang]['ok']);
page.find('.activate-booster-action').removeAttr('disabled');
page.find('.submit-button-ring').css('display','none');
}
}
}
}
xhr.send('code='+encodeURIComponent(code)+'&login='+encodeURIComponent(login));
}