forked from hunterg2/Zabo-Cryptocurrency-Profile-Aggregator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
510 lines (464 loc) · 17.8 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
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
<!DOCTYPE html>
<html>
<title>Crypton</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Raleway">
<link rel="icon" type="image/png" href="images/icons/favicon.ico"/>
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="vendor/bootstrap/css/bootstrap.min.css">
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="fonts/font-awesome-4.7.0/css/font-awesome.min.css">
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="vendor/animate/animate.css">
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="vendor/select2/select2.min.css">
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="vendor/perfect-scrollbar/perfect-scrollbar.css">
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="css/util.css">
<link rel="stylesheet" type="text/css" href="css/main.css">
<style>
.hidden{
display:none;
}
.unhidden{
display:block;
}
body,h1,h2{font-family: "Raleway", sans-serif}
body, html {height: 100%}
p {line-height: 2}
.bgimg, .bgimg2, .bgimg3 {
min-height: 100%;
background-position: center;
background-size: cover;
}
.bgimg {background-image: url("public/images/bg2.jpg")}
.bgimg2 {background-image: url("public/images/bg3.jpg")}
.bgimg3 {background-image: url("public/images/bg1.png")}
canvas {
height:500px;
width:1000px;
}
th {
white-space: pre-wrap;
}
</style>
<body>
<!-- Header / Home-->
<header class="w3-display-container w3-wide bgimg w3-grayscale-min" id="home">
<div class="w3-display-middle w3-text-white w3-center">
<h1 class="w3-jumbo"><b>Crypton</b></h1>
<h2><b>Cryptocurrencies made simple</b></h2>
<h2><button id= "connect"><span id="connect_display"></span></button></h2>
<div id="table_connect" class="hidden">
<table style="width:100%">
<tr>
<th>Wallet Provider</th>
<th>Currencies in Account</th>
</tr>
<tr>
<td><span id="walletProvider"></span></td>
<td><span id="curren"></span></td>
</tr>
</table>
</div>
</div>
</header>
<!-- Navbar (sticky bottom) -->
<div class="w3-bottom w3-hide-small">
<div class="w3-bar w3-black w3-center w3-padding w3-opacity-min w3-hover-opacity-off">
<a href="#home" style="width:25%" class="w3-bar-item w3-button">Home</a>
<a href="#balance" style="width:25%" class="w3-bar-item w3-button">Balance</a>
<a href="#transaction" style="width:25%" class="w3-bar-item w3-button">Transaction</a>
<a href="#market" style="width:25%" class="w3-bar-item w3-button">Market</a>
</div>
</div>
<!-- Balance -->
<!-- <div class="w3-container w3-padding-64 w3-pale-black w3-grayscale-min" id="balance"> -->
<div class="w3-display-container bgimg3">
<div id="table_balance" class="hidden">
<font size=4 style="font-family=Courier New">
<table rules="groups" id='balance_table' class="w3-display-topmiddle w3-margin-top w3-text-black w3-padding" style="background-color: #ffffff" border=2></table>
</font>
</div>
<div class="w3-display-middle w3-text-white w3-center" style="height:40%">
<!-- <div class="w3-content"> -->
<div >
<h2 class="w3-center w3-text-grey w3-margin-bottom">
<button id= "balance">Balance</button>
</h2>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.min.js"></script>
<canvas id="canvas"></canvas>
</div>
</div>
<!-- Background photo -->
<div class="w3-display-container bgimg2">
<div class="w3-display-middle w3-text-white w3-center">
<div>
<h2 class="w3-center w3-text-grey w3-margin-bottom">
<button id= "exchangeRates">Exchange Rate</button>
</h2>
</div>
</div>
<div class="w3-display-middle hidden" id="table_exchange" style="width:80%">
<font size=4 style="font-family=Courier New">
<table rules="groups" id='exchange_table' class="w3-display-left w3-margin-top w3-text-white w3-padding" border=2></table>
</font>
</div>
</div>
<!-- Transaction -->
<div class="w3-container w3-padding-64 w3-silver w3-grayscale-min w3-center" id="transaction">
<div class="w3-content">
<h2 class="w3-text-grey"><b>
<div id="table_transact" class="hidden">
<table style="width:100%">
<tr>
<th>Currencies in Account</th>
</tr>
<tr>
<td><span id="trans"></span></td>
</tr>
</table>
</div>
<input type="text" id="tic" name="message" rows="1" cols="4"></input>
</b><button id= "history">Get Transaction History (Last 25)</button></b></h2>
<div class="w3-row">
<div id="transaction_table" class="hidden">
<table id="table_transaction" style="width:100%; white-space:nowrap; border-collapse: collapse;" border=1>
<tr>
<th>Transaction ID (Dont share with ANYONE!)</th>
<th>Type</th>
<th>Amount</th>
<th>Currency Type</th>
<th>Transaction Status</th>
<th>Initiated At</th>
<th>Confirmed At</th>
</tr>
</table>
</div>
</div>
</div>
</div>
<!-- Market -->
<div class="w3-container w3-padding-64 w3-gray w3-center w3-wide" id="market">
<h1>CHECK OUT THE MARKET</h1>
<p class="w3-xlarge">
<button onclick="window.location.href = 'https://coinmarketcap.com/';" class="w3-button w3-round w3-white w3-opacity w3-hover-opacity-off" style="padding:8px 60px">Crypto Market</button>
</p>
</div>
<!-- Footer -->
<footer class="w3-center w3-black w3-padding-16">
<p>Powered by <a href="https://zabo.com/" title="Zabo" target="_blank" class="w3-hover-text-green">Zabo</a></p>
</footer>
<div class="w3-hide-small" style="margin-bottom:32px"> </div>
<!-- SCRIPT STARTS HERE -->
<script src="https://cdn.zabo.com/0.5.1/zabo.js"></script>
<script type="text/javascript">
document.getElementById('connect_display').innerHTML="Connect"
var cur_currencies = [];
// Wait for document to fully load
document.onreadystatechange = () => {
if (document.readyState !== 'complete') { return }
const output = document.querySelector('#output')
// Initiate Zabo SDK, replace the `clientId` field with your app key generated at {LINK}.
Zabo.init({
clientId: 'J28kJ68mHfiXSYLqyoujgFA4mCrRGxBiUkELZS1YImTyD4DAhNmR9VZqpiFpqRUV',
env: 'sandbox'
})
// Bind "connect" button
document.querySelector('#connect').addEventListener('click', ev => {
// Call connect when pressed and provide default .connect() window.
Zabo.connect().onConnection(account => {
console.log('account connected: ',account)
unhide('table_connect')
unhide('table_transact')
document.getElementById('connect_display').innerHTML="Connected"
// var jsonStr = JSON.stringify(account)
document.getElementById('walletProvider').innerHTML = account.wallet_provider_display_name;
document.getElementById('curren').innerHTML = "";
for(var i=0;i<account.currencies.length;i++) {
var curr = account.currencies[i];
console.log('1');
document.getElementById('curren').innerHTML += curr.currency + ", ";
cur_currencies.push(curr.currency)
}
console.log(cur_currencies)
document.getElementById('trans').innerHTML = cur_currencies;
bindOtherMethods()
})
.onError(error => {
console.error('account connection error:', error.message)
})
})
}
function generateCanvas(balances = []) {
console.log(balances);
var labels = balances.map(function(e) {
return e.currency;
});
var data = balances.map(function(e) {
return e.balance;
});
var ctx = document.getElementById("canvas").getContext('2d');
var config = {
animationEnabled: true,
type: 'bar',
data: {
labels: labels,
datasets: [{
label: 'Graph Line',
data: data,
backgroundColor: 'rgba(34, 28, 201, 1)'
}]
}
};
var chart = new Chart(ctx,config);
}
function unhide(divID) {
var item = document.getElementById(divID);
if (item) {
if(item.className=='hidden') {
item.className = 'unhidden';
}
}
}
// function addCell(tr, val) {
// var td = document.createElement('td');
// td.innerHTML = val;
// tr.appendChild(td)
// }
// function addRow(table, val1, val2, val3) {
// var tr = document.createElement('tr');
// addCell(tr, val1);
// addCell(tr, val2);
// addCell(tr, val3);
// table.appendChild(tr)
// }
function generateBalance(balance) {
const myNode = document.getElementById('balance_table');
while(myNode.firstChild) {
myNode.removeChild(myNode.firstChild);
}
var balance_table=document.getElementById('balance_table');
var tb1=document.createElement('table');
for(var i=0;i<balance.length+1;i++) {
var tr = document.createElement('tr');
if(i<1) {
var td4 = document.createElement('td');
var td5 = document.createElement('td');
var td6 = document.createElement('td');
var text4 = document.createTextNode('Crypto-Currency');
var text5 = document.createTextNode('Current Balance');
var text6 = document.createTextNode('Last Updated');
td4.appendChild(text4);
td5.appendChild(text5);
td6.appendChild(text6);
tr.appendChild(td4);
tr.appendChild(td5);
tr.appendChild(td6);
tb1.appendChild(tr);
}
// addRow(balance_table, balance[i].currency, balance[i].balance, balance[i].updated_at);
else {
var td1 = document.createElement('td');
var td2 = document.createElement('td');
var td3 = document.createElement('td');
var text1 = document.createTextNode(balance[i-1].currency);
var text2 = document.createTextNode(balance[i-1].balance);
var text3 = document.createTextNode(balance[i-1].updated_at);
td1.appendChild(text1);
td2.appendChild(text2);
td3.appendChild(text3);
tr.appendChild(td1);
tr.appendChild(td2);
tr.appendChild(td3);
tb1.appendChild(tr);
}
}
balance_table.appendChild(tb1);
}
function generateTransaction(transactions) {
console.log(transactions);
const myNode = document.getElementById('table_transaction');
while(myNode.firstChild) {
myNode.removeChild(myNode.firstChild);
}
var table_transaction=document.getElementById('table_transaction');
var tb1=document.createElement('table');
for(var i=0;i<transactions.length+1;i++) {
var tr = document.createElement('tr');
if(transactions.length==0) {
var td1 = document.createElement('td');
var text1 = document.createTextNode('No Transactions Found.');
td1.appendChild(text1);
tr.appendChild(td1);
tb1.appendChild(tr);
break;
}
else if(i<1) {
var td1 = document.createElement('td');
var td2 = document.createElement('td');
var td3 = document.createElement('td');
var td4 = document.createElement('td');
var td5 = document.createElement('td');
var td6 = document.createElement('td');
var td7 = document.createElement('td');
var text1 = document.createTextNode('Transaction ID');
var text2 = document.createTextNode('Type');
var text3 = document.createTextNode('Amount');
var text4 = document.createTextNode('Currency Type');
var text5 = document.createTextNode('Transaction Status');
var text6 = document.createTextNode('Initiated At');
var text7 = document.createTextNode('Confirmed At');
td1.appendChild(text1);
td2.appendChild(text2);
td3.appendChild(text3);
td4.appendChild(text4);
td5.appendChild(text5);
td6.appendChild(text6);
td7.appendChild(text7);
tr.appendChild(td1);
tr.appendChild(td2);
tr.appendChild(td3);
tr.appendChild(td4);
tr.appendChild(td5);
tr.appendChild(td6);
tr.appendChild(td7);
tb1.appendChild(tr);
}
else {
var td1 = document.createElement('td');
var td2 = document.createElement('td');
var td3 = document.createElement('td');
var td4 = document.createElement('td');
var td5 = document.createElement('td');
var td6 = document.createElement('td');
var td7 = document.createElement('td');
var text1 = document.createTextNode(transactions[i-1].id);
var text2 = document.createTextNode(transactions[i-1].type);
var text3 = document.createTextNode(transactions[i-1].amount);
var text4 = document.createTextNode(transactions[i-1].type);
var text5 = document.createTextNode(transactions[i-1].status);
var text6 = document.createTextNode(transactions[i-1].initiated_at);
var text7 = document.createTextNode(transactions[i-1].confirmed_at);
td1.appendChild(text1);
td2.appendChild(text2);
td3.appendChild(text3);
td4.appendChild(text4);
td5.appendChild(text5);
td6.appendChild(text6);
td7.appendChild(text7);
tr.appendChild(td1);
tr.appendChild(td2);
tr.appendChild(td3);
tr.appendChild(td4);
tr.appendChild(td5);
tr.appendChild(td6);
tr.appendChild(td7);
tb1.appendChild(tr);
}
}
table_transaction.appendChild(tb1);
}
function generateExchange(exchange) {
console.log(exchange);
const myNode = document.getElementById('exchange_table');
while(myNode.firstChild) {
myNode.removeChild(myNode.firstChild);
}
var exchange_table=document.getElementById('exchange_table');
var tb1=document.createElement('table');
for(var i=0;i<exchange.length+1;i++) {
var tr = document.createElement('tr');
if(i<1) {
var td1 = document.createElement('td');
var td2 = document.createElement('td');
var td3 = document.createElement('td');
var text1 = document.createTextNode("Currency");
var text2 = document.createTextNode("USD");
var text3 = document.createTextNode("Last Updated");
td1.appendChild(text1);
td2.appendChild(text2);
td3.appendChild(text3);
tr.appendChild(td1);
tr.appendChild(td2);
tr.appendChild(td3);
tb1.appendChild(tr);
}
else {
var td1 = document.createElement('td');
var td2 = document.createElement('td');
var td3 = document.createElement('td');
var text1 = document.createTextNode(exchange[i-1].from);
var text2 = document.createTextNode(exchange[i-1].rate);
var text3 = document.createTextNode(exchange[i-1].timestamp);
td1.appendChild(text1);
td2.appendChild(text2);
td3.appendChild(text3);
tr.appendChild(td1);
tr.appendChild(td2);
tr.appendChild(td3);
tb1.appendChild(tr);
}
}
exchange_table.appendChild(tb1);
}
// Bind buttons for the other SDK example methods [Requires a successful Zabo.connect() first]
const bindOtherMethods = () => {
document.querySelector('#balance').addEventListener('click', ev => {
// Get ETH balance
var tkrs = "";
for(var i=0;i<cur_currencies.length;i++) {
if(i>0)
tkrs+=',';
tkrs+=cur_currencies[i];
}
// var jsonStr = JSON.stringify(tkrs)
console.log(tkrs)
Zabo.accounts.getBalances({tickers: tkrs}).then(balances => {
generateBalance(balances.data);
unhide('table_balance');
generateCanvas(balances.data);
}).catch(error => {
/* User has not yet connected or doesn't have an ether wallet */
console.error(error)
})
})
document.querySelector('#history').addEventListener('click', ev => {
// Get account transactions history
Zabo.transactions.getTransactionHistory({ currencyTicker: document.getElementById("tic").value }).then(history => {
console.log(history)
generateTransaction(history.data)
unhide('transaction_table')
}).catch(error => {
/* User has not yet connected */
console.error(error)
})
})
document.querySelector('#exchangeRates').addEventListener('click', ev => {
// Get crypto USD exchange rates
Zabo.currencies.getExchangeRates().then(rates => {
console.log(rates)
generateExchange(rates.data)
document.getElementById('table_exchange').classList.remove('hidden')
unhide('table_exchange')
}).catch(error => {
console.error(error)
})
})
}
</script>
<span id="myAccount"></span>
<script src="vendor/jquery/jquery-3.2.1.min.js"></script>
<!--===============================================================================================-->
<script src="vendor/bootstrap/js/popper.js"></script>
<script src="vendor/bootstrap/js/bootstrap.min.js"></script>
<!--===============================================================================================-->
<script src="vendor/select2/select2.min.js"></script>
<!--===============================================================================================-->
<script src="js/main.js"></script>
</body>
</html>