import "bootstrap/dist/css/bootstrap.min.css"; let state = {}; let url = "http://salmon.fluence.one:8080/"; let wsUrl = "ws://salmon.fluence.one:8080/"; window.onload = function () { getApps(); let list = document.getElementById("zoneList"); let coolZone = { name: "Cool Zone", nodesNumber: 12, lastHeight: 49771, binaryLink: "#" }; let coolStatus = { status: "in-progress", height: 3545 }; appendNewZone("cool-zone", coolZone, coolStatus); let iris = { name: "Iris", nodesNumber: 57, lastHeight: 12567, binaryLink: "#" }; let irisStatus = { status: "success" }; appendNewZone("iris", iris, irisStatus); let badZone = { name: "Bad Zone", nodesNumber: 4, lastHeight: 2566, binaryLink: "#" }; let nameStatus = { status: "error" }; let bzId = "bad-zone"; state[bzId] = {}; state[bzId].errorInfo = JSON.parse(`{ "height": "10", "txs": null, "signatures": [ { "validator_address": "7869301611744D2F6A5578EB001DB18BCC0AC705", "signature": "ruuvN8mPiKXniLc0JkblK4ol1oUHx3RuLDykik/DN8aiWXnWzPOPiLZrOLE0XbranEJpdErGalZnzShblUixAw==" } ] }`); appendNewZone(bzId, badZone, nameStatus); let buttonEl = document.getElementById("start-check"); buttonEl.addEventListener("click", function() { startCheckEvent() }); document.getElementById("name-service-hlp").onclick = function() { document.getElementById("node-ip").value = "207.154.210.117"; document.getElementById("node-port").value = "26657"; document.getElementById("binary-url").value = "QmQ69JoPDaKFpPSbWvvUGRGG5E83u6nTP2hRegmCoa6aW5"; document.getElementById("node-name").value = "nameservice"; }; document.getElementById("commercio-hlp").onclick = function() { document.getElementById("node-ip").value = "188.166.71.251 "; document.getElementById("node-port").value = "26657"; document.getElementById("binary-url").value = "QmepV645qHM9XR97KiK7Bvd2jjK3MiKTGbq8cYm7izRyQK"; document.getElementById("node-name").value = "commercionetwork"; }; }; function startCheckEvent() { let nodeIp = document.getElementById("node-ip").value; let port = document.getElementById("node-port").value; let binaryUrl = document.getElementById("binary-url").value; let name = document.getElementById("node-name").value; let params = { nodeIp: nodeIp, port: port, binaryUrl: binaryUrl, name: name }; let app = state.apps.find((r) => { return r.name === name }); let someInfo; if (app) { someInfo = { name: name, nodesNumber: 13, lastHeight: app.consensusHeight, binaryLink: app.binaryHash }; } else { // mock someInfo = { name: name, nodesNumber: 34, lastHeight: 48, binaryLink: "#" }; } startCheck(params, someInfo.name, someInfo); } function appendNewZone(id, info, status) { if (state[id]) { state[id].info = info; state[id].status = status; } else { state[id] = { info: info, status: status }; } let list = document.getElementById("zoneList"); if (!status) { status = { status: "in-progress", height: 0 }; } let zoneInfo = zoneElement(id, info, status); list.innerHTML = zoneInfo + list.innerHTML; if (status.status === "error") { setError(id, status.height) } } function setHeightAndWidth(el, currentHeight, lastHeight) { let percent = currentHeight / lastHeight * 100; el.style.width = `${percent}%`; el.innerHTML = `Height: ${currentHeight}`; } function changeHeight(el, currentHeight) { el.innerHTML = `Height: ${currentHeight}`; } function getInfo(id) { let el = document.getElementById(id); return el.getElementsByClassName("error-info")[0]; } function showError(id, btn) { let infoDiv = getInfo(id); let jsonInfo; console.log("ID === " + state[id].errorInfo); if (state[id].errorInfo) { jsonInfo = state[id].errorInfo; } else { let block = state[id].block; let signatures = block.last_commit.precommits.map((p) => { return { validator_address: p.validator_address, signature: p.signature } }); jsonInfo = { height: block.header.height, txs: block.data.txs, signatures: signatures }; } infoDiv.innerHTML = `
${JSON.stringify(jsonInfo, null, 2)}`; btn.innerHTML = "Hide Error"; } function hideError(id, btn) { let infoDiv = getInfo(id); infoDiv.innerHTML = ""; btn.innerHTML = "Show Error"; } function errorAction(btn, id) { showError(id, btn); } function unerrorAction(btn, id) { hideError(id, btn); } function genErrorButton(id) { let newBtn = document.createElement("button"); newBtn.type = "button"; newBtn.id = id + "-btn"; newBtn.style.width = "20%"; newBtn.classList.add("btn", "btn-block", "btn-danger"); newBtn.innerHTML = "Get Error Info"; return newBtn; } function setError(id, erroredHeight) { let el = getProgressBar(id); console.log("ERROR!!!!!!!!!!! " + erroredHeight); getBlock(id, erroredHeight).then((resp) => { return resp.text() }).then((r) => { console.log(JSON.parse(r)); state[id].block = JSON.parse(r).result.block; }); el.classList.add("progress-error"); let claimBtn = document.getElementById(id).getElementsByClassName("claim-btn")[0]; claimBtn.style.display = "block"; let btn = genErrorButton(id); state[id].swap = false; state[id].errorButton = btn; state[id].errorFunc = function(e) { console.log("error button clicked = " + id); if (state[id].swap) { unerrorAction(btn, id); state[id].swap = false; } else { errorAction(btn, id); state[id].swap = true; } }; el.parentElement.appendChild(btn); // to avoid `onclick` erasure for some reasons Object.keys(state).forEach(function(key) { if (state[key].errorButton) { document.getElementById(key).onclick = state[key].errorFunc } }); } function zoneElement(id, info, status) { let barStatus; let percent = "100"; let currentHeight = info.lastHeight; if (status.status === "success") { barStatus = "progress-bar" } else if (status.status === "error") { barStatus = "progress-bar progress-error" } else if (status.status === "in-progress") { barStatus = "progress-bar"; currentHeight = status.height; percent = currentHeight / info.lastHeight * 100; } return `
Name: ${info.name}
Validator Number: 4
Consensus Height: ${info.lastHeight}
Binary in IPFS: ${info.binaryLink}