mirror of
https://github.com/feather-wallet/feather.git
synced 2024-11-17 01:37:53 +00:00
lock: add sync status
This commit is contained in:
parent
6a3b3fc830
commit
082413dc0d
9 changed files with 79 additions and 35 deletions
|
@ -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)
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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>
|
||||
|
@ -168,6 +170,37 @@
|
|||
</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/>
|
||||
|
|
Loading…
Reference in a new issue