Browse Source

cleanup, simplification and more ui tweaks

fix-133-memory-crash
Dan Janosik 6 years ago
parent
commit
6ad03fa0ee
  1. 26
      app/utils.js
  2. 9
      views/index.pug

26
app/utils.js

@ -258,34 +258,17 @@ function parseExponentStringDouble(val) {
: lead + ( +pow >= decimal.length ? (decimal + "0".repeat(+pow-decimal.length)) : (decimal.slice(0,+pow)+"."+decimal.slice(+pow))); : lead + ( +pow >= decimal.length ? (decimal + "0".repeat(+pow-decimal.length)) : (decimal.slice(0,+pow)+"."+decimal.slice(+pow)));
} }
function formatHashrate(val, decimalPlaces) { function formatLargeNumber(n, decimalPlaces) {
console.log("formatting hashrate: " + val);
var x = parseExponentStringDouble(val);
for (var i = 0; i < exponentScales.length; i++) {
var item = exponentScales[i];
var fraction = new Decimal(x / item.val);
if (fraction >= 1) {
return [fraction.toDecimalPlaces(decimalPlaces), item];
}
}
return [x, {}];
}
function formatDifficulty(d, decimalPlaces) {
for (var i = 0; i < exponentScales.length; i++) { for (var i = 0; i < exponentScales.length; i++) {
var item = exponentScales[i]; var item = exponentScales[i];
var fraction = new Decimal(d / item.val); var fraction = new Decimal(n / item.val);
if (fraction >= 1) { if (fraction >= 1) {
return [fraction.toDecimalPlaces(decimalPlaces), item]; return [fraction.toDecimalPlaces(decimalPlaces), item];
} }
} }
return [d, {}]; return [n, {}];
} }
@ -306,6 +289,5 @@ module.exports = {
getBlockTotalFeesFromCoinbaseTxAndBlockHeight: getBlockTotalFeesFromCoinbaseTxAndBlockHeight, getBlockTotalFeesFromCoinbaseTxAndBlockHeight: getBlockTotalFeesFromCoinbaseTxAndBlockHeight,
refreshExchangeRate: refreshExchangeRate, refreshExchangeRate: refreshExchangeRate,
parseExponentStringDouble: parseExponentStringDouble, parseExponentStringDouble: parseExponentStringDouble,
formatHashrate: formatHashrate, formatLargeNumber: formatLargeNumber
formatDifficulty: formatDifficulty
}; };

9
views/index.pug

@ -44,7 +44,7 @@ block content
tbody(class="monospace") tbody(class="monospace")
tr tr
- var hashrateData = utils.formatHashrate(miningInfo.networkhashps, 3); - var hashrateData = utils.formatLargeNumber(miningInfo.networkhashps, 3);
td td
span #{hashrateData[0]} span #{hashrateData[0]}
span(title=(hashrateData[1].name + "-hash / x10^" + hashrateData[1].exponent), data-toggle="tooltip") #{hashrateData[1].abbreviation}H span(title=(hashrateData[1].name + "-hash / x10^" + hashrateData[1].exponent), data-toggle="tooltip") #{hashrateData[1].abbreviation}H
@ -53,15 +53,16 @@ block content
span(class="text-muted") (pruned: #{getblockchaininfo.pruned}) span(class="text-muted") (pruned: #{getblockchaininfo.pruned})
td td
- var difficultyData = utils.formatDifficulty(getblockchaininfo.difficulty, 3); - var difficultyData = utils.formatLargeNumber(getblockchaininfo.difficulty, 3);
span(title=parseFloat(getblockchaininfo.difficulty).toLocaleString(), data-toggle="tooltip") span(title=parseFloat(getblockchaininfo.difficulty).toLocaleString(), data-toggle="tooltip")
span #{difficultyData[0]} span #{difficultyData[0]}
span x 10 span x 10
sup #{difficultyData[1].exponent} sup #{difficultyData[1].exponent}
td #{mempoolInfo.size.toLocaleString()} tx td #{mempoolInfo.size.toLocaleString()} tx /
span(class="text-muted") (#{mempoolInfo.usage.toLocaleString()} bytes) - var mempoolBytesData = utils.formatLargeNumber(mempoolInfo.usage, 2);
span #{mempoolBytesData[0]} #{mempoolBytesData[1].abbreviation}B
if (latestBlocks) if (latestBlocks)
div(class="card mb-3") div(class="card mb-3")

Loading…
Cancel
Save