]> Nutra Git (v1) - gamesguru/feather.git/commitdiff
lock: add sync status
authortobtoht <tob@featherwallet.org>
Sat, 30 Dec 2023 13:17:11 +0000 (14:17 +0100)
committertobtoht <tob@featherwallet.org>
Sat, 30 Dec 2023 13:17:11 +0000 (14:17 +0100)
src/MainWindow.cpp
src/MainWindow.h
src/libwalletqt/Wallet.cpp
src/libwalletqt/Wallet.h
src/utils/Utils.cpp
src/utils/Utils.h
src/widgets/WalletUnlockWidget.cpp
src/widgets/WalletUnlockWidget.h
src/widgets/WalletUnlockWidget.ui

index 6e414995321d43ef58f5f1ce2308b4c1a9e08a6c..9d089a21b9a20e94c6a400a85037e22cad6d7b92 100644 (file)
@@ -263,7 +263,7 @@ void MainWindow::initWidgets() {
        m_wallet->setSelectedInputs({});
     });
 
-    m_walletUnlockWidget = new WalletUnlockWidget(this);
+    m_walletUnlockWidget = new WalletUnlockWidget(this, m_wallet);
     m_walletUnlockWidget->setWalletName(this->walletName());
     ui->walletUnlockLayout->addWidget(m_walletUnlockWidget);
 
@@ -452,9 +452,7 @@ void MainWindow::initOffline() {
 
 void MainWindow::initWalletContext() {
     connect(m_wallet, &Wallet::balanceUpdated,           this, &MainWindow::onBalanceUpdated);
-    connect(m_wallet, &Wallet::synchronized,             this, &MainWindow::onSynchronized); //TODO
-    connect(m_wallet, &Wallet::blockchainSync,           this, &MainWindow::onBlockchainSync);
-    connect(m_wallet, &Wallet::refreshSync,              this, &MainWindow::onRefreshSync);
+    connect(m_wallet, &Wallet::syncStatus,               this, &MainWindow::onSyncStatus);
     connect(m_wallet, &Wallet::transactionCreated,       this, &MainWindow::onTransactionCreated);
     connect(m_wallet, &Wallet::transactionCommitted,     this, &MainWindow::onTransactionCommitted);
     connect(m_wallet, &Wallet::initiateTransaction,      this, &MainWindow::onInitiateTransaction);
@@ -697,21 +695,11 @@ void MainWindow::onMultiBroadcast(const QMap<QString, QString> &txHexMap) {
     }
 }
 
-void MainWindow::onSynchronized() {
-    this->updateNetStats();
-    this->setStatusText("Synchronized");
-}
-
-void MainWindow::onBlockchainSync(int height, int target) {
-    QString blocks = (target >= height) ? QString::number(target - height) : "?";
-    QString heightText = QString("Blockchain sync: %1 blocks remaining").arg(blocks);
-    this->setStatusText(heightText);
-}
-
-void MainWindow::onRefreshSync(int height, int target) {
-    QString blocks = (target >= height) ? QString::number(target - height) : "?";
-    QString heightText = QString("Wallet sync: %1 blocks remaining").arg(blocks);
-    this->setStatusText(heightText);
+void MainWindow::onSyncStatus(quint64 height, quint64 target, bool daemonSync) {
+    if (height >= (target - 1)) {
+        this->updateNetStats();
+    }
+    this->setStatusText(Utils::formatSyncStatus(height, target, daemonSync));
 }
 
 void MainWindow::onConnectionStatusChanged(int status)
index 926645555dabc3b480497388cf7ca8886c84411e..238a23e7f2677290e39770b506f23b453084c8a0 100644 (file)
@@ -127,7 +127,7 @@ private slots:
 
     // libwalletqt
     void onBalanceUpdated(quint64 balance, quint64 spendable);
-    void onSynchronized();
+    void onSyncStatus(quint64 height, quint64 target, bool daemonSync);
     void onWalletOpened();
     void onConnectionStatusChanged(int status);
     void onTransactionCreated(PendingTransaction *tx, const QVector<QString> &address);
@@ -149,8 +149,6 @@ private slots:
     void payToMany();
     void showHistoryTab();
     void skinChanged(const QString &skinName);
-    void onBlockchainSync(int height, int target);
-    void onRefreshSync(int height, int target);
     void onViewOnBlockExplorer(const QString &txid);
     void onResendTransaction(const QString &txid);
     void importContacts();
index 9bae3f29c475ce186142686182b17a07f3bfd384..1abf048151337d9d6070895f179c2e02bb9a8880 100644 (file)
@@ -396,7 +396,7 @@ void Wallet::onHeightsRefreshed(bool success, quint64 daemonHeight, quint64 targ
         quint64 walletHeight = blockChainHeight();
 
         if (daemonHeight < targetHeight) {
-            emit blockchainSync(daemonHeight, targetHeight);
+            emit syncStatus(daemonHeight, targetHeight, true);
         }
         else {
             this->syncStatusUpdated(walletHeight, daemonHeight);
@@ -426,13 +426,12 @@ quint64 Wallet::daemonBlockChainTargetHeight() const {
 }
 
 void Wallet::syncStatusUpdated(quint64 height, quint64 target) {
-    if (height < (target - 1)) {
-        emit refreshSync(height, target);
-    }
-    else {
+    if (height >= (target - 1)) {
+        // TODO: is this needed?
         this->updateBalance();
-        emit synchronized();
     }
+
+    emit syncStatus(height, target, false);
 }
 
 void Wallet::onNewBlock(uint64_t walletHeight) {
index be792d10e0056b51843c0180c016e8486229de5f..72cb775f4f35a373e2b1adc3fe730061f9f09bef 100644 (file)
@@ -440,9 +440,9 @@ signals:
     void connectionStatusChanged(int status) const;
     void currentSubaddressAccountChanged() const;
 
-    void refreshSync(int height, int target);
-    void blockchainSync(int height, int target);
-    void synchronized();
+
+    void syncStatus(quint64 height, quint64 target, bool daemonSync = false);
+
     void balanceUpdated(quint64 balance, quint64 spendable);
     void keysCorrupted();
 
index b022eb2022a48095a8d057b6a09ec43dac3e9db5..22cce6cf0222af108947c700c6ccfab867ae823a 100644 (file)
@@ -708,4 +708,14 @@ void clearLayout(QLayout* layout, bool deleteWidgets)
         delete item;
     }
 }
+
+QString formatSyncStatus(quint64 height, quint64 target, bool daemonSync) {
+    if (height < (target - 1)) {
+        QString blocks = (target >= height) ? QString::number(target - height) : "?";
+        QString type = daemonSync ? "Blockchain" : "Wallet";
+        return QString("%1 sync: %2 blocks remaining").arg(type, blocks);
+    }
+
+    return "Synchronized";
+}
 }
index ba530e92c4f46d5a7021b91963bda91bab6bd952..f85c8ac8081ed7bc9f257835e6effd2aab5f2983 100644 (file)
@@ -114,6 +114,8 @@ namespace Utils
 
     QWindow* windowForQObject(QObject* object);
     void clearLayout(QLayout *layout, bool deleteWidgets = true);
+
+    QString formatSyncStatus(quint64 height, quint64 target, bool daemonSync = false);
 }
 
 #endif //FEATHER_UTILS_H
index 9fa0a7d6723b775af6d8c9c0a7bb272b9577957f..ed9d9e347adfcb02ebb09cbc9866c2a55f9b12ab 100644 (file)
@@ -7,9 +7,12 @@
 #include <QKeyEvent>
 #include <QPushButton>
 
-WalletUnlockWidget::WalletUnlockWidget(QWidget *parent)
+#include "utils/Utils.h"
+
+WalletUnlockWidget::WalletUnlockWidget(QWidget *parent, Wallet *wallet)
         : QWidget(parent)
         , ui(new Ui::WalletUnlockWidget)
+        , m_wallet(wallet)
 {
     ui->setupUi(this);
     this->reset();
@@ -18,6 +21,14 @@ WalletUnlockWidget::WalletUnlockWidget(QWidget *parent)
 
     connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &WalletUnlockWidget::tryUnlock);
     connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &WalletUnlockWidget::closeWallet);
+
+    ui->frame_sync->hide();
+    if (m_wallet) {
+        connect(m_wallet, &Wallet::syncStatus, [this](quint64 height, quint64 target, bool daemonSync){
+            ui->frame_sync->show();
+            ui->label_sync->setText(Utils::formatSyncStatus(height, target, daemonSync));
+        });
+    }
 }
 
 void WalletUnlockWidget::setWalletName(const QString &walletName) {
index 99bd551656e2eb74c8651cef7e2217688db925e0..64625a1c96626466e1b7c21e68839abf60aae642 100644 (file)
@@ -7,6 +7,8 @@
 #include <QWidget>
 #include <QMenu>
 
+#include "Wallet.h"
+
 namespace Ui {
     class WalletUnlockWidget;
 }
@@ -16,7 +18,7 @@ class WalletUnlockWidget : public QWidget
 Q_OBJECT
 
 public:
-    explicit WalletUnlockWidget(QWidget *parent = nullptr);
+    explicit WalletUnlockWidget(QWidget *parent, Wallet *wallet = nullptr);
     ~WalletUnlockWidget();
 
     void setWalletName(const QString &walletName);
@@ -35,6 +37,7 @@ protected:
 
 private:
     QScopedPointer<Ui::WalletUnlockWidget> ui;
+    Wallet *m_wallet;
 };
 
 #endif //FEATHER_WALLETUNLOCKWIDGET_H
index fe445fffe42f8ef7ff5f9808af596da987195929..be083bc8a8e70e0351db6ec39eda0b59460f4e0d 100644 (file)
@@ -7,13 +7,16 @@
     <x>0</x>
     <y>0</y>
     <width>918</width>
-    <height>255</height>
+    <height>440</height>
    </rect>
   </property>
   <property name="windowTitle">
    <string>Form</string>
   </property>
   <layout class="QVBoxLayout" name="verticalLayout">
+   <property name="bottomMargin">
+    <number>2</number>
+   </property>
    <item>
     <layout class="QHBoxLayout" name="horizontalLayout">
      <item>
@@ -68,7 +71,6 @@
           <property name="font">
            <font>
             <pointsize>12</pointsize>
-            <weight>75</weight>
             <bold>true</bold>
            </font>
           </property>
      </item>
     </layout>
    </item>
+   <item>
+    <widget class="QFrame" name="frame_sync">
+     <property name="frameShape">
+      <enum>QFrame::NoFrame</enum>
+     </property>
+     <property name="frameShadow">
+      <enum>QFrame::Plain</enum>
+     </property>
+     <layout class="QHBoxLayout" name="horizontalLayout_3">
+      <property name="leftMargin">
+       <number>0</number>
+      </property>
+      <property name="topMargin">
+       <number>0</number>
+      </property>
+      <property name="rightMargin">
+       <number>0</number>
+      </property>
+      <property name="bottomMargin">
+       <number>0</number>
+      </property>
+      <item>
+       <widget class="QLabel" name="label_sync">
+        <property name="text">
+         <string>Sync:</string>
+        </property>
+       </widget>
+      </item>
+     </layout>
+    </widget>
+   </item>
   </layout>
  </widget>
  <resources/>