From ee6dd2ec56a8b4e426dc3d96a8824d377d43934e Mon Sep 17 00:00:00 2001
From: Jaquee <jaquee.monero@gmail.com>
Date: Tue, 20 Mar 2018 19:19:30 +0100
Subject: [PATCH] progress bar improvements

---
 components/ProgressBar.qml | 13 +------------
 main.qml                   | 25 ++++++++++++++++++++-----
 2 files changed, 21 insertions(+), 17 deletions(-)

diff --git a/components/ProgressBar.qml b/components/ProgressBar.qml
index cf5b3a12..04b92b3a 100644
--- a/components/ProgressBar.qml
+++ b/components/ProgressBar.qml
@@ -37,27 +37,16 @@ Rectangle {
     color: "#1C1C1C"
 
     function updateProgress(currentBlock,targetBlock, blocksToSync, statusTxt){
-        if(targetBlock == 1) {
-            fillLevel = 0
-            progressText.text = qsTr("Establishing connection...");
-            progressBar.visible = true
-            return
-        }
-
         if(targetBlock > 0) {
             var remaining = (currentBlock < targetBlock) ? targetBlock - currentBlock : 0
-            var progressLevel = (blocksToSync > 0) ? (100*(blocksToSync - remaining)/blocksToSync).toFixed(0) : 100
+            var progressLevel = (blocksToSync > 0 && blocksToSync != remaining) ? (100*(blocksToSync - remaining)/blocksToSync).toFixed(0) : 100*(currentBlock / targetBlock).toFixed(0)
             fillLevel = progressLevel
             if(typeof statusTxt != "undefined" && statusTxt != "") {
                 progressText.text = statusTxt;
             } else {
                 progressText.text = syncText + remaining.toFixed(0);
             }
-
         }
-
-        if(remaining == 0 && (typeof statusTxt == "undefined" || statusTxt == ""))
-            progressText.text = qsTr("%1 is synchronized").arg(syncType)
     }
 
     Item {
diff --git a/main.qml b/main.qml
index 78818a96..afadb2ac 100644
--- a/main.qml
+++ b/main.qml
@@ -57,6 +57,7 @@ ApplicationWindow {
     property bool isNewWallet: false
     property int restoreHeight:0
     property bool daemonSynced: false
+    property bool walletSynced: false
     property int maxWindowHeight: (isAndroid || isIOS)? screenHeight : (screenHeight < 900)? 720 : 800;
     property bool daemonRunning: false
     property alias toolTip: toolTip
@@ -405,6 +406,9 @@ ApplicationWindow {
         // Daemon connected
         leftPanel.networkStatus.connected = currentWallet.connected()
 
+        // Wallet height
+        var bcHeight = currentWallet.blockChainHeight();
+
         // Check daemon status
         var dCurrentBlock = currentWallet.daemonBlockChainHeight();
         var dTargetBlock = currentWallet.daemonBlockChainTargetHeight();
@@ -412,18 +416,25 @@ ApplicationWindow {
         // TODO: implement onDaemonSynced or similar in wallet API and don't start refresh thread before daemon is synced
         // targetBlock = currentBlock = 1 before network connection is established.
         daemonSynced = dCurrentBlock >= dTargetBlock && dTargetBlock != 1
-        // Update daemon sync progress
-        leftPanel.daemonProgressBar.updateProgress(dCurrentBlock,dTargetBlock);
-        if(!daemonSynced)
+        walletSynced = bcHeight >= dTargetBlock
+
+        // Update progress bars
+        if(!daemonSynced) {
+            leftPanel.daemonProgressBar.updateProgress(dCurrentBlock,dTargetBlock, dTargetBlock-dCurrentBlock);
             leftPanel.progressBar.updateProgress(0,dTargetBlock, dTargetBlock, qsTr("Waiting for daemon to sync"));
+        } else {
+            leftPanel.daemonProgressBar.updateProgress(dCurrentBlock,dTargetBlock, 0, qsTr("Daemon is synchronized (%1)").arg(dCurrentBlock.toFixed(0)));
+            if(walletSynced)
+                leftPanel.progressBar.updateProgress(bcHeight,dTargetBlock,dTargetBlock-bcHeight, qsTr("Wallet is synchronized"))
+        }
+
         // Update wallet sync progress
         updateSyncing((currentWallet.connected() !== Wallet.ConnectionStatus_Disconnected) && !daemonSynced)
         // Update transfer page status
         middlePanel.updateStatus();
 
         // Refresh is succesfull if blockchain height > 1
-        if (currentWallet.blockChainHeight() > 1){
-
+        if (bcHeight > 1){
             // Save new wallet after first refresh
             // Wallet is nomrmally saved to disk on app exit. This prevents rescan from block 0 after app crash
             if(isNewWallet){
@@ -498,6 +509,10 @@ ApplicationWindow {
         }
 
         leftPanel.progressBar.updateProgress(blockHeight,targetHeight, blocksToSync);
+
+        // If wallet is syncing, daemon is already synced
+        leftPanel.daemonProgressBar.updateProgress(1,1,0,qsTr("Daemon is synchronized"));
+
         foundNewBlock = true;
     }