diff --git a/app/utils.js b/app/utils.js index 01b2a95..ef65290 100644 --- a/app/utils.js +++ b/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))); } -function formatHashrate(val, 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) { +function formatLargeNumber(n, decimalPlaces) { for (var i = 0; i < exponentScales.length; i++) { var item = exponentScales[i]; - var fraction = new Decimal(d / item.val); + var fraction = new Decimal(n / item.val); if (fraction >= 1) { return [fraction.toDecimalPlaces(decimalPlaces), item]; } } - return [d, {}]; + return [n, {}]; } @@ -306,6 +289,5 @@ module.exports = { getBlockTotalFeesFromCoinbaseTxAndBlockHeight: getBlockTotalFeesFromCoinbaseTxAndBlockHeight, refreshExchangeRate: refreshExchangeRate, parseExponentStringDouble: parseExponentStringDouble, - formatHashrate: formatHashrate, - formatDifficulty: formatDifficulty + formatLargeNumber: formatLargeNumber }; diff --git a/views/index.pug b/views/index.pug index 5574b3f..f192cb7 100644 --- a/views/index.pug +++ b/views/index.pug @@ -44,7 +44,7 @@ block content tbody(class="monospace") tr - - var hashrateData = utils.formatHashrate(miningInfo.networkhashps, 3); + - var hashrateData = utils.formatLargeNumber(miningInfo.networkhashps, 3); td span #{hashrateData[0]} 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}) 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 #{difficultyData[0]} span x 10 sup #{difficultyData[1].exponent} - td #{mempoolInfo.size.toLocaleString()} tx - span(class="text-muted") (#{mempoolInfo.usage.toLocaleString()} bytes) + td #{mempoolInfo.size.toLocaleString()} tx / + - var mempoolBytesData = utils.formatLargeNumber(mempoolInfo.usage, 2); + span #{mempoolBytesData[0]} #{mempoolBytesData[1].abbreviation}B if (latestBlocks) div(class="card mb-3")