-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
465 lines (394 loc) · 21.1 KB
/
index.html
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>SRC-20 Dashboard</title>
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css" rel="stylesheet" />
<style type="text/css">
#header { margin-top: 20px; }
.info-btn { cursor: pointer;}
table#tokens thead th { text-decoration: underline; cursor: pointer; }
table#tokens thead th[data-sort-method="none"] { text-decoration: none; }
[aria-sort] { position: relative; }
[aria-sort="ascending"]:after { position: absolute; content: "⌄"; display: block; width: 20px; height: 20px; right: 0; top: 0; font-size: 20px; text-align: center; }
[aria-sort="descending"]:after { position: absolute; content: "⌃"; display: block; width: 20px; height: 20px; right: 0; top: 12px; font-size: 14px; text-align: center; }
</style>
</head>
<body>
<div class="container mb-3">
<h3 id="header">SRC-20 Dashboard</h3>
<hr />
<div class="alert alert-info" role="alert">
<span>
<i class="info-btn bi bi-info-circle-fill"></i>
</span>
This is an Alpha version and it's possible that the information may not be accurate or updated in real time.<br /><br />
This dashboard leverages <a target="_blank" href="https://github.com/hydren-crypto/stampchain/blob/main/docs/api-src20.md">StampChain API</a>, so if that updates the dashboard will do too (after a refresh)
</div>
<p>
Current conditions:
<ul>
<li>Amounts greater than mint limit fallback to the mint limit</li>
<li>Casing doesn't matter, so KeViN, KEVIN and Kevin are all valid</li>
<li>Mints after the deploy are valid, mints before deploy aren't</li>
<li>Mint amounts containing a comma are considered invalid, as <a href="https://github.com/hydren-crypto/stampchain/blob/main/docs/src20.md#src-20-token-examples" target="_blank">per spec</a></li>
</ul>
</p>
<hr />
</div>
<div class="container mb-5">
<div id="result">
<div class="alert alert-warning" role="alert">
<span>
<i class="info-btn bi bi-info-circle-fill"></i>
</span>
Down until further notice, please use <a href="https://www.stampscan.xyz/" target="_blank">stampscan.xyz</a> as an alternative! ✌️
</div>
</div>
</div>
<div class="container text-center">
<footer class="d-flex flex-wrap justify-content-between align-items-center py-3 my-4 border-top">
<div class="col-md-12 d-flex align-items-center">
<span class="text-muted">Made by obi, source: <a target="_blank" href="https://github.com/crypt0biwan/src20">github</a>, contact: <a target="_blank" href="https://twitter.com/crypt0biwan">twitter</a>, donations: 1obiAgwKHdqrv135uzHH81Pz7MGG1sqvw</span>
</div>
</footer>
</div>
<script src="js/bootstrap.bundle.min.js"></script>
<script src="js/lodash.min.js"></script>
<script src="js/tablesort.min.js"></script>
<script src="js/tablesort.number.min.js"></script>
<script>
let total_stamps = 0
let total_pages = 1
let stamp_cache = []
let stamps = []
let src20s = []
let tokens = []
let timestamp = new Date().getTime()
const header = document.querySelector('#header')
const result = document.querySelector('#result')
const formatValue = (value, decimals = 0, style = 'decimal') =>
new Intl.NumberFormat('en-US', {
style,
currency: 'USD',
minimumFractionDigits: decimals,
maximumFractionDigits: decimals,
}).format(value)
const showLoadingMessage = (text = "loading..") => {
result.innerHTML = `<div class="alert alert-info" role="alert">
<span>
<i class="info-btn bi bi-info-circle-fill"></i>
</span> ${text}
</div>`
}
const showApiError = (html) => {
result.innerHTML = html ? html : `<div class="alert alert-danger" role="alert">
<i class="bi bi-exclamation-triangle-fill"></i> Couldn't fetch Stampchain API
</div>`
}
const get_stamp_cache = () => fetch(`./json/src20.json?ts=${timestamp}`).then((response) => response.json()).catch(e => {
console.log(e)
showApiError()
})
const get_src20_count = () => fetch('https://stampchain.io/api/src20?count').then((response) => response.json()).catch(e => {
console.log(e)
showApiError()
})
const get_stamps = (page = 1) => fetch(`https://stampchain.io/api/src20?page=${page}`).then((response) => response.json()).catch(e => {
console.log(e)
showApiError()
})
const get_mints = (ticker, deployStamp) => _.filter(_.orderBy(stamps, ['stamp'], ['asc']), x => x.tick.toUpperCase() === ticker.toUpperCase() && x.op.toUpperCase() === 'MINT' && x.stamp > deployStamp)
const get_amount_minted = tick => {
const token = _.filter(tokens, token => token.tick.toUpperCase() === tick.toUpperCase())[0]
const {
stamp: tokenStamp,
max,
lim,
} = token
let total_tokens = 0
let amount_of_mints = 0
let mint_info = {}
_.each(get_mints(tick, tokenStamp), mint => {
let {
stamp: mintStamp,
amt,
} = mint
let amount = _.parseInt(amt)
if(tokenStamp < mintStamp) {
if(amount > _.parseInt(lim)) {
amount = _.parseInt(lim)
}
if(total_tokens < max) {
if(total_tokens + amount > max) {
amount = max - total_tokens
}
if(total_tokens + amount <= max) {
amount_of_mints++
total_tokens += amount
}
}
}
})
return {
amount_of_mints,
total_tokens
}
}
const get_mints_html = (tick) => {
const token = _.filter(tokens, token => token.tick.toUpperCase() === tick.toUpperCase())[0]
const {
stamp: tokenStamp,
max,
lim,
} = token
let htmlValidTableStart =
`<table id="tokens" class="table table-striped table-sm mb-5" style="text-align: left; font-weight: 400;">
<thead>
<tr>
<th style="text-align: right; padding-right: 20px;" scope="col">ID</th>
<th style="text-align: right; padding-right: 20px;" scope="col">Stamp</th>
<th scope="col">Creator</th>
<th style="text-align: right; padding-right: 20px;" scope="col">Amount</th>
<th style="text-align: right; padding-right: 20px;" scope="col">Total</th>
<th style="text-align: right; padding-right: 20px;" scope="col">%</th>
</tr>
</thead>
<tbody>`
let htmlInvalidTableStart =
`<table id="tokens" class="table table-striped mb-5 text-danger" style="text-align: left;">
<thead>
<tr>
<th style="text-align: right; padding-right: 20px;" scope="col">ID</th>
<th style="text-align: right; padding-right: 20px;" scope="col">Stamp</th>
<th scope="col">Creator</th>
<th style="text-align: right; padding-right: 20px;" scope="col">Amount</th>
</tr>
</thead>
<tbody>`
let htmlValid = ``
let htmlInvalid = ``
let total_tokens = 0
_.each(get_mints(tick, tokenStamp), (mint, index) => {
const {
stamp: mintStamp,
op,
block_index,
creator,
amt,
tx_hash,
p
} = mint
let amount = _.parseInt(amt)
let limit = _.parseInt(lim)
// check if the "MINT" stamp is later than the "DEPLOY" stamp
if(tokenStamp < mintStamp) {
let newAmount = false
// check if the minted amount is greater than the mint limit
if(amount > limit) {
newAmount = limit
amount = newAmount
}
if(total_tokens < max && total_tokens + amount > max) {
newAmount = max - total_tokens
amount = newAmount
}
if(amt.toString().indexOf(',') === -1 && amount > 0 && total_tokens + amount <= max) {
total_tokens += amount
htmlValid += `<tr>
<td style="text-align: right; padding-right: 20px;">
${formatValue(index + 1)}
</td>
<td style="text-align: right; padding-right: 20px;">
<a href="https://stampchain.io/asset.html?stampNumber=${mintStamp}" target="_blank">${formatValue(mintStamp)}</a>
</td>
<td>
${creator}
</td>
<td style="text-align: right; padding-right: 20px; white-space: nowrap;">
${newAmount ? `<del>${formatValue(amt)}</del> <i class="bi bi-arrow-right-circle-fill"></i> ${formatValue(newAmount)}` : formatValue(amt)}
</td>
<td style="text-align: right; padding-right: 20px;">
${formatValue(total_tokens)}
</td>
<td style="text-align: right; padding-right: 20px;">
${parseFloat(100 / max * total_tokens).toFixed(2)} %
</td>
</tr>`
} else {
htmlInvalid += `<tr>
<td class="text-danger" style="text-align: right; padding-right: 20px;">
${formatValue(index + 1)}
</td>
<td class="text-danger" style="text-align: right; padding-right: 20px;">
<a href="https://stampchain.io/asset.html?stampNumber=${mintStamp}" target="_blank">${formatValue(mintStamp)}</a>
</td>
<td class="text-danger">
${creator}
</td>
<td class="text-danger" style="text-align: right; padding-right: 20px;">
${formatValue(amt)}
</td>
</tr>`
}
}
})
let htmlTableEnd =
`</tbody>
</table>`
let html = `<h5 style="text-align: left;">Valid mints <i class="bi bi-check-circle-fill"></i></h5>
${htmlValidTableStart}
${htmlValid}
${htmlTableEnd}
`
if(htmlInvalid) {
html += `<h5 style="text-align: left;">Invalid mints <i class="bi bi-x-circle-fill"></i></h5>
${htmlInvalidTableStart}
${htmlInvalid}
${htmlTableEnd}
`
}
return html
}
const parse_tokens = () => {
_.each(_.filter(stamps, x => x.op.toUpperCase() === 'DEPLOY'), x => {
const {
tick,
max,
lim
} = x
if(!_.filter(tokens, token => token.tick.toUpperCase() === tick.toUpperCase()).length) {
tokens.push(x)
}
})
}
const get_table_html = () => {
let html =
`<table id="tokens" class="table table-striped mb-5">
<thead>
<tr>
<th style="text-align: right; padding-right: 20px;" scope="col">ID</th>
<th style="text-align: right; padding-right: 20px;" scope="col">Stamp</th>
<th scope="col">Tick</th>
<th style="text-align: right; padding-right: 20px;" scope="col">Lim</th>
<th data-sort-method="none" style="text-align: right; padding-right: 20px;" scope="col">Mints</th>
<th style="text-align: right; padding-right: 20px;" scope="col">Total</th>
<th style="text-align: right; padding-right: 20px;" scope="col">Max</th>
<th style="text-align: right; padding-right: 20px;" scope="col">%</th>
</tr>
</thead>
<tbody>`
_.each(tokens, (token, index) => {
const {
stamp: stamp,
tick,
max,
lim
} = token
const {
amount_of_mints,
total_tokens
} = get_amount_minted(tick)
html +=
`<tr>
<td style="text-align: right; padding-right: 20px;">
${index+1}
</td>
<td style="text-align: right; padding-right: 20px;">
<a href="https://stampchain.io/asset.html?stampNumber=${stamp}" target="_blank">${formatValue(stamp)}</a>
</td>
<td>
${tick}
</td>
<td style="text-align: right; padding-right: 20px;">
${formatValue(lim)}
</td>
<td style="text-align: right; padding-right: 20px; white-space: nowrap;">
${formatValue(amount_of_mints)}
<span class="text-primary">
<i class="info-btn bi bi-info-circle-fill" data-bs-toggle="modal" data-bs-target="#modal${index}"></i>
</span>
<div class="modal fade" id="modal${index}" tabindex="-1" aria-labelledby="modal${tick}" aria-hidden="true" style="display: none;">
<div class="modal-dialog modal-xl">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-4" id="gridModalLabel">${tick} mint info</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div>
${get_mints_html(tick)}
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</td>
<td style="text-align: right; padding-right: 20px;">
${formatValue(total_tokens)}
</td>
<td style="text-align: right; padding-right: 20px;">
${formatValue(max)}
</td>
<td style="text-align: right; padding-right: 20px;">
${formatValue(100 / max * total_tokens, 2)} %
</td>
</tr>`
})
html +=
`</tbody>
</table>`
return html
}
const init = async () => {
try {
showLoadingMessage('Getting stamps from cache')
stamp_cache = await get_stamp_cache()
console.log(`${formatValue(stamp_cache.length)} stamps in cache, get latest total number of stamps..`)
showLoadingMessage('Getting latest number of stamps')
total_stamps = (await get_src20_count()).count
let stamp_difference = total_stamps - stamp_cache.length
console.log(`There are ${formatValue(total_stamps)} stamps in total, so we have to get ${formatValue(stamp_difference)} additional stamps from the API`)
total_pages = Math.ceil(total_stamps / 1000)
// Fill stamps array with cache
stamps = stamp_cache
if(stamp_difference > 0) {
showLoadingMessage('Getting latest stamps')
console.log(`we can skip the first ${Math.floor(stamp_cache.length / 1000)} pages, so we need to get page ${Math.ceil(stamp_cache.length / 1000)} to ${total_pages}`)
for(let i=Math.ceil(stamp_cache.length / 1000); i<=total_pages; i++) {
showLoadingMessage(`Loading page ${i} of ${total_pages}`)
let resp = (await get_stamps(i)).items
resp.forEach(item => {
if(_.filter(stamps, x => x.stamp === item.stamp).length) {
console.log(`Stamp id ${item.stamp} already in array`)
} else {
stamps.push(item)
}
})
}
}
showLoadingMessage('Building table HTML')
document.querySelector('#header').innerHTML = `SRC-20 Dashboard - ${formatValue(total_stamps)} SRC-20 stamps so far`
setTimeout(function() {
parse_tokens()
result.innerHTML = get_table_html()
new Tablesort(document.getElementById('tokens'))
}, 0)
} catch(e) {
console.log(e)
showApiError(
`<div class="alert alert-danger" role="alert">
<i class="bi bi-exclamation-triangle-fill"></i> There was a problem fetching the data..
</div>`
)
}
}
// init()
</script>
</body>
</html>