ledger-ui/public/index.html

61 lines
1.8 KiB
HTML

<html>
<header>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/dark.css">
<script>
function init() {
http("get", "/ledger.json", (body, status) => {
body = JSON.parse(body)
loadTransactions(body.Transactions)
}, null)
}
function loadTransactions(transactions) {
if (transactions.length < 1) {
return
}
var innerHTML = ""
var keys = []
innerHTML += "<tr>"
innerHTML += "<th>" + "idx" + "</th>"
for(const key in transactions[0]) {
innerHTML += "<th>" + key + "</th>"
keys.push(key)
}
innerHTML += "</tr>"
for(var i in transactions) {
const transaction = transactions[i]
innerHTML += "<tr>"
innerHTML += "<th>" + i + "</th>"
for(var key of keys) {
innerHTML += "<td>" + transaction[key] + "</td>"
}
innerHTML += "</tr>"
}
document.getElementById("transactions").innerHTML = innerHTML
}
function http(method, remote, callback, body) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == XMLHttpRequest.DONE) {
callback(xmlhttp.responseText, xmlhttp.status)
}
};
xmlhttp.open(method, remote, true);
if (typeof body == "undefined") {
body = null
}
xmlhttp.send(body);
}
</script>
</header>
<body onload="init()">
<h1>hi</h1>
<table id="transactions">
</table>
</body>
<footer>
</footer>
</html>