-
Notifications
You must be signed in to change notification settings - Fork 0
/
widget.html
62 lines (53 loc) · 2.26 KB
/
widget.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
<!DOCTYPE html>
<html>
<head>
<title>Crypton rate</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="widget.css" />
<link rel="icon" href="img/favicon.png" sizes="48x48" type="image/png">
</head>
<body>
<div class="widget" id="crypton-widget">
<img src="img/favicon.png" id="crypton-icon"/>
<div id="coin-name">Utopia Crypton</div>
<div id="crypton-rate">$0.6024</div>
<a href="https://www.coingecko.com/en/coins/crypton" target="_blank" class="widget-link" id="coingecko">
<img src="img/coingecko.png">
</a>
<a href="https://crp.is/exchange/crp_usdt" target="_blank" class="widget-link">
<img src="img/exchange.png">
</a>
<a href="https://www.lbank.com/trade/crp_usdt" target="_blank" class="widget-link" id="lbank">
<img src="img/lbank.png">
</a>
</div>
<script src="js/crypton-api.js?v1.0"></script>
<script>
var widgetRate = document.getElementById('crypton-rate');
function updateRate(newRate = 0.5) {
widgetRate.innerText = "$" + newRate;
}
// Wrap all the code in an async function
async function getRate() {
const API = new CryptonAPI(transport, saveToken);
try {
const response = await API.pairs(); // Waiting for response from API
const pairs = response.pairs;
const crpUsdtPair = pairs.find(pair => pair.pair.pair === 'crp_usdt');
if (crpUsdtPair) {
const closePrice = crpUsdtPair.data_market.close;
updateRate(closePrice);
} else {
console.log('Pair crp_usdt not found.');
}
} catch (error) {
console.error('Error while getting pairs:', error);
}
}
// Run the main function
getRate();
setInterval(getRate, 60000);
</script>
</body>
</html>