-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBadDebt.html
110 lines (107 loc) · 4.98 KB
/
BadDebt.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="author" content="J1Mtonic">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Venus Protocol: Bad Debts</title>
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<link rel="stylesheet" href="https://mottie.github.io/tablesorter/css/theme.blue.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto">
<script src="https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/tablesorter@latest/dist/js/jquery.tablesorter.combined.min.js"></script>
<style> body,h1,h2,h3,h4,h5 {font-family: "Roboto", sans-serif; font-size: 9pt;} </style>
</head>
<body onload="fetchDebtors();">
<table class="tblData tablesorter">
<thead>
<th class="sorter-false">Deposits</th>
<th class="sorter-false">Borrows</th>
<th class="sorter-false">TVL</th>
<th class="sorter-false">Debt</th>
<th class="sorter-false">Debtors</th>
<th class="sorter-false">Updated</th>
</thead>
<tbody>
</tbody>
</table>
<table id="tblDebtors" class="tblDebtors tablesorter">
<thead>
<th class="sorter-false">Address</th>
<th>Debt</th>
</thead>
<tbody>
</tbody>
</table>
<script type="text/javascript">
const debtorsContainer = document.createElement("div");
document.body.append(debtorsContainer);
async function fetchDebtors() {
fetch('https://raw.githubusercontent.com/Risk-DAO/simulation-results/main/bad-debt/latest/BSC_venus.json')
.then(response => response.json())
.then(renderData)
.catch(error => console.error('Error:', error));
}
function renderData(debtorsObject) {
$(function() { $(".tblData").tablesorter({theme : 'blue'});});
let addCtrl = "<tr>"
addCtrl += "<td>" + nFormatter(Math.abs(debtorsObject.deposits), 2) + "</td>"
addCtrl += "<td>" + nFormatter(Math.abs(debtorsObject.borrows), 2) + "</td>"
addCtrl += "<td>" + nFormatter(Math.abs(debtorsObject.tvl), 2) + "</td>"
addCtrl += "<td>" + nFormatter(Math.abs(debtorsObject.total), 2) + "</td>"
addCtrl += "<td>" + debtorsObject.users.length + "</td>"
addCtrl += "<td>" + new Date(debtorsObject.updated * 1000).toLocaleString() + "</td>"
addCtrl += "</tr>";
$(".tblData tbody").append(addCtrl);
let arrayDebtors = debtorsObject.users;
let i = 1;
$(function() { $(".tblDebtors").tablesorter({theme : 'blue'});});
Object.keys(arrayDebtors).forEach((key) => {
let User = arrayDebtors[key].user;
let BadDebt = Number(arrayDebtors[key].badDebt);
debtorRow(`${User}`, `${BadDebt}`);
});
$(function() { $(".tblDebtors").find("th:contains(Debt)").trigger("sort"); markDebtors();});
}
function debtorRow(user, baddebt) {
let addCtrl = "<tr>"
addCtrl += "<td>" + "<a href='https://debank.com/profile/" + user + "?chain=bsc' target='_blank'>" + user + "</a>" + "</td>"
addCtrl += "<td>" + baddebt + "</td>"
addCtrl += "</tr>";
$(".tblDebtors tbody").append(addCtrl);
}
function markDebtors() {
var table = document.getElementById("tblDebtors");
var rows = table.getElementsByTagName("tbody")[0].getElementsByTagName("tr");
for (var i = 0; i < rows.length; i++) {
var debtCell = rows[i].getElementsByTagName("td")[1];
var debtValue = parseFloat(debtCell.innerHTML);
debtCell.innerHTML = nFormatter(Math.abs(debtValue), 1);
}
}
function nFormatter(value, decimals) {
let venusdecimals = 1000000000000000000;
if (value < venusdecimals) return value = "<1"
else {
value = (value / venusdecimals).toString().replace(/[^0-9.]/g, "");
let si = [
{ value: 1, symbol: "" },
{ value: 1e3, symbol: "k" },
{ value: 1e6, symbol: "M" }
];
let i;
for (i = si.length - 1; i > 0; i--) {
if (value >= si[i].value) {
break;
}
}
return (
(value / si[i].value)
.toFixed(decimals)
.replace(/\.0+$|(\.[0-9]*[1-9])0+$/, "$1") + si[i].symbol
);
}
}
</script>
</body>
</html>