From 2237d5eff8bb661c147fba17d714fdb27f61d0fc Mon Sep 17 00:00:00 2001 From: tobtoht Date: Wed, 30 Dec 2020 04:58:17 +0100 Subject: [PATCH] History: add sync notice --- src/appcontext.cpp | 2 ++ src/appcontext.h | 2 +- src/historywidget.cpp | 23 +++++++++++++++ src/historywidget.h | 3 ++ src/historywidget.ui | 67 +++++++++++++++++++++++++++++++++++++++++++ src/mainwindow.cpp | 4 ++- src/utils/config.cpp | 3 +- src/utils/config.h | 3 +- 8 files changed, 103 insertions(+), 4 deletions(-) diff --git a/src/appcontext.cpp b/src/appcontext.cpp index 338490f..bf89640 100644 --- a/src/appcontext.cpp +++ b/src/appcontext.cpp @@ -316,6 +316,7 @@ void AppContext::onWalletOpened(Wallet *wallet) { return; } + this->refreshed = false; this->currentWallet = wallet; this->walletPath = this->currentWallet->path() + ".keys"; this->walletViewOnly = this->currentWallet->viewOnly(); @@ -716,6 +717,7 @@ void AppContext::onWalletRefreshed(bool success) { if (!this->refreshed) { refreshModels(); this->refreshed = true; + emit walletRefreshed(); // store wallet immediately upon finishing synchronization this->currentWallet->store(); } diff --git a/src/appcontext.h b/src/appcontext.h index d74acb0..6d81614 100644 --- a/src/appcontext.h +++ b/src/appcontext.h @@ -150,7 +150,7 @@ signals: void refreshSync(int height, int target); void synchronized(); void blockHeightWSUpdated(QMap heights); - void walletSynchronized(); + void walletRefreshed(); void walletOpened(); void walletCreatedError(const QString &msg); void walletCreated(Wallet *wallet); diff --git a/src/historywidget.cpp b/src/historywidget.cpp index f84934b..ab13ebe 100644 --- a/src/historywidget.cpp +++ b/src/historywidget.cpp @@ -4,6 +4,7 @@ #include "historywidget.h" #include "ui_historywidget.h" #include "dialog/transactioninfodialog.h" +#include HistoryWidget::HistoryWidget(QWidget *parent) : QWidget(parent) @@ -33,6 +34,11 @@ HistoryWidget::HistoryWidget(QWidget *parent) } }); + connect(ui->btn_moreInfo, &QPushButton::clicked, this, &HistoryWidget::showSyncNoticeMsg); + connect(ui->btn_close, &QPushButton::clicked, [this]{ + config()->set(Config::showHistorySyncNotice, false); + ui->syncNotice->hide(); + }); } void HistoryWidget::showContextMenu(const QPoint &point) { @@ -143,6 +149,23 @@ void HistoryWidget::copy(copyField field) { Utils::copyToClipboard(data); } +void HistoryWidget::onWalletOpened() { + ui->syncNotice->setVisible(config()->get(Config::showHistorySyncNotice).toBool()); +} + +void HistoryWidget::onWalletRefreshed() { + ui->syncNotice->hide(); +} + +void HistoryWidget::showSyncNoticeMsg() { + QMessageBox::information(this, "Sync notice", + "The wallet needs to scan the blockchain to find your transactions. " + "The status bar will show you how many blocks are still remaining.\n" + "\n" + "The history page will update once synchronization has finished. " + "To update the history page during synchronization press Ctrl+R."); +} + HistoryWidget::~HistoryWidget() { delete ui; } diff --git a/src/historywidget.h b/src/historywidget.h index 20a6a82..35c1df1 100644 --- a/src/historywidget.h +++ b/src/historywidget.h @@ -28,6 +28,8 @@ public: public slots: void setSearchText(const QString &text); void resetModel(); + void onWalletRefreshed(); + void onWalletOpened(); signals: void viewOnBlockExplorer(QString txid); @@ -48,6 +50,7 @@ private: void copy(copyField field); void showContextMenu(const QPoint &point); + void showSyncNoticeMsg(); Ui::HistoryWidget *ui; QMenu *m_contextMenu; diff --git a/src/historywidget.ui b/src/historywidget.ui index c333a69..ff8cb25 100644 --- a/src/historywidget.ui +++ b/src/historywidget.ui @@ -33,6 +33,73 @@ + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 3 + + + 3 + + + + + History may appear incomplete during synchronization. + + + + + + + Qt::Horizontal + + + + 0 + 20 + + + + + + + + + 0 + 0 + + + + More info + + + + + + + + 0 + 0 + + + + Close + + + false + + + + + + diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 3fdc280..4b89dda 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -292,6 +292,8 @@ MainWindow::MainWindow(AppContext *ctx, QWidget *parent) : // History connect(ui->historyWidget, &HistoryWidget::viewOnBlockExplorer, this, &MainWindow::onViewOnBlockExplorer); connect(ui->historyWidget, &HistoryWidget::resendTransaction, this, &MainWindow::onResendTransaction); + connect(m_ctx, &AppContext::walletRefreshed, ui->historyWidget, &HistoryWidget::onWalletRefreshed); + connect(m_ctx, &AppContext::walletOpened, ui->historyWidget, &HistoryWidget::onWalletOpened); // Contacts connect(ui->contactWidget, &ContactsWidget::fillAddress, ui->sendWidget, &SendWidget::fillAddress); @@ -693,7 +695,7 @@ void MainWindow::onBlockchainSync(int height, int target) { void MainWindow::onRefreshSync(int height, int target) { QString blocks = (target >= height) ? QString::number(target - height) : "?"; - QString heightText = QString("Wallet refresh: %1 blocks remaining").arg(blocks); + QString heightText = QString("Wallet sync: %1 blocks remaining").arg(blocks); this->setStatusText(heightText); } diff --git a/src/utils/config.cpp b/src/utils/config.cpp index 0541eb4..60b7c64 100644 --- a/src/utils/config.cpp +++ b/src/utils/config.cpp @@ -45,7 +45,8 @@ static const QHash configStrings = { {Config::windowState, {QS("windowState"), {}}}, {Config::firstRun,{QS("firstRun"), false}}, {Config::hideBalance, {QS("hideBalance"), false}}, - {Config::redditFrontend, {QS("redditFrontend"), "old.reddit.com"}} + {Config::redditFrontend, {QS("redditFrontend"), "old.reddit.com"}}, + {Config::showHistorySyncNotice, {QS("showHistorySyncNotice"), true}} }; diff --git a/src/utils/config.h b/src/utils/config.h index 460a8b8..5f48b7e 100644 --- a/src/utils/config.h +++ b/src/utils/config.h @@ -47,7 +47,8 @@ public: windowState, firstRun, hideBalance, - redditFrontend + redditFrontend, + showHistorySyncNotice }; ~Config() override;