From 33f0fac8b5f95fdbb2294cebee79e8c9d136cbc0 Mon Sep 17 00:00:00 2001 From: jmacxx <47253594+jmacxx@users.noreply.github.com> Date: Tue, 3 Nov 2020 21:47:01 -0600 Subject: [PATCH] Add footer row with column totals Fixes #528 --- track-repayments.html | 90 ++++++++++++++++++++++++++++--------------- 1 file changed, 59 insertions(+), 31 deletions(-) diff --git a/track-repayments.html b/track-repayments.html index fd13ba8..af2ea45 100644 --- a/track-repayments.html +++ b/track-repayments.html @@ -80,11 +80,19 @@

Apr 2020 security incident repayment report

var jmcData = { - globalAccounts: null, + work: { + accounts: [], + total_btc_lost: 0.0, + total_usd_lost: 0.0, + total_btc_received: 0.0, + total_usd_received: 0.0, + transaction_count: 0, + first_seen_receiving: null, + blockchairStatus: null + }, // grab the static source data required to make the report (repayment_address, etc) prepareData: function() { - var strJson = '{"accounts": [ '; var lines = document.getElementById('phrase').value.split('\n'); var count = 0; while (lines.length > 0) { @@ -94,26 +102,27 @@

Apr 2020 security incident repayment report

if (fields[0].trim() == "ID") continue; // ignore header line if (fields.length >= 4) { - if (count > 0) { strJson += ','; } - strJson += '{ "id":"'+ fields[0].trim() + '"'; - strJson += ', "btc_lost":"'+ fields[1].trim() + '"'; - strJson += ', "usd_value":"'+ fields[2].trim() + '"'; - strJson += ', "repayment_address":"'+ fields[3].trim() + '"'; - strJson += ', "btc_received":"0"'; - strJson += ', "usd_received":"0"'; - strJson += '}'; + var account = { + id: fields[0].trim(), + btc_lost: Number(fields[1].trim().replace(/\,/g, '')), + usd_value: Number(fields[2].trim().replace(/[\$\,]/g, '')), + repayment_address: fields[3].trim(), + btc_received: 0.0, + usd_received: 0.0 + }; + this.work.accounts.push(account); + this.work.total_btc_lost += account.btc_lost; + this.work.total_usd_lost += account.usd_value; } count = count + 1; } - strJson += '], "transaction_count":"0"}'; - globalAccounts = JSON.parse(strJson); }, // get list of addresses for which we are reporting on getAddressList: function() { var retVal = ""; - var all_info = globalAccounts.accounts; + var all_info = this.work.accounts; for (const i of all_info) { if (i.repayment_address != "TBD") { if (retVal.length > 0) { retVal += ","; } @@ -125,22 +134,24 @@

Apr 2020 security incident repayment report

// populate the report data with information retrieved from blockchair setAmounts: function(repayment_address, btc_received, usd_received) { - var all_info = globalAccounts.accounts; + var all_info = this.work.accounts; for (const i of all_info) { if (i.repayment_address == repayment_address) { i.btc_received = btc_received; i.usd_received = usd_received; + this.work.total_btc_received += btc_received; + this.work.total_usd_received += usd_received; } } }, - // populate the report data with information retrieved from blockchair - setTransactionCount: function(transaction_count) { - globalAccounts.transaction_count = transaction_count; - }, - // write the report into an HTML table - updateDocument: function(status) { + updateDocument: function(data) { + data.pct_btc_received = + 100*(data.total_btc_received / data.total_btc_lost); + data.pct_usd_received = + 100*(data.total_usd_received / data.total_usd_lost); + var results = ""; results += "" +"" @@ -149,20 +160,38 @@

Apr 2020 security incident repayment report

+"" +"" +"\n"; - var all_info = globalAccounts.accounts; + var all_info = data.accounts; for (const i of all_info) { results += "" +"" +"" +"" +"" - +"" + +"" +"" +"\n"; } + results += "" + +"" + +"" + +"" + +"" + +"" + +"" + +"\n"; + + results += "" + +"" + +"" + +"" + +"" + +"" + +"" + +"\n"; results += "
IDBTC receivedUSD valueUSD received
" + i.id.toString() + "" + i.repayment_address + "" + i.btc_lost.toString() + "" + i.btc_received.toString() + "" + i.usd_value.toString() + "$" + i.usd_value.toString() + "$" + Number(i.usd_received).toFixed(2) + "
" + "totals" + "" + " " + "" + data.total_btc_lost.toString() + "" + data.total_btc_received.toFixed(8) + "$" + data.total_usd_lost.toString() + "$" + data.total_usd_received.toFixed(2) + "
" + " " + "" + " " + "" + " " + "" + data.pct_btc_received.toFixed(2) + "%" + " " + "" + data.pct_usd_received.toFixed(2) + "%
\n"; - results += "

Transaction count: " + globalAccounts.transaction_count.toString() + "
\n"; - if (status != null) { results += "

Blockchair status: " + status + "
\n"; } + results += "

First seen receiving: " + data.first_seen_receiving + "
\n"; + results += "

Transaction count: " + data.transaction_count.toString() + "
\n"; + if (data.blockchairStatus != null) { results += "

Blockchair status: " + data.blockchairStatus + "
\n"; } document.getElementById('results').innerHTML = results; document.body.style.cursor = 'auto'; }, @@ -198,24 +227,23 @@

Apr 2020 security incident repayment report

{ if (req.readyState > 3) { - debugger; if (req.responseText.length > 0) { var data = JSON.parse(req.responseText); if ((data.context && data.data) && data.context.code =='200'){ var all_info = data.data.addresses; for (var m in all_info){ var o = all_info[m]; - var received = ((o.received.toString()*1)/100000000).toFixed(8); - var received_usd = o.received_usd; + var received = Number(((o.received.toString()*1)/100000000).toFixed(8)); + var received_usd = Number(o.received_usd); jmcData.setAmounts(m, received, received_usd); } - jmcData.setTransactionCount(data.data.set.transaction_count); + jmcData.work.first_seen_receiving = data.data.set.first_seen_receiving; + jmcData.work.transaction_count = data.data.set.transaction_count; } - var blockchairStatus = null; if ((data.context && typeof data.context.error !== 'undefined')){ - blockchairStatus = data.context.error.toString(); + jmcData.work.blockchairStatus = data.context.error.toString(); } - jmcData.updateDocument(blockchairStatus); + jmcData.updateDocument(jmcData.work); } } };