From 94f8c97d1357aef35cb80a39663139fb46cd3ca2 Mon Sep 17 00:00:00 2001 From: joeuhren <46763106+joeuhren@users.noreply.github.com> Date: Fri, 20 Nov 2020 16:50:53 -0700 Subject: [PATCH] AddressTX: include balance history and show in address history --- app.js | 1 + lib/database.js | 14 +++++++++++++- models/addresstx.js | 3 ++- views/includes/address_history.pug | 7 +++++-- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/app.js b/app.js index 7f25059..b6d7ed2 100644 --- a/app.js +++ b/app.js @@ -213,6 +213,7 @@ app.use('/ext/getaddresstxsajax/:address', function(req,res){ row.push(txs[i].txid); row.push(out); row.push(vin); + row.push(txs[i].balance); data.push(row); } } diff --git a/lib/database.js b/lib/database.js index 2fc0a83..3c88491 100644 --- a/lib/database.js +++ b/lib/database.js @@ -90,6 +90,7 @@ function update_address(hash, txid, amount, type, cb) { if (typeof address_tx == "undefined") { var newAddressTx = new AddressTx({ a_id: hash, + balance: received - sent, txid: txid }); newAddressTx.save(function(err) { @@ -100,7 +101,13 @@ function update_address(hash, txid, amount, type, cb) { } }); } else { - return cb(); //duplicate + AddressTx.updateOne({a_id: hash, txid: txid}, { + a_id: hash, + balance: received - sent, + txid: txid + }, function() { + return cb(); + }); } }); }); @@ -127,6 +134,7 @@ function update_address(hash, txid, amount, type, cb) { } else { var newAddressTx = new AddressTx({ a_id: hash, + balance: amount, txid: txid }); newAddressTx.save(function(err) { @@ -514,9 +522,13 @@ module.exports = { var i = loop.iteration(); find_tx(hashes[i].txid, function (tx) { if (tx && !txs.includes(tx)) { + // tx = {...hashes[i], ...tx} + tx.balance = hashes[i].balance; txs.push(tx); loop.next(); } else if (!txs.includes(tx)) { + // tx = {...hashes[i], ...tx} + tx.balance = hashes[i].balance; txs.push("1. Not found"); loop.next(); } else { diff --git a/models/addresstx.js b/models/addresstx.js index 46517ca..5c52790 100644 --- a/models/addresstx.js +++ b/models/addresstx.js @@ -3,7 +3,8 @@ var mongoose = require('mongoose') var AddressTXSchema = new Schema({ a_id: { type: String, index: true}, - txid: { type: String, lowercase: true, index: true} + txid: { type: String, lowercase: true, index: true}, + balance: { type: Number, default: 0} }, {id: false}); module.exports = mongoose.model('AddressTx', AddressTXSchema); \ No newline at end of file diff --git a/views/includes/address_history.pug b/views/includes/address_history.pug index 74234be..cb9f0bf 100644 --- a/views/includes/address_history.pug +++ b/views/includes/address_history.pug @@ -25,6 +25,7 @@ script. var txhash = data[1]; //variables for better readability var out = data[2]; //variables for better readability var vin = data[3]; //variables for better readability + var balance = (data[4] / 100000000).toLocaleString('en',{'minimumFractionDigits':2,'maximumFractionDigits':8,'useGrouping':true}); //variables for better readability $("td:eq(0)", row).html(timestamp); $("td:eq(1)", row).html('' + txhash + ''); @@ -43,13 +44,14 @@ script. amount = amount.toLocaleString('en',{'minimumFractionDigits':2,'maximumFractionDigits':8,'useGrouping':true}); $("td:eq(2)", row).html(amount).addClass("info"); } - }else if(out > 0) { + } else if (out > 0) { amount = (out / 100000000).toLocaleString('en',{'minimumFractionDigits':2,'maximumFractionDigits':8,'useGrouping':true}); $("td:eq(2)", row).html("+" + amount).addClass("success"); - }else{ + } else { amount = (vin / 100000000).toLocaleString('en',{'minimumFractionDigits':2,'maximumFractionDigits':8,'useGrouping':true}); $("td:eq(2)", row).html("-" + amount).addClass("danger"); } + $("td:eq(3)", row).html(balance); }, }); @@ -60,4 +62,5 @@ table#address-txs.table.table-bordered.table-striped th.hidden-xs #{settings.locale.timestamp} th.hidden-xs #{settings.locale.tx_hash} th #{settings.locale.mkt_amount} (#{settings.symbol}) + th #{settings.locale.rl_balance} (#{settings.symbol}) tbody \ No newline at end of file