forked from wlegate/Block-Explorer-IQ-Public
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscatter-header.html
More file actions
208 lines (184 loc) · 7.75 KB
/
Copy pathscatter-header.html
File metadata and controls
208 lines (184 loc) · 7.75 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
<script>
var eos = "";
var scatterAccountName = ""; // need to fix this later
var scatterAccountNameUInt64 = "";
var TokenNameUInt64 = "";
var TokenNameUInt64PlusOne = "";
var network = "";
var requiredFields = "";
var isMobile = parseInt('{{request.mobile|yesno:"1,0"}}');
var isTablet = parseInt('{{request.tablet|yesno:"1,0"}}');
var IQ_PRECISION_MULTIPLIER = 10000;
var network = {};
var requiredFields = {};
var eosOptions = {};
var theNetType = Eos;
function ipfs_to_uint64_trunc(hash){
var preHash = hash.replace(/[6789\s]/g, '');
var truncatedHash = preHash.substring(2, 14).toLowerCase();
var hashNumber = Eos.modules.format.encodeName(truncatedHash, 0);
var result = bigInt(hashNumber).mod(9007199254740990).toJSNumber();
return(result);
}
function convertSecs(secs) {
var d, h, m, s;
s = secs;
m = Math.floor(s / 60);
s = s % 60;
h = Math.floor(m / 60);
m = m % 60;
d = Math.floor(h / 24);
h = h % 24;
return { d: d, h: h, m: m, s: s };
}
function isNormalInteger(str) {
var n = Math.floor(Number(str));
return n !== Infinity && String(n) === str && n >= 0;
}
function refreshEOS() {
$.ajax({
type: "POST",
url: "https://mainnet.libertyblock.io:7777/v1/chain/get_table_rows",
// cannot filter by proposal ID until secondary indexes are fixed by Dan. Also cannot set proposal ID as primary key due to uniqueness issues...
data: JSON.stringify({"scope":scatterAccountNameUInt64, "code":"eosio.token", "table":"accounts", "limit":"999999999999", "json": true}),
beforeSend: function( xhr ) {
},
success: function (data) {
$.each(data.rows, function( index, value ) {
let theBalance = value.balance;
let theSplit = theBalance.split(/[ ,]+/);
if(theSplit[1] == "EOS" ){
eosBalance = parseFloat(theSplit[0]);
// Fix this later
// var iqElement = '<a href="/editor/' + scatterAccountName + '/">' + iqBalance.toLocaleString() +' IQ</a>';
let eosElement = '<a href="javascript:void(0);"><span id="header_eos_count">' + eosBalance.toLocaleString() +' EOS</span></a>';
$(".navbar-nav #header_eos_count").parent().parent().html(eosElement);
return false;
}
});
}
});
}
function refreshIQ() {
$.ajax({
type: "POST",
url: "https://mainnet.libertyblock.io:7777/v1/chain/get_table_rows",
// cannot filter by proposal ID until secondary indexes are fixed by Dan. Also cannot set proposal ID as primary key due to uniqueness issues...
data: JSON.stringify({"scope":scatterAccountNameUInt64, "code":"everipediaiq", "table":"accounts", "limit":"999999999999", "json": true}),
beforeSend: function( xhr ) {
},
success: function (data) {
$.each(data.rows, function( index, value ) {
let theBalance = value.balance;
let theSplit = theBalance.split(/[ ,]+/);
if(theSplit[1] == "IQ" ){
iqBalance = parseFloat(theSplit[0]);
// Fix this later
// var iqElement = '<a href="/editor/' + scatterAccountName + '/">' + iqBalance.toLocaleString() +' IQ</a>';
let iqElement = '<a href="javascript:void(0);"><span id="header_iq_count">' + iqBalance.toLocaleString() +' IQ</span></a>';
$(".navbar-nav #header_iq_count").parent().parent().html(iqElement);
return false;
}
});
}
});
}
function refreshBrainpower(){
var uint64ScatterName = bigInt(Eos.modules.format.encodeName(scatterAccountName, 1));
var uint64ScatterNamePlusOne = uint64ScatterName + 1;
var uint64ScatterNameStringed = uint64ScatterName.toString();
var uint64ScatterNamePlusOneStringed = uint64ScatterNamePlusOne.toString();
$.ajax({
type: "POST",
url: "https://mainnet.libertyblock.io:7777/v1/chain/get_table_rows",
data: JSON.stringify({
"scope": "eparticlectr", "code": "eparticlectr", "table": "brainpwrtbl",
"lower_bound": uint64ScatterNameStringed, "upper_bound": uint64ScatterNamePlusOneStringed,
"table_key": "byuser", "json": true
}),
beforeSend: function (xhr) {
},
success: function (data) {
var brainpower;
try {
brainpower = data.rows[0].power;
brainpower = brainpower.toLocaleString() + " BRAIN";
}
catch(err) {
brainpower = "GET BRAINPOWER";
}
var brainElement = '<a href="/brainpower/' + scatterAccountName + '/"><span id="header_bpwr_count">' + brainpower + '</span></a>';
$(".navbar-nav #header_bpwr_count").parent().parent().html(brainElement);
}
});
}
function getBrainpower(){
let quickString = $("#header_bpwr_count").html();
let quickSplit = quickString.replace(",", "").split(" ");
let brainValue = quickSplit[0];
if (isNormalInteger(brainValue)){
return parseInt(brainValue);
}
else{
return 0;
}
}
$(document).on("scatterLoaded", function () {
network = {
protocol:'https',
blockchain: 'eos',
host: 'mainnet.libertyblock.io', // ( or null if endorsed chainId )
port: 7777, // ( or null if defaulting to 80 )
chainId: "aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906" // FILL THIS IN WITH MAINNET https://mainnet.libertyblock.io:7777/v1/chain/get_info
};
requiredFields = {accounts:[ network ]};
eosOptions = {
broadcast: true,
sign: true,
expireInSeconds: 3600, // 1 hr
verbose: false,
chainId: "aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906" // FILL THIS IN WITH MAINNET https://mainnet.libertyblock.io:7777/v1/chain/get_info
};
// $.ajax({
// type: "POST",
// url: "https://mainnet.libertyblock.io:7777/v1/chain/get_info",
// data: {},
// beforeSend: function (xhr) {
// },
// success: function (data) {
// console.log(data);
// },
// error: function (request, error) {
// console.log(arguments);
// alert(" Can't do because: " + error);
// },
// });
var iqBalance = "0 IQ";
scatter.getIdentity(requiredFields).then(identity => {
eos = scatter.eos(network, theNetType, eosOptions);
scatterAccountName = identity.accounts[0].name;
var scatterAccountNameBigInt = bigInt(Eos.modules.format.encodeName(scatterAccountName, 0));
scatterAccountNameUInt64 = scatterAccountNameBigInt.toString();
// var TokenNameBigInt = bigInt(Eos.modules.format.encodeName("iq", 0));
// TokenNameUInt64 = TokenNameBigInt.toString();
// TokenNameUInt64PlusOne = TokenNameBigInt.plus(1).toString();
if (isMobile){
alert(isMobile);
}
else{
$("ul.nav li.avatar-iq .scatter-username").html(scatterAccountName);
}
refreshIQ();
$.event.trigger({
type: "scatterNavbarDone",
});
}).catch(error => {
console.log(error);
console.log("Failed to get Scatter identity")
});
});
$(document).on("scatterNavbarDone", function () {
refreshBrainpower();
refreshEOS();
});
</script>