-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetNumOutstanding.js
25 lines (22 loc) · 1.13 KB
/
getNumOutstanding.js
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
document.addEventListener("DOMContentLoaded", function() {
const elementsWithAssetCodeToReplaceWithOutstanding = document.querySelectorAll("[asset-code]");
elementsWithAssetCodeToReplaceWithOutstanding.forEach(element => {
const code = element.getAttribute("asset-code");
// logic here for outstanding, float, otherInfo
getNumOutstanding(code).then(outstanding => setOutstanding(element, outstanding, code));
});
function getNumOutstanding(code) {
return fetch(`https://api.blocktransfer.com/assets/${code}/outstanding`)
.then(response => (response.status === 200 ? response.text() : undefined));
}
function setOutstanding(element, outstanding, code) {
const astrix = "<span style='font-size: 0.8em; vertical-align: top;'>*</span>";
element.innerHTML = `${formatNum(outstanding)} Shares Outstanding${astrix}`;
}
function formatNum(raw) {
let [integerPart, decimalPart] = raw.toString().split(".");
integerPart = parseInt(integerPart).toLocaleString("en-US");
const isDecimal = parseInt(decimalPart);
return isDecimal ? `${integerPart}.${decimalPart.replace(/0+$/, "")}` : integerPart;
}
});