-
Notifications
You must be signed in to change notification settings - Fork 6
/
proposal.html
executable file
·603 lines (454 loc) · 18.5 KB
/
proposal.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
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
<html>
<head>
<meta charset="utf-8">
<title>Proposal - DAO Stats</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
<link rel="stylesheet" href="graph.css">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<script src="datahelper.js"></script>
<script src="graph.js"></script>
<script src="markdown.min.js"></script>
<style>
#miniDesc{
overflow:hidden;
white-space:nowrap;
max-width: 105%;
}
.miniDescFade{
position:relative;
}
.miniDescFade:before {
content:'';
width:15%;
height:100%;
position:absolute;
left:85%;
top:0;
background:linear-gradient(to left, rgba(255,255,255,1) 0%,rgba(255,255,255,0) 100%);
}
</style>
</head>
<body>
<nav class="navbar navbar-default navbar-static-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"/>
<span class="icon-bar"/>
<span class="icon-bar"/>
</button>
<a class="navbar-brand" href="index.html">DAO Stats</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>
<a href="index.html">Home</a>
</li>
<li>
<a href="nav.html">Search</a>
</li>
<li>
<a href="accounts.html">Accounts</a>
</li>
<li>
<a href="proposals.html">Proposals</a>
</li>
<li>
<a href="tokenvol.html">Graphs</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
<a href="about.html">About</a>
</li>
</ul>
</div>
<!--/.nav-collapse -->
</div>
</nav>
<div class="container">
<div id="invalidacc" class="alert alert-danger collapse" role="alert">Invalid proposal ID</div>
<div id="unknownacc" class="alert alert-warning collapse" role="alert">
<strong>Proposal not indexed</strong>
<br />
The proposal will be indexed shortly after it is created</div>
<div id="newSPAlert" class="alert alert-info collapse" role="alert">
<strong>This is a split proposal</strong>
<br />
See below for more information</div>
<div class="row">
<div class="col-md-6">
<h3>Proposal ID: <small>
<span id="proposal-js"></span>
<span id="statP" class="label label-success" style="display:none;">Passed with <span class="majority"/>
</span></span>
<span id="statF" class="label label-danger" style="display:none;">Failed with <span class="majority"/>
</span></span>
<span id="statV" class="label label-info" style="display:none;">Currently voting</span>
<span id="statT" class="label label-warning" style="display:none;">Ready to be tallied</span>
</small>
</h3>
</div>
<div class="col-md-6">
<br /><h4><span id="miniDesc" class="pull-right" >No Description</span></h4>
</div>
</div>
<hr style="margin:5px;"/>
<div id="extraInfo" class="collapse">
<div class="row">
<div class="col-md-6">
<h4>Amount: <small>
<span id="amount-js"/>
</small>
</h4>
<h4>Created by: <small>
<a class="hexLink" id="creator-js"> </a>
</small>
</h4>
<h4>
<span id="recipientMode">New Curator:</span> <small>
<a class="hexLink" id="recipient-js">
</a>
</small>
</h4>
</div>
<div class="col-md-6">
<h4>Close date: <small><span id="close-js"></span></h4></small>
<h4>Transaction: <small><a class="txLink shrink" id="txhash-js"></a></h4></small>
<h4>Deposit: <small><span id="deposit-js"></span></h4></small>
</div>
</div><!-- row -->
<h4> Voting result: <small>
<span id="voteCapYay" data-toggle="tooltip"></span>, <span id="voteCapNay" data-toggle="tooltip"></></span>
</small>
<div class="progress">
<div id="voteYay" class="progress-bar progress-bar-success" style="width: 0%">
<span class="sr-only">Yay</span>
</div>
<div id="voteNay" class="progress-bar progress-bar-danger" style="width: 0%">
<span class="sr-only">Nay</span>
</div>
<div data-toggle="tooltip" title="50% Marker" style="width: 1px; height: 20px; position: absolute; background: black; right: 50%;">
</div>
</div></h4>
<h4>Turnout: <span id="turnout" data-toggle="tooltip"></span>
<span class="pull-right">Quorum: <span id="quorumText"></span></span>
<div class="progress quorum">
<div id="totalVotes" class="progress-bar" style="width: 0%">
<span class="sr-only">Votes</span>
</div>
<div id="neededVotes" class="progress-bar progress-bar-success" data-toggle="tooltip" title="Quorum" data-placement="right" style=" width: 0%">
<span class="sr-only">Quorum needed</span>
</div>
</div>
</h4>
<ul id="tabs1" class="nav nav-tabs">
<li id="desctab" class="active"><a href="#descpage" data-toggle="tab">Description</a></li>
<li id="votetab"><a href="#votepage" data-toggle="tab">Voting</a></li>
</ul>
<div id="pages1" class="tab-content">
<div id="descpage" class="tab-pane active">
<div id="descDisplay" class="btn-group" style="display:none;" role="group" aria-label="Rendering">
<button id="buttonPlain" type="button" class="btn btn-default">Plain text</button>
<button id="buttonMarkdown" type="button" class="btn btn-default">Markdown</button>
</div>
<div id="descText" class="panel-body">
No Description
</div>
</div>
<div id="votepage" class="tab-pane" >
<a id="voteGraphLink" href="#votepage">Link to this graph <span class="glyphicon glyphicon-link" aria-hidden="true"></span></a>
<div id="graphBox" class="graph">
</div>
</div>
</div>
<br />
</div>
</div>
<!-- Container end -->
<script src="https://d3js.org/d3.v3.min.js"></script>
<script>
$(window).on('hashchange', function() {
window.location.reload(true);
});
$(document).ready( function () {
$('#table-showsent').on('click', function (e) {
tableView(false, true);
});
$('#table-showrecv').on('click', function (e) {
tableView(true, false);
});
$('#table-showall').on('click', function (e) {
tableView(false, false);
});
$('#tabs').tab();
});
function tableView(sentvis, recvvis){
if(recvvis)$('.tx-recv').addClass("hidden");
else $('.tx-recv').removeClass("hidden");
if(sentvis)$('.tx-sent').addClass("hidden");
else $('.tx-sent').removeClass("hidden");
/*$("table#transferTable").removeClass("table-striped");
// now add stripes to alternating rows
$("table#transferTable tr").each(function (index) {
alert(index);
// but first remove class that may have been added by previous changes
$(this).css("background-color", "inherit");
if ( index % 2 == 0) {
$(this).css("background-color", "#f9f9f9");
}
});*/
/*
$("tr:not(.hidden)").each(function (index) {
$(this).toggleClass("stripe", !!(index & 1));
});*/
}
function quorumPc(value, divisor){
return 0.2 + value/divisor;
}
var params = window.location.hash.substring(1).split(",");
var propid = parseInt(params[0]);
var tabParam = params[1];
var plainText;
if(propid % 1 == 0)
{
applyData({proposal: propid});
getData("proposals/" + propid, function(data, status){
if(status != "success"){
applyData({amount: "Proposal not in records"});
$("#unknownacc").collapse("show");
return;
}
getData("vol", function(volData, vStatus){
if(!data["closed"]){
var totalVol = volData[2];
var quorumDivisor = volData[1];
}
else{
var totalVol = data["totalVol"] * (1e16);
var quorumDivisor = data["qDivisor"] * (1e16);
}
var totalVolUnit = totalVol * (1e-16);
$("#extraInfo").collapse("show");
deadline = data["deadline"];
now = Date.now()/1000;
timeup = false
if(deadline < now){
timeup = true;
}
close = new Date(deadline * 1000);
var y = close.getUTCFullYear();
var mo = padTime(close.getUTCMonth()+1);
var d = padTime(close.getUTCDate());
var h = padTime(close.getUTCHours());
var m = padTime(close.getUTCMinutes());
var s = padTime(close.getUTCSeconds());
ctext = y + "-" + mo + "-" + d + " " + h + ":" + m + ":" + s + " UTC";
if(deadline >= now){
var seconds = Math.floor(deadline - now);
var minutes = Math.floor(seconds/60);
var hours = Math.floor(minutes/60);
var days = Math.floor(hours/24);
seconds = seconds%60;
minutes = minutes%60;
hours = hours%24;
t = " (";
if(days > 0) t += days + " days, "
if(hours > 0) t += hours + " hours, "
if(minutes > 0) t += minutes + " minutes, "
t += seconds + " seconds"
t += ")";
ctext += t;
}
$("#close-js").text(ctext);
console.log(status);
if(data["newCurator"]==0) $("#recipientMode").text("Recipient: ");
applyData({amount: baseToETH2(data["amount"]),
creator: data["creator"],
recipient: data["recipient"],
txhash: data["txhash"],
deposit: baseToETH2(data["propdeposit"], "eth")});
if(data["newCurator"]){
$("#newSPAlert").collapse("show");
}
plainText = data["desc"];
if(plainText){
$("#descText").text(plainText);
$("#descDisplay").removeAttr("style");
$("#buttonPlain").on("click", function(){
$("#descText").text(plainText);
});
$("#buttonMarkdown").on("click", function(){
$("#descText").html(markdown.toHTML(plainText).replace(/(?:\\n)/g, '<br />'));
});
var miniDesc = plainText.slice(0, 80);
miniDesc = miniDesc.split(" ")[0];
miniDesc = miniDesc.split("\\n")[0];
$("#miniDesc").text(miniDesc);
var width = ( 100 * parseFloat($('#miniDesc').css('width')) / parseFloat($('#miniDesc').parent().css('width')) );
console.log(width);
if(miniDesc.length >= 80 || width > 100) $('#miniDesc').addClass("miniDescFade");
}
var yay = data["yes"];
var nay = data["nope"];
var total = yay + nay;
var yayStr = Math.round(yay * (1e-16)).toLocaleString();
var nayStr = Math.round(nay * (1e-16)).toLocaleString();
var totalStr = Math.round(total * (1e-16)).toLocaleString();
if(total > 0){
$("#voteYay").css("width", 100*yay/total + "%");
$("#voteNay").css("width", 100*nay/total + "%");
$("#voteCapYay").text(formatFloat(100*yay/total) + "% Yes")
.prop("title", yayStr + " DAO");
$("#voteCapNay").text(formatFloat(100*nay/total) + "% No")
.prop("title", nayStr + " DAO");
}
else $("#voteCap").text("No votes");
var turnout = total/totalVol;
$("#turnout").text(formatFloat(100*turnout) + "%")
.prop("title", totalStr + " DAO");
var quorum = quorumPc(data["amount"], quorumDivisor);
if(data["newCurator"]) quorum = (5+1/3)*0.1;
$("#quorumText").text(formatFloat(100*quorum) + "%");
var needed = quorum - turnout;
if(needed < 0){
$("#totalVotes").addClass("progress-bar-success")
.css("width", 100*quorum + "%");
$("#neededVotes").css("width", -100*needed + "%")
.css("border-left", "1px dotted black")
.attr("data-placement", "left")
.prop("title", "Quorum: " + formatFloat(quorum*100) + "%")
}
else{
$("#totalVotes").addClass("progress-bar-danger")
.css("width", 100*turnout + "%");
$("#neededVotes").css("width", 100*needed + "%")
.css("border-right", "1px dotted black")
.css("box-shadow", "none")
.css("background", "none")
.prop("title", "Quorum: " + formatFloat(quorum*100) + "%");
}
if(data['closed']){
if(data['passed']){
$("#statP").css("display", "inline");
$(".majority").text(100*yay/total + "% vs " + 100*nay/total + "%");
}
else{
$("#statF").css("display", "inline");
if(nay > yay) $(".majority").text(100*nay/total + "% vs " + 100*yay/total + "%");
else $(".majority").text("Quorum not met");
}
}
else{
if(timeup)
$("#statT").css("display", "inline");
else
$("#statV").css("display", "inline");
}
$("#voteGraphLink").prop("href", "#" + propid + ",votepage");
var graphLog = data['history'];
//graphLog = [[1280000,1,2]];//,[2,1,2],[3,2,4],[4,3,5],[5,5,5]]
if(graphLog.length != 0){
if(graphLog.length == 1){
graphLog.unshift([graphLog[0][0]-60, 0, 0]);
}
console.log(graphLog);
getData("blocktime", function(bdata, bstatus){
blockTimeArray = bdata;
console.log(graphLog);
var startTime = blockToTime(graphLog[0][0])
var endTime = new Date(deadline * 1000);
var startBlock = graphLog[0][0];
var endBlock = graphLog[graphLog.length-1][0];
var yesData = new Array(graphLog.length);
var noData = new Array(graphLog.length);
for(var i=0; i<graphLog.length; i++){
var blockTime = blockToTime(graphLog[i][0]);
var yesFac = graphLog[i][1]/totalVolUnit;
var noFac = graphLog[i][2]/totalVolUnit;
yesData[i] = {xNum: graphLog[i][0], xTime: blockTime, y: yesFac};
noData[i] = {xNum: graphLog[i][0], xTime: blockTime, y: noFac};
}
var lastY = yesData.slice(-1)[0].y;
var lastN = noData.slice(-1)[0].y;
var maxFac = Math.max(yesData.slice(-1)[0].y, noData.slice(-1)[0].y);
var lastBlock = yesData.slice(-1)[0].xNum;
yesData.push({xNum: lastBlock, xTime: new Date, y: lastY})
noData.push({xNum: lastBlock, xTime: new Date, y: lastN})
var yesLine = genLineDict(yesData, "Yes");
yesLine.legend = {toggle: false};
yesLine.brush = true;
var noLine = genLineDict(noData, "No", "#d22");
noLine.legend = {toggle: false};
noLine.brush = true;
var drawGraph = function(){
new plotGraph("graphBox", [yesLine, noLine], [0], "Block", ["Votes (Percent)"], function(n){
return Math.round(n*10000)/100 + "%";
}, {button: [{text: "Show UTC time",
enable: function(){
this.changeTickFormat(
function(){return [this.xScaleTime, this.xScaleTime2];},
function(axis){
var r = getXRatio(this.xScaleTime2.domain(), this.width);
var n = Math.floor(r / 1000);
axis
.ticks(getNDIntervals(n))
.tickFormat(d3.time.format('%b %d'));
}, "xTime", 180, "Time");}
, disable: function(){this.changeTickFormat(undefined, undefined, "xNum", 100, "Block");}},
{text: "Scale Y axis",
enable: function(){
this.y.domain([0, maxFac * 1.02]); this.updateAxes(); this.rebrush();},
disable: function(){this.y.domain([0, 1]); this.updateAxes(); this.rebrush();}}],
type: "dual",
blockDomain: [startBlock, endBlock],
timeDomain: [startTime, endTime],
yDomain: [0, 1],
yDomainMod: 1,
ttLines: [0, 1],
ttFormat: function(n){return formatFloat(n*100) + "%";}});
}
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
var target = $(e.target).attr("href") // activated tab
console.log(target);
if(target == "#votepage" && $("#graphBox svg").length == 0){
console.log("Drawing graph");
drawGraph();
}
});
console.log(tabParam);
if(tabParam == "votepage"){
$('.nav-tabs a[href="#votepage"]').tab("show");
}
});
}
else $("#graphBox").text("No voting data are available yet");
$('[data-toggle="tooltip"]').tooltip({
container : 'body'
});
hexLink();
txLink();
});
});
}
else {
applyData({account: "Invalid account"});
$("#invalidacc").collapse("show");
}
</script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-77332805-1', 'auto');
ga('send', 'pageview', {'page': location.pathname + location.search + location.hash});
</script>
</body>
</html>