Browse Source

Fix #19

- Support for displaying all currency values in your unit of choice
- Header menu for changing user settings (currency unit, and display width currently)
fix-133-memory-crash
Dan Janosik 7 years ago
parent
commit
e780ead3fe
  1. 31
      app.js
  2. 18
      app/utils.js
  3. 10
      routes/baseActionsRouter.js
  4. 12
      views/includes/block-content.pug
  5. 42
      views/layout.pug
  6. 4
      views/mempool-summary.pug
  7. 18
      views/transaction.pug

31
app.js

@ -78,6 +78,37 @@ app.use(function(req, res, next) {
res.locals.genesisBlockHash = rpcApi.getGenesisBlockHash(); res.locals.genesisBlockHash = rpcApi.getGenesisBlockHash();
res.locals.genesisCoinbaseTransactionId = rpcApi.getGenesisCoinbaseTransactionId(); res.locals.genesisCoinbaseTransactionId = rpcApi.getGenesisCoinbaseTransactionId();
// currency format type
if (!req.session.currencyFormatType) {
var cookieValue = req.cookies['user-setting-currencyFormatType'];
if (cookieValue) {
req.session.currencyFormatType = cookieValue;
} else {
req.session.currencyFormatType = "";
}
}
res.locals.currencyFormatType = req.session.currencyFormatType;
// display width
if (!req.session.displayWidth) {
var cookieValue = req.cookies['user-setting-displayWidth'];
if (cookieValue) {
req.session.displayWidth = cookieValue;
} else {
req.session.displayWidth = "container";
}
}
res.locals.displayWidth = req.session.displayWidth;
if (!["/", "/connect"].includes(req.originalUrl)) { if (!["/", "/connect"].includes(req.originalUrl)) {
if (utils.redirectToConnectPageIfNeeded(req, res)) { if (utils.redirectToConnectPageIfNeeded(req, res)) {
return; return;

18
app/utils.js

@ -99,6 +99,21 @@ function formatBytes(bytesInt) {
return bytesInt + " B"; return bytesInt + " B";
} }
function formatBtcAmount(amountBtc, formatType) {
if (formatType == "btc" || formatType == "") {
return amountBtc + " " + formatType;
} else if (formatType == "mbtc") {
return (amountBtc * 1000.0).toLocaleString() + " " + formatType;
} else if (formatType == "ubtc") {
return (amountBtc * 1000000.0).toLocaleString() + " " + formatType;
} else if (formatType == "bits") {
return (amountBtc * 1000000.0).toLocaleString() + " " + formatType;
}
}
module.exports = { module.exports = {
doSmartRedirect: doSmartRedirect, doSmartRedirect: doSmartRedirect,
@ -107,5 +122,6 @@ module.exports = {
getBlockReward: getBlockReward, getBlockReward: getBlockReward,
splitArrayIntoChunks: splitArrayIntoChunks, splitArrayIntoChunks: splitArrayIntoChunks,
getRandomString: getRandomString, getRandomString: getRandomString,
formatBytes: formatBytes formatBytes: formatBytes,
formatBtcAmount: formatBtcAmount
}; };

10
routes/baseActionsRouter.js

@ -159,6 +159,16 @@ router.get("/disconnect", function(req, res) {
res.redirect("/"); res.redirect("/");
}); });
router.get("/changeSetting", function(req, res) {
if (req.query.name) {
req.session[req.query.name] = req.query.value;
res.cookie('user-setting-' + req.query.name, req.query.value);
}
res.redirect(req.headers.referer);
});
router.get("/blocks", function(req, res) { router.get("/blocks", function(req, res) {
var limit = 20; var limit = 20;
var offset = 0; var offset = 0;

12
views/includes/block-content.pug

@ -139,8 +139,8 @@ div(class="tab-content")
th 1 th 1
td td
span(class="tag monospace") coinbase span(class="tag monospace") coinbase
span(class="monospace") Newly minted BTC span(class="monospace") Newly minted coins
td(class="monospace") #{utils.getBlockReward(result.getblock.height)} td(class="monospace") #{utils.formatBtcAmount(utils.getBlockReward(result.getblock.height), currencyFormatType)}
each txInput, txInputIndex in result.txInputsByTransaction[tx.txid] each txInput, txInputIndex in result.txInputsByTransaction[tx.txid]
if (txInput) if (txInput)
@ -159,7 +159,7 @@ div(class="tab-content")
td td
if (vout.value) if (vout.value)
- totalInputValue = totalInputValue.plus(new Decimal(vout.value)); - totalInputValue = totalInputValue.plus(new Decimal(vout.value));
span(class="monospace") #{vout.value} span(class="monospace") #{utils.formatBtcAmount(vout.value, currencyFormatType)}
- var coinbaseCount = tx.vin[0].coinbase ? 1 : 0; - var coinbaseCount = tx.vin[0].coinbase ? 1 : 0;
if ((tx.vin.length - coinbaseCount) > result.txInputsByTransaction[tx.txid].length) if ((tx.vin.length - coinbaseCount) > result.txInputsByTransaction[tx.txid].length)
@ -173,7 +173,7 @@ div(class="tab-content")
td td
td td
td td
strong(class="monospace") #{totalInputValue} strong(class="monospace") #{utils.formatBtcAmount(totalInputValue, currencyFormatType)}
div(class="col-md-6") div(class="col-md-6")
@ -204,14 +204,14 @@ div(class="tab-content")
span(class="monospace") OP_RETURN: span(class="monospace") OP_RETURN:
span(class="monospace text-muted") #{utils.hex2ascii(vout.scriptPubKey.asm.substring("OP_RETURN ".length))} span(class="monospace text-muted") #{utils.hex2ascii(vout.scriptPubKey.asm.substring("OP_RETURN ".length))}
td td
span(class="monospace") #{vout.value} span(class="monospace") #{utils.formatBtcAmount(vout.value, currencyFormatType)}
- totalOutputValue = totalOutputValue.plus(vout.value); - totalOutputValue = totalOutputValue.plus(vout.value);
tr tr
td td
td td
td td
strong(class="monospace") #{totalOutputValue} strong(class="monospace") #{utils.formatBtcAmount(totalOutputValue, currencyFormatType)}
//pre //pre
// code #{JSON.stringify(tx, null, 4)} // code #{JSON.stringify(tx, null, 4)}

42
views/layout.pug

@ -19,7 +19,7 @@ html
body body
nav(class="navbar navbar-expand-lg navbar-dark bg-dark mb-4") nav(class="navbar navbar-expand-lg navbar-dark bg-dark mb-4")
div(class="container") div(class=displayWidth)
a(class="navbar-brand", href="/") a(class="navbar-brand", href="/")
span span
img(src="/img/logo/logo-64.png", class="header-image") img(src="/img/logo/logo-64.png", class="header-image")
@ -31,18 +31,46 @@ html
div(class="collapse navbar-collapse", id="navbarNav") div(class="collapse navbar-collapse", id="navbarNav")
if (client) if (client)
ul(class="navbar-nav mr-auto") ul(class="navbar-nav mr-auto")
if (debug)
li(class="nav-item") li(class="nav-item")
a(href="/rpc-terminal", class="nav-link") RPC Terminal a(href="/node-details", class="nav-link")
li(class="nav-item") i(class="fas fa-info-circle")
a(href="/node-details", class="nav-link") Node Details span Node Details
li(class="nav-item dropdown")
a(class="nav-link dropdown-toggle", href="javascript:void(0)", id="navbarDropdown", role="button", data-toggle="dropdown", aria-haspopup="true", aria-expanded="false")
i(class="fas fa-cog")
span Settings
div(class="dropdown-menu", aria-labelledby="navbarDropdown")
span(class="dropdown-header") Currency Units
a(class="dropdown-item", href="/changeSetting?name=currencyFormatType&value=")
if (currencyFormatType == "btc" || currencyFormatType == "")
i(class="fas fa-check")
span BTC
a(class="dropdown-item", href="/changeSetting?name=currencyFormatType&value=mbtc")
if (currencyFormatType == "mbtc")
i(class="fas fa-check")
span mbtc
a(class="dropdown-item", href="/changeSetting?name=currencyFormatType&value=bits")
if (currencyFormatType == "bits")
i(class="fas fa-check")
span bits
div(class="dropdown-divider")
span(class="dropdown-header") Display Width
a(class="dropdown-item", href="/changeSetting?name=displayWidth&value=container")
if (displayWidth == "container")
i(class="fas fa-check")
span Centered
a(class="dropdown-item", href="/changeSetting?name=displayWidth&value=container-fluid")
if (displayWidth == "container-fluid")
i(class="fas fa-check")
span Full Width
form(method="post", action="/search", class="form-inline") form(method="post", action="/search", class="form-inline")
div(class="input-group") div(class="input-group")
input(type="text", class="form-control form-control-sm", name="query", placeholder="block height, block hash, txid", value=(query), style="width: 250px;") input(type="text", class="form-control form-control-sm", name="query", placeholder="block height, block hash, txid", value=(query), style="width: 250px;")
span(class="input-group-btn") span(class="input-group-btn")
input(type="submit", class="btn btn-primary", value="Search") input(type="submit", class="btn btn-primary", value="Search")
div(class="container mb-4", style="margin-top: -1.0rem;") div(class=(displayWidth + " mb-4"), style="margin-top: -1.0rem;")
ul(class="nav") ul(class="nav")
li(class="nav-item") li(class="nav-item")
a(href="/rpc-browser", class="nav-link") RPC Browser a(href="/rpc-browser", class="nav-link") RPC Browser
@ -55,7 +83,7 @@ html
hr hr
div(class="container") div(class=displayWidth)
if (userMessage) if (userMessage)
div(class="alert", class=(userMessageType ? ("alert-" + userMessageType) : "alert-info"), role="alert") div(class="alert", class=(userMessageType ? ("alert-" + userMessageType) : "alert-info"), role="alert")
span !{userMessage} span !{userMessage}

4
views/mempool-summary.pug

@ -28,7 +28,7 @@ block content
td(class="monospace") #{getmempoolinfo.mempoolminfee.toLocaleString()} td(class="monospace") #{getmempoolinfo.mempoolminfee.toLocaleString()}
tr tr
th(class="table-active properties-header") Total Fees th(class="table-active properties-header") Total Fees
td(class="monospace") #{mempoolstats.totalFee.toLocaleString()} td(class="monospace") #{utils.formatBtcAmount(mempoolstats.totalFee, currencyFormatType)}
h4 Transaction count by fee level h4 Transaction count by fee level
@ -49,7 +49,7 @@ block content
script var feeBucketLabels = []; script var feeBucketLabels = [];
each feeBucketLabel, index in feeBucketLabels each feeBucketLabel, index in feeBucketLabels
- var percentTx = Math.round(100 * feeBucketTxCounts[index] / getmempoolinfo.size).toLocaleString(); - var percentTx = Math.round(100 * feeBucketTxCounts[index] / getmempoolinfo.size).toLocaleString();
script feeBucketLabels.push(["#{feeBucketLabel}","#{feeBucketTxCounts[index]} tx (#{percentTx}%)","#{totalfeeBuckets[index].toLocaleString()} BTC"]); script feeBucketLabels.push(["#{feeBucketLabel}","#{feeBucketTxCounts[index]} tx (#{percentTx}%)","#{utils.formatBtcAmount(totalfeeBuckets[index], currencyFormatType)}"]);
script var feeBucketTxCounts = [#{feeBucketTxCounts}]; script var feeBucketTxCounts = [#{feeBucketTxCounts}];

18
views/transaction.pug

@ -116,13 +116,13 @@ block content
if (result.getrawtransaction.vin[0].coinbase) if (result.getrawtransaction.vin[0].coinbase)
tr tr
th(class="table-active properties-header") Total Network Fees th(class="table-active properties-header") Total Network Fees
td(class="monospace") #{new Decimal(totalOutputValue).minus(totalInputValue)} td(class="monospace") #{utils.formatBtcAmount(new Decimal(totalOutputValue).minus(totalInputValue), currencyFormatType)}
else else
tr tr
th(class="table-active properties-header") Network Fee Paid th(class="table-active properties-header") Network Fee Paid
td(class="monospace") td(class="monospace")
strong #{new Decimal(totalInputValue).minus(totalOutputValue)} strong #{utils.formatBtcAmount(new Decimal(totalInputValue).minus(totalOutputValue), currencyFormatType)}
span(class="text-muted") (#{totalInputValue} - #{totalOutputValue}) span(class="text-muted") (#{utils.formatBtcAmount(totalInputValue, currencyFormatType)} - #{utils.formatBtcAmount(totalOutputValue, currencyFormatType)})
br br
span ~#{new DecimalRounded(totalInputValue).minus(totalOutputValue).dividedBy(result.getrawtransaction.size).times(100000000)} sat/B span ~#{new DecimalRounded(totalInputValue).minus(totalOutputValue).dividedBy(result.getrawtransaction.size).times(100000000)} sat/B
@ -163,8 +163,8 @@ block content
th 1 th 1
td td
span(class="tag monospace") coinbase span(class="tag monospace") coinbase
span(class="monospace") Newly minted BTC span(class="monospace") Newly minted coins
td(class="monospace") #{utils.getBlockReward(result.getblock.height)} td(class="monospace") #{utils.formatBtcAmount(utils.getBlockReward(result.getblock.height), currencyFormatType)}
each txInput, txInputIndex in result.txInputs each txInput, txInputIndex in result.txInputs
if (txInput) if (txInput)
@ -182,13 +182,13 @@ block content
a(href=("/tx/" + txInput.txid + "#output-" + result.getrawtransaction.vin[txInputIndex].vout), class="monospace") #{txInput.txid.substring(0, 14)}..., Output ##{result.getrawtransaction.vin[txInputIndex].vout + 1} a(href=("/tx/" + txInput.txid + "#output-" + result.getrawtransaction.vin[txInputIndex].vout), class="monospace") #{txInput.txid.substring(0, 14)}..., Output ##{result.getrawtransaction.vin[txInputIndex].vout + 1}
td td
if (vout.value) if (vout.value)
span(class="monospace") #{vout.value} span(class="monospace") #{utils.formatBtcAmount(vout.value, currencyFormatType)}
tr tr
td td
td td
td td
strong(class="monospace") #{totalInputValue} strong(class="monospace") #{utils.formatBtcAmount(totalInputValue, currencyFormatType)}
div(class="col-md-6") div(class="col-md-6")
@ -217,13 +217,13 @@ block content
span(class="monospace") OP_RETURN: span(class="monospace") OP_RETURN:
span(class="monospace text-muted") #{utils.hex2ascii(vout.scriptPubKey.asm.substring("OP_RETURN ".length))} span(class="monospace text-muted") #{utils.hex2ascii(vout.scriptPubKey.asm.substring("OP_RETURN ".length))}
td td
span(class="monospace") #{vout.value} span(class="monospace") #{utils.formatBtcAmount(vout.value, currencyFormatType)}
tr tr
td td
td td
td td
strong(class="monospace") #{totalOutputValue} strong(class="monospace") #{utils.formatBtcAmount(totalOutputValue, currencyFormatType)}
div(id="tab-scripts", class="tab-pane", role="tabpanel") div(id="tab-scripts", class="tab-pane", role="tabpanel")
h3 Input Scripts h3 Input Scripts

Loading…
Cancel
Save