diff --git a/rootfs/standard/var/www/mynode/api.py b/rootfs/standard/var/www/mynode/api.py index 9d3dcbb9..abc93afa 100644 --- a/rootfs/standard/var/www/mynode/api.py +++ b/rootfs/standard/var/www/mynode/api.py @@ -55,6 +55,8 @@ def api_get_lightning_info(): data["lnd_ready"] = is_lnd_ready() data["balances"] = get_lightning_balance_info() data["channels"] = get_lightning_channels() + data["transactions"] = get_lightning_transactions() + data["payments_and_invoices"] = get_lightning_payments_and_invoices() return jsonify(data) diff --git a/rootfs/standard/var/www/mynode/lightning_info.py b/rootfs/standard/var/www/mynode/lightning_info.py index a8067b54..0627a599 100644 --- a/rootfs/standard/var/www/mynode/lightning_info.py +++ b/rootfs/standard/var/www/mynode/lightning_info.py @@ -272,6 +272,7 @@ def get_lightning_transactions(): transactions = [] data = copy.deepcopy(lightning_transactions) for tx in data["transactions"]: + tx["id"] = tx["tx_hash"] tx["amount_str"] = format_sat_amount(tx["amount"]) tx["date_str"] = time.strftime("%D %H:%M", time.localtime(int(tx["time_stamp"]))) transactions.append(tx) @@ -285,6 +286,7 @@ def get_lightning_payments(): payments = [] data = copy.deepcopy(lightning_payments) for tx in data["payments"]: + tx["id"] = tx["payment_hash"] tx["type"] = "PAYMENT" tx["value_str"] = format_sat_amount(tx["value_sat"]) tx["fee_str"] = format_sat_amount(tx["fee"]) @@ -294,7 +296,7 @@ def get_lightning_payments(): payments.reverse() return payments except: - return None + return [] def get_lightning_invoices(): global lightning_invoices @@ -302,6 +304,7 @@ def get_lightning_invoices(): invoices = [] data = copy.deepcopy(lightning_invoices) for tx in data["invoices"]: + tx["id"] = tx["r_hash"] tx["type"] = "INVOICE" tx["value_str"] = format_sat_amount(tx["value"]) tx["date_str"] = time.strftime("%D %H:%M", time.localtime(int(tx["creation_date"]))) @@ -310,7 +313,7 @@ def get_lightning_invoices(): invoices.reverse() return invoices except: - return None + return [] def get_lightning_payments_and_invoices(): payments = get_lightning_payments() @@ -318,13 +321,13 @@ def get_lightning_payments_and_invoices(): txs = [] if payments == None and invoices == None: - return None + return [] elif payments == None and invoices != None: return invoices elif payments != None and invoices == None: return payments elif len(payments) == 0 and len(invoices) == 0: - return None + return [] while len(payments) or len(invoices): if len(payments) == 0: diff --git a/rootfs/standard/var/www/mynode/templates/includes/services.html b/rootfs/standard/var/www/mynode/templates/includes/services.html index 3ac6f16d..17505214 100644 --- a/rootfs/standard/var/www/mynode/templates/includes/services.html +++ b/rootfs/standard/var/www/mynode/templates/includes/services.html @@ -191,12 +191,13 @@
On-chain Transactions - +
+
Date Amount
Lightning Transactions - +
+
Date Amount
diff --git a/rootfs/standard/var/www/mynode/templates/main.html b/rootfs/standard/var/www/mynode/templates/main.html index e7de7626..547c21c8 100644 --- a/rootfs/standard/var/www/mynode/templates/main.html +++ b/rootfs/standard/var/www/mynode/templates/main.html @@ -16,6 +16,8 @@ var electrs_active = {% if electrs_active %}1{% else %}0{% endif %}; var lnd_ready = {% if lnd_ready %}true{% else %}false{% endif %}; var is_installing_docker_images = {% if is_installing_docker_images %}true{% else %}false{% endif %}; + var lnd_last_btc_tx = ""; + var lnd_last_ln_tx = ""; // Toggle enable/disable functions function get_custom_enable_message(short_name) { @@ -104,6 +106,21 @@ window.location.href=location.protocol+'//'+location.hostname+"/"; } + function need_to_update_tx_table(transactions, last_displayed_tx) { + if (transactions.length > 0) { + tx = transactions[0]; + if (tx["id"] != last_displayed_tx) { + return true; + } + return false; + } else { + if (last_displayed_tx == "none") { + return false; + } + return true; + } + } + var showing_blocks = false; function toggleBlocks() { if (showing_blocks) { @@ -225,6 +242,78 @@ } } } + if ("transactions" in data && data["transactions"] != null) { + transactions = data["transactions"]; + if (need_to_update_tx_table(transactions, lnd_last_btc_tx)) { + // Clear table + while ($('#lnd_transactions tr').length > 1) { + $('#lnd_transactions tr:last').remove(); + } + for (i=0; i < transactions.length && i < {{lnd_tx_display_limit}}; i++) { + tx = transactions[i]; + //console.log(JSON.stringify(tx)) + if (i==0) {lnd_last_btc_tx = tx['id'];} + row = ""; + row += ""+tx['date_str']+""; + row += ""+tx['amount_str']+""; + row += ""; + if (tx["num_confirmations"] < 1) { row += ""; } + else if (tx["num_confirmations"] <= 3) { row += ""; } + else if (tx["num_confirmations"] > 3) { row += ""; } + row += ""; + row += ""; + $('#lnd_transactions tr:last').after(row); + } + if (transactions.length >= {{lnd_tx_display_limit}}) { + $('#lnd_transactions tr:last').after("more..."); + } + if (transactions.length == 0) { + lnd_last_btc_tx = "none"; + $('#lnd_transactions tr:last').after("

None yet!"); + } + } + } + if ("payments_and_invoices" in data && data["payments_and_invoices"] != null) { + payments_and_invoices = data["payments_and_invoices"]; + if (need_to_update_tx_table(payments_and_invoices, lnd_last_ln_tx)) { + // Clear table + while ($('#lnd_payments_and_invoices tr').length > 1) { + $('#lnd_payments_and_invoices tr:last').remove(); + } + for (i=0; i < payments_and_invoices.length && i < {{lnd_tx_display_limit}}; i++) { + tx = payments_and_invoices[i]; + //console.log(JSON.stringify(tx)) + if (i==0) {lnd_last_ln_tx = tx['id'];} + row = ""; + row += ""+tx['date_str']+""; + row += ""+tx['value_str']+""; + row += ""; + if (tx["type"] == "PAYMENT") { + row += ""; + } else { + row += ""; + } + if ("state" in tx && tx["state"] == "OPEN") { row += ""; } + if ("state" in tx && tx["state"] == "SETTLED") { row += ""; } + if ("state" in tx && tx["state"] == "CANCELED") { row += ""; } + if ("state" in tx && tx["state"] == "CANCELLED") { row += ""; } + + if ("memo" in tx && tx["memo"] != "") { + row += ""; + } + row += ""; + row += ""; + $('#lnd_payments_and_invoices tr:last').after(row); + } + if (payments_and_invoices.length >= {{lnd_tx_display_limit}}) { + $('#lnd_payments_and_invoices tr:last').after("more..."); + } + if (payments_and_invoices.length == 0) { + lnd_last_ln_tx = "none"; + $('#lnd_payments_and_invoices tr:last').after("

None yet!"); + } + } + } }); // Update app status