From aeae07e9c1c57408ef3d73d0b06fabd7132325a9 Mon Sep 17 00:00:00 2001 From: Taylor Helsper Date: Thu, 7 Apr 2022 23:28:22 -0500 Subject: [PATCH] Improve Bitcoin progress and error reporting UX --- rootfs/standard/var/pynode/bitcoin_info.py | 12 ++++++++++- rootfs/standard/var/www/mynode/api.py | 1 + rootfs/standard/var/www/mynode/mynode.py | 4 +++- .../var/www/mynode/templates/syncing.html | 20 ++++++++++++++++--- 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/rootfs/standard/var/pynode/bitcoin_info.py b/rootfs/standard/var/pynode/bitcoin_info.py index de61df8f..4eb76a44 100644 --- a/rootfs/standard/var/pynode/bitcoin_info.py +++ b/rootfs/standard/var/pynode/bitcoin_info.py @@ -67,7 +67,9 @@ def update_bitcoin_main_info(): if "difficulty" in info: info["difficulty"] = "{:.3g}".format(info["difficulty"]) if "verificationprogress" in info: - info["verificationprogress"] = "{:.3g}".format(info["verificationprogress"]) + info["verificationprogress"] = "{:.2f}%".format(100 * info["verificationprogress"]) + else: + info["verificationprogress"] = "???" bitcoin_blockchain_info = info @@ -219,6 +221,14 @@ def get_mynode_block_height(): global mynode_block_height return mynode_block_height +def get_bitcoin_sync_progress(): + info = get_bitcoin_blockchain_info() + progress = "???" + if info: + if "verificationprogress" in info: + return info["verificationprogress"] + return progress + def get_bitcoin_recent_blocks(): global bitcoin_recent_blocks return copy.deepcopy(bitcoin_recent_blocks) diff --git a/rootfs/standard/var/www/mynode/api.py b/rootfs/standard/var/www/mynode/api.py index 283a1ed8..771d3d15 100644 --- a/rootfs/standard/var/www/mynode/api.py +++ b/rootfs/standard/var/www/mynode/api.py @@ -32,6 +32,7 @@ def api_get_bitcoin_info(): data = {} data["current_block"] = get_mynode_block_height() data["block_height"] = get_bitcoin_block_height() + data["progress"] = get_bitcoin_sync_progress() data["peer_count"] = get_bitcoin_peer_count() #data["difficulty"] = get_bitcoin_difficulty() # Dont send difficulty, it causes errors in jsonify data["mempool_size"] = get_bitcoin_mempool_info()["display_bytes"] diff --git a/rootfs/standard/var/www/mynode/mynode.py b/rootfs/standard/var/www/mynode/mynode.py index b5510b43..4b9b40a1 100644 --- a/rootfs/standard/var/www/mynode/mynode.py +++ b/rootfs/standard/var/www/mynode/mynode.py @@ -210,6 +210,7 @@ def index(): elif status == STATE_DRIVE_CONFIRM_FORMAT: if request.args.get('format'): touch("/tmp/format_ok") + os.system("rm -f /home/bitcoin/.mynode/force_format_prompt") time.sleep(1) return redirect("/") @@ -450,7 +451,7 @@ def index(): "title": "myNode Status", "header_text": "Starting...", "subheader_text": Markup("Launching myNode Services{}".format(message)), - "error_message": error_message, + "error_message": Markup(error_message + "

"), "ui_settings": read_ui_settings() } return render_template('state.html', **templateData) @@ -477,6 +478,7 @@ def index(): "header_text": "Bitcoin Blockchain", "bitcoin_block_height": bitcoin_block_height, "mynode_block_height": mynode_block_height, + "progress": get_bitcoin_sync_progress(), "message": get_message(include_funny=True), "ui_settings": read_ui_settings() } diff --git a/rootfs/standard/var/www/mynode/templates/syncing.html b/rootfs/standard/var/www/mynode/templates/syncing.html index 8e09a010..05a73c57 100644 --- a/rootfs/standard/var/www/mynode/templates/syncing.html +++ b/rootfs/standard/var/www/mynode/templates/syncing.html @@ -7,13 +7,15 @@ $(document).ready(function() { current_block = {{mynode_block_height}}; block_height = {{bitcoin_block_height}}; + progress = "{{progress}}"; function update_counts() { // Update Bitcoin Info $.getJSON("/api/get_bitcoin_info", function( data ) { - //console.log("Bitcoin Data: " + JSON.stringify(data)) + //console.log("Bitcoin Data: " + JSON.stringify(data)); if ("current_block" in data && data["current_block"] != null && - "block_height" in data && data["block_height"] != null) { + "block_height" in data && data["block_height"] != null && + "progress" in data && data["progress"] != null) { if (current_block != parseInt(data["current_block"])) { $("#current_block").fadeOut(250, function() { $(this).text(data["current_block"]); @@ -26,6 +28,12 @@ }).fadeIn(250); block_height = parseInt(data["block_height"]); } + if (progress != data['progress']) { + $("#progress").fadeOut(250, function() { + $(this).text(data["progress"]); + }).fadeIn(250); + progress = data["progress"]; + } // We're close, so do a full refresh to get to home page faster if (current_block > (block_height - 5)) { @@ -65,8 +73,14 @@
Syncing...
- {{mynode_block_height}} of {{bitcoin_block_height}} + +
+ {{mynode_block_height}} of {{bitcoin_block_height}} +
+
{{progress}}
+ +
{{ message }}