-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDashboard.html
224 lines (199 loc) · 7.99 KB
/
Dashboard.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
<title>BUC</title>
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
<script src="https://unpkg.com/web3@latest/dist/web3.min.js"></script>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script src="./abi.js"></script>
<link rel="icon" href="./images/BUC.png" type="image/x-icon">
<style>
body {
background-color: #111518;
}
</style>
</head>
<body bgcolor="#111518">
<nav class="navbar navbar-dark bg-dark">
<div class="container-fluid">
<a class="navbar-brand">
<img src="./images/BUC.png" alt="" width="30" height="30" class="d-inline-block align-text-top"> BUC Dashboard
</a>
<button class="btn btn-outline-success" type="submit" onclick="CheckMetamaskConnection()">Connect</button>
</div>
</nav>
<br><br>
<div style="width: 80%;margin: auto;">
<div class="row">
<div class="col-sm-6">
<div class="card">
<div style="background-color: #333;color: yellowgreen;border-radius: 10px;border-color: #333;" class="card-body">
<h5 class="card-title">Total Supply:</h5>
<p style="text-align: center;font-size: 30px;" class="card-text" id="TS"></p>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="card">
<div style="background-color: #333;color: yellowgreen;border-radius: 10px;" class="card-body">
<h5 class="card-title">Average Velocity:</h5>
<p style="text-align: center;font-size: 30px;" class="card-text" id="vel"></p>
</div>
</div>
</div>
</div>
</div>
<br><br>
<div style="width: 80%;margin: auto;">
<div class="row">
<div class="col-sm-6">
<div class="card">
<div style="background-color: #333;color: yellowgreen;border-radius: 10px;" class="card-body">
<h5 class="card-title">Your BUC Holdings:</h5>
<p style="text-align: center;font-size: 30px;" class="card-text" id="myBal"></p>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="card">
<div style="background-color: #333;color: yellowgreen;border-radius: 10px;" class="card-body">
<h5 class="card-title">Your BUC Share:</h5>
<p style="text-align: center;font-size: 30px;" class="card-text" id="share"></p>
</div>
</div>
</div>
</div>
</div>
<br><br>
<div id="chartContainer" style="height: 300px; width: 80%;margin: auto;"></div>
<script>
Number.prototype.noExponents = function() {
var data = String(this).split(/[eE]/);
if (data.length == 1) return data[0];
var z = "",
sign = this < 0 ? "-" : "",
str = data[0].replace(".", ""),
mag = Number(data[1]) + 1;
if (mag < 0) {
z = sign + "0.";
while (mag++) z += "0";
return z + str.replace(/^\-/, "");
}
mag -= str.length;
while (mag--) z += "0";
return str + z;
};
console.log('hello')
var myContract;
var accounts;
async function CheckMetamaskConnection() {
// Modern dapp browsers...
if (window.ethereum) {
window.web3 = new Web3(window.ethereum);
try {
// Request account access if needed
await ethereum.enable();
accounts = await web3.eth.getAccounts();
console.log("yes");
init();
// Acccounts now exposed
return true;
} catch (error) {
// User denied account access...
return false;
}
}
// Legacy dapp browsers...
else if (window.web3) {
window.web3 = new Web3(web3.currentProvider);
// Acccounts always exposed
accounts = await web3.eth.getAccounts();
console.log("yes");
init();
return true;
}
// Non-dapp browsers...
else {
console.log(
"Non-Ethereum browser detected. You should consider trying MetaMask!"
);
return false;
}
}
CheckMetamaskConnection();
myContract = new web3.eth.Contract(
scAbi,
"0x72d42A0df86CfE4618ad0450eD2b910a8E3f32d2"
);
const init = async() => {
console.log(accounts);
var Ts = parseFloat(
(await myContract.methods.totalSupply().call()) / Math.pow(10, 18)
);
var velocity = parseFloat(
(await myContract.methods.avgVel().call()) / Math.pow(10, 18)
);
var shares = (
(await myContract.methods.yourShare(accounts[0]).call()) /
Math.pow(10, 18)
).noExponents()
document.getElementById("TS").innerHTML = Ts.noExponents();
document.getElementById(
"vel"
).innerHTML = `${velocity.noExponents()}`;
document.getElementById("myBal").innerHTML = (
(await myContract.methods.balanceOf(accounts[0]).call()) / Math.pow(10, 18)
).noExponents();
document.getElementById("share").innerHTML = `${shares}%`;
google.charts.load('current', {
'packages': ['corechart']
});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var remaining = 100 - shares;
console.log(shares)
var data = google.visualization.arrayToDataTable([
['Address', 'Percentage'],
[accounts[0], shares],
['others', 10],
]);
var options = {
title: 'Your Share'
};
var chart = new google.visualization.PieChart(document.getElementById('piechart'));
chart.draw(data, options);
window.location.reload(true);
}
};
//line chart
window.onload = function() {
var chart = new CanvasJS.Chart("chartContainer", {
animationEnabled: true,
theme: "light2",
title: {
text: "Total supply"
},
data: [{
type: "line",
indexLabelFontSize: 16,
dataPoints: [{
y: 1000000000
}, {
y: 1000020000
}, {
y: 1000300000
}, {
y: 1000024000
}]
}]
});
chart.render();
}
</script>
</body>
</html>