73 lines
1.8 KiB
JavaScript
73 lines
1.8 KiB
JavaScript
|
|
export function getPercentage(amount, goal) {
|
|
return ((Number(amount) / Number(goal)) * 100).toFixed(2);
|
|
}
|
|
|
|
// input type bigint
|
|
export function formatBigIntDivision(nominator, denominator) {
|
|
console.log("nominator", nominator);
|
|
console.log("denominator", denominator);
|
|
if (!nominator) {
|
|
return 0n
|
|
}
|
|
let integer = Number(nominator / denominator)
|
|
integer = formatNumber(integer).toString();
|
|
// pick how much digits after point to show
|
|
const fraction = (nominator % denominator).toString().substring(0,2);
|
|
// output type string
|
|
return integer + '.' + fraction;
|
|
}
|
|
|
|
export function formatNumber(number) {
|
|
const options = {
|
|
style: "decimal",
|
|
minimumFractionDigits: 0,
|
|
maximumFractionDigits: 0,
|
|
};
|
|
if (!number) {
|
|
return 0
|
|
}
|
|
const formattedWithOptions = number.toLocaleString("en-US", options);
|
|
return formattedWithOptions;
|
|
}
|
|
|
|
export function getAddressShortName(address) {
|
|
// const address = "0x66422602B2f4885c57EE794174f98d9E4DDBBBC6";
|
|
const addressBegin = address.substring(0, 6);
|
|
const addressEnd = address.substring(address.length - 4, address.length)
|
|
return addressBegin + "..." + addressEnd;
|
|
}
|
|
|
|
|
|
export function getblocky(address) {
|
|
var blockiesData = blockies
|
|
.create({
|
|
seed: address.toLowerCase(),
|
|
size: 8,
|
|
scale: 4,
|
|
})
|
|
.toDataURL();
|
|
|
|
return blockiesData;
|
|
}
|
|
|
|
export function debounce(func, timeout = 300) {
|
|
let timer;
|
|
return (...args) => {
|
|
clearTimeout(timer);
|
|
timer = setTimeout(() => {
|
|
return func.apply(this, args);
|
|
}, timeout);
|
|
};
|
|
}
|
|
|
|
export function createDebounce() {
|
|
let timeout = null;
|
|
return function (fnc, delayMs) {
|
|
clearTimeout(timeout);
|
|
timeout = setTimeout(() => {
|
|
fnc();
|
|
}, delayMs || 500);
|
|
};
|
|
}
|