Add mempool fees and uptime to ticker

This commit is contained in:
Taylor Helsper 2022-02-17 21:03:06 -06:00
parent 468db64406
commit e66fede198
6 changed files with 88 additions and 38 deletions

View File

@ -34,6 +34,7 @@ def api_get_bitcoin_info():
data["peer_count"] = get_bitcoin_peer_count() data["peer_count"] = get_bitcoin_peer_count()
#data["difficulty"] = get_bitcoin_difficulty() # Dont send difficulty, it causes errors in jsonify #data["difficulty"] = get_bitcoin_difficulty() # Dont send difficulty, it causes errors in jsonify
data["mempool_size"] = get_bitcoin_mempool_size() data["mempool_size"] = get_bitcoin_mempool_size()
data["recommended_fees"] = get_bitcoin_recommended_fees()
# Add blocks # Add blocks
data["recent_blocks"] = None data["recent_blocks"] = None
@ -120,6 +121,7 @@ def api_get_device_info():
data["cpu"] = get_cpu_usage() data["cpu"] = get_cpu_usage()
data["ram"] = get_ram_usage() data["ram"] = get_ram_usage()
data["temp"] = get_device_temp() data["temp"] = get_device_temp()
data["uptime"] = get_system_uptime()
data["is_installing_docker_images"] = is_installing_docker_images() data["is_installing_docker_images"] = is_installing_docker_images()
data["is_electrs_active"] = is_electrs_active() data["is_electrs_active"] = is_electrs_active()

View File

@ -1,6 +1,8 @@
from config import * from config import *
from utilities import * from utilities import *
from systemctl_info import *
from threading import Timer from threading import Timer
import requests
from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException
import urllib import urllib
import subprocess import subprocess
@ -18,6 +20,7 @@ bitcoin_peers = []
bitcoin_network_info = None bitcoin_network_info = None
bitcoin_wallets = None bitcoin_wallets = None
bitcoin_mempool = None bitcoin_mempool = None
bitcoin_recommended_fees = None
bitcoin_version = None bitcoin_version = None
# Functions # Functions
@ -73,6 +76,7 @@ def update_bitcoin_other_info():
global bitcoin_peers global bitcoin_peers
global bitcoin_network_info global bitcoin_network_info
global bitcoin_mempool global bitcoin_mempool
global bitcoin_recommended_fees
global bitcoin_wallets global bitcoin_wallets
while bitcoin_blockchain_info == None: while bitcoin_blockchain_info == None:
@ -118,6 +122,22 @@ def update_bitcoin_other_info():
wallet_info = wallet_rpc_connection.getwalletinfo() wallet_info = wallet_rpc_connection.getwalletinfo()
wallet_data.append(wallet_info) wallet_data.append(wallet_info)
bitcoin_wallets = wallet_data bitcoin_wallets = wallet_data
# Get recommended fee info (from mempool on port 4080)
if is_service_enabled("mempool"):
try:
r = requests.get("http://localhost:4080/api/v1/fees/recommended", timeout=1)
data = r.json()
bitcoin_recommended_fees = ""
bitcoin_recommended_fees += "Low priority: {} sat/vB".format(data["hourFee"])
bitcoin_recommended_fees += "             "
bitcoin_recommended_fees += "Medium priority: {} sat/vB".format(data["halfHourFee"])
bitcoin_recommended_fees += "             "
bitcoin_recommended_fees += "High priority: {} sat/vB".format(data["fastestFee"])
except Exception as e:
bitcoin_recommended_fees = "Fee error - " . str(e)
else:
bitcoin_recommended_fees = None
except Exception as e1: except Exception as e1:
log_message("ERROR: In update_bitcoin_other_info - {}".format( str(e1) )) log_message("ERROR: In update_bitcoin_other_info - {}".format( str(e1) ))
@ -201,6 +221,10 @@ def get_bitcoin_mempool_size():
size = float(info["bytes"]) / 1000 / 1000 size = float(info["bytes"]) / 1000 / 1000
return "{:.3} MB".format(size) return "{:.3} MB".format(size)
def get_bitcoin_recommended_fees():
global bitcoin_recommended_fees
return bitcoin_recommended_fees
def get_bitcoin_wallets(): def get_bitcoin_wallets():
global bitcoin_wallets global bitcoin_wallets
return copy.deepcopy(bitcoin_wallets) return copy.deepcopy(bitcoin_wallets)

View File

@ -249,7 +249,7 @@ td, th {
background: #f0f0f0; background: #f0f0f0;
} }
/* width of four tiles (full width) */ /* width of four tiles (full width) */
.app_tile_price_ticker { .app_tile_ticker {
display: inline-block; display: inline-block;
position: relative; position: relative;
border: none; border: none;

View File

@ -40,7 +40,7 @@ a:active {
.device_status_info, .device_status_info,
.bitcoin_block, .bitcoin_block,
.pair_wallet_text, .pair_wallet_text,
.app_tile_price_ticker, .app_tile_ticker,
.app_tile_lightning_details, .app_tile_lightning_details,
.lightning_channel_container, .lightning_channel_container,
.settings_block_subheader, .settings_block_subheader,
@ -55,7 +55,7 @@ table,
.app_tile, .app_tile,
.app_tile_short, .app_tile_short,
.app_tile_wide, .app_tile_wide,
.app_tile_price_ticker, .app_tile_ticker,
.app_tile_bitcoin_recent_blocks, .app_tile_bitcoin_recent_blocks,
.app_tile_lightning_details, .app_tile_lightning_details,
.info_tile { .info_tile {
@ -64,7 +64,7 @@ table,
.app_tile, .app_tile,
.app_tile_wide, .app_tile_wide,
.app_tile_price_ticker, .app_tile_ticker,
.app_tile_bitcoin_recent_blocks, .app_tile_bitcoin_recent_blocks,
.app_tile_lightning_details, .app_tile_lightning_details,
.app_tile_short { .app_tile_short {

View File

@ -100,9 +100,9 @@
</div> </div>
<!-- Show Price Info --> <!-- Show Price Info -->
<div class="app_tile_row" id="price_ticker" style="display: none;"> <div class="app_tile_row" id="ticker" style="display: none;">
<div class="app_tile_price_ticker" > <div class="app_tile_ticker" >
<span id="price_ticker_text"></span> <span id="ticker_text"></span>
</div> </div>
</div> </div>

View File

@ -19,6 +19,9 @@
var lnd_last_btc_tx = ""; var lnd_last_btc_tx = "";
var lnd_last_ln_tx = ""; var lnd_last_ln_tx = "";
var price_data = {}; var price_data = {};
var device_info = null;
var bitcoin_info = null;
var lnd_info = null;
// Toggle enable/disable functions // Toggle enable/disable functions
function get_custom_enable_message(short_name) { function get_custom_enable_message(short_name) {
@ -97,35 +100,52 @@
} }
} }
var price_display_rotate_count = 0; var ticker_rotate_count = 0;
function update_price_display() { function update_ticker() {
{% if ui_settings['price_ticker'] %} display_options = [];
// Append price display options
if ("price" in price_data && "delta" in price_data && "direction" in price_data ) { if ("price" in price_data && "delta" in price_data && "direction" in price_data ) {
$("#price_ticker").show();
$("#price_ticker_text").slideUp('fast', function() {
display_id = price_display_rotate_count % 3;
if (display_id == 0) {
p = price_data["price"].toLocaleString('en-US', {style: 'currency', currency: 'USD'}); p = price_data["price"].toLocaleString('en-US', {style: 'currency', currency: 'USD'});
$("#price_ticker_text").html(p + " USD/BTC"); display_options.push(p + " USD/BTC")
} else if (display_id == 1) {
sats = parseInt(100000000 / price_data["price"]); sats = parseInt(100000000 / price_data["price"]);
$("#price_ticker_text").html(sats + " SATS/USD"); display_options.push(sats + " SATS/USD")
} else if (display_id == 2) {
p = Math.abs(price_data["delta"]).toLocaleString('en-US', {style: 'currency', currency: 'USD'}); p = Math.abs(price_data["delta"]).toLocaleString('en-US', {style: 'currency', currency: 'USD'});
if (price_data["direction"] == "flat") { if (price_data["direction"] == "flat") {
$("#price_ticker_text").html("Price is flat"); direction_text = "Price is flat";
} else if (price_data["direction"] == "up") { } else if (price_data["direction"] == "up") {
$("#price_ticker_text").html("Price is up "+p); direction_text = "Price is up " + p;
} else if (price_data["direction"] == "down") { } else if (price_data["direction"] == "down") {
$("#price_ticker_text").html("Price is down "+p); direction_text = "Price is down " + p;
} }
display_options.push(direction_text)
} }
$("#price_ticker_text").slideDown(); // Append uptime option
price_display_rotate_count = price_display_rotate_count + 1; if (device_info && "uptime" in device_info) {
display_options.push("Online for " + device_info["uptime"])
}
// Append fees option
if (bitcoin_info && "recommended_fees" in bitcoin_info && bitcoin_info["recommended_fees"] != null) {
display_options.push(bitcoin_info["recommended_fees"])
}
if (display_options.length == 0) {
display_options.push("Loading...")
} else if (display_options.length == 1) {
display_options.push("Welcome to myNode!")
display_options.push("Enable Mempool or the Price Ticker to see more info here!")
}
// Display new ticker text
$("#ticker").show();
$("#ticker_text").slideUp('fast', function() {
display_id = ticker_rotate_count % display_options.length;
$("#ticker_text").html( display_options[display_id] );
$("#ticker_text").slideDown();
ticker_rotate_count = ticker_rotate_count + 1;
}); });
} }
{% endif %}
}
function update_sso_token(short_name, data) { function update_sso_token(short_name, data) {
if ("sso_token" in data && data["sso_token"] != null && data["sso_token"] != "") { if ("sso_token" in data && data["sso_token"] != null && data["sso_token"] != "") {
@ -225,6 +245,7 @@
// Update Bitcoin Info // Update Bitcoin Info
$.getJSON("/api/get_bitcoin_info", function( data ) { $.getJSON("/api/get_bitcoin_info", function( data ) {
//console.log("Bitcoin Data: " + JSON.stringify(data)) //console.log("Bitcoin Data: " + JSON.stringify(data))
bitcoin_info = data;
if ("current_block" in data && data["current_block"] != null) { if ("current_block" in data && data["current_block"] != null) {
$("#current_block").html(data["current_block"]); $("#current_block").html(data["current_block"]);
} }
@ -257,6 +278,7 @@
// Update Lightning Info // Update Lightning Info
$.getJSON("/api/get_lightning_info", function( data ) { $.getJSON("/api/get_lightning_info", function( data ) {
//console.log("Lightning Data: " + JSON.stringify(data)) //console.log("Lightning Data: " + JSON.stringify(data))
lnd_info = data;
if ("channel_count" in data && data["channel_count"] != null) { if ("channel_count" in data && data["channel_count"] != null) {
$("#lnd_channel_count").html(data["channel_count"]); $("#lnd_channel_count").html(data["channel_count"]);
} }
@ -393,19 +415,19 @@
{% endfor %} {% endfor %}
// Update price info // Update price info
{% if ui_settings['price_ticker'] %}
$.getJSON("/api/get_price_info", function( data ) { $.getJSON("/api/get_price_info", function( data ) {
// console.log("Price Data: " + JSON.stringify(data)) // console.log("Price Data: " + JSON.stringify(data))
if ("price" in data && data["price"] != null) { if ("price" in data && data["price"] != null) {
price_data = data; price_data = data;
if (price_display_rotate_count == 0) {
update_price_display();
}
} }
}); });
{% endif %}
// Update device info // Update device info
$.getJSON("/api/get_device_info", function( data ) { $.getJSON("/api/get_device_info", function( data ) {
//console.log("Device Data: " + JSON.stringify(data)) //console.log("Device Data: " + JSON.stringify(data))
device_info = data
if ("data_drive_usage" in data && data["data_drive_usage"] != null) { if ("data_drive_usage" in data && data["data_drive_usage"] != null) {
$("#data_drive_usage").html(data["data_drive_usage"]); $("#data_drive_usage").html(data["data_drive_usage"]);
} }
@ -625,8 +647,10 @@
const update_interval = setInterval(update_page, 15000); const update_interval = setInterval(update_page, 15000);
update_page(); update_page();
// Rotate Price Ticker every 10 seconds // Rotate Ticker every 6 seconds
const rotate_ticker_interval = setInterval(update_price_display, 10000); const rotate_ticker_interval = setInterval(update_ticker, 8000);
setTimeout(update_ticker, 1500);
update_ticker();
// If pinned lightning, auto open lightning details // If pinned lightning, auto open lightning details
{% if lnd_wallet_exists and lnd_ready and ui_settings['pinned_lightning_details'] %} {% if lnd_wallet_exists and lnd_ready and ui_settings['pinned_lightning_details'] %}