From: tobtoht Date: Sat, 30 Dec 2023 13:17:11 +0000 (+0100) Subject: lock: add sync status X-Git-Url: https://git.nutra.tk/v2?a=commitdiff_plain;h=082413dc0de90c11225066ed35a69e8813300f14;p=gamesguru%2Ffeather.git lock: add sync status --- diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 6e414995..9d089a21 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -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 &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) diff --git a/src/MainWindow.h b/src/MainWindow.h index 92664555..238a23e7 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -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 &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(); diff --git a/src/libwalletqt/Wallet.cpp b/src/libwalletqt/Wallet.cpp index 9bae3f29..1abf0481 100644 --- a/src/libwalletqt/Wallet.cpp +++ b/src/libwalletqt/Wallet.cpp @@ -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) { diff --git a/src/libwalletqt/Wallet.h b/src/libwalletqt/Wallet.h index be792d10..72cb775f 100644 --- a/src/libwalletqt/Wallet.h +++ b/src/libwalletqt/Wallet.h @@ -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(); diff --git a/src/utils/Utils.cpp b/src/utils/Utils.cpp index b022eb20..22cce6cf 100644 --- a/src/utils/Utils.cpp +++ b/src/utils/Utils.cpp @@ -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"; +} } diff --git a/src/utils/Utils.h b/src/utils/Utils.h index ba530e92..f85c8ac8 100644 --- a/src/utils/Utils.h +++ b/src/utils/Utils.h @@ -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 diff --git a/src/widgets/WalletUnlockWidget.cpp b/src/widgets/WalletUnlockWidget.cpp index 9fa0a7d6..ed9d9e34 100644 --- a/src/widgets/WalletUnlockWidget.cpp +++ b/src/widgets/WalletUnlockWidget.cpp @@ -7,9 +7,12 @@ #include #include -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) { diff --git a/src/widgets/WalletUnlockWidget.h b/src/widgets/WalletUnlockWidget.h index 99bd5516..64625a1c 100644 --- a/src/widgets/WalletUnlockWidget.h +++ b/src/widgets/WalletUnlockWidget.h @@ -7,6 +7,8 @@ #include #include +#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; + Wallet *m_wallet; }; #endif //FEATHER_WALLETUNLOCKWIDGET_H diff --git a/src/widgets/WalletUnlockWidget.ui b/src/widgets/WalletUnlockWidget.ui index fe445fff..be083bc8 100644 --- a/src/widgets/WalletUnlockWidget.ui +++ b/src/widgets/WalletUnlockWidget.ui @@ -7,13 +7,16 @@ 0 0 918 - 255 + 440 Form + + 2 + @@ -68,7 +71,6 @@ 12 - 75 true @@ -168,6 +170,37 @@ + + + + QFrame::NoFrame + + + QFrame::Plain + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Sync: + + + + + +