Skip to content

Commit 7f59bdb

Browse files
committed
Add percent progress and height of peers to blocks field
This commit adds a conditional height of peers and percent progress indicator to the blocks field on the overview screen to provide more information during a wallet sync.
1 parent 3ca3a44 commit 7f59bdb

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

src/qt/bitcoingui.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,11 @@ void BitcoinGUI::setNumConnections(int n)
980980

981981
void BitcoinGUI::setNumBlocks(int count, int nTotalBlocks)
982982
{
983+
// Note: It is a really good question why the GUI uses a different standard than the core for determining whether
984+
// the client is in sync.
985+
// TODO: Review this and decide whether to converge the sync standards.
986+
bool in_sync = false;
987+
983988
// return if we have no connection to the network
984989
if (!clientModel || clientModel->getNumConnections() == 0)
985990
{
@@ -1023,6 +1028,7 @@ void BitcoinGUI::setNumBlocks(int count, int nTotalBlocks)
10231028
labelBlocksIcon->setPixmap(GRC::ScaleStatusIcon(this, ":/icons/status_sync_done_" + sSheet));
10241029

10251030
overviewPage->showOutOfSyncWarning(false);
1031+
in_sync = true;
10261032
statusbarAlertsLabel->setText(clientModel->getStatusBarWarnings());
10271033
}
10281034
else
@@ -1031,6 +1037,7 @@ void BitcoinGUI::setNumBlocks(int count, int nTotalBlocks)
10311037
tooltip = tr("Catching up...") + QString("<br>") + tooltip;
10321038

10331039
overviewPage->showOutOfSyncWarning(true);
1040+
in_sync = false;
10341041
}
10351042

10361043
if(!text.isEmpty())
@@ -1043,7 +1050,7 @@ void BitcoinGUI::setNumBlocks(int count, int nTotalBlocks)
10431050
tooltip = QString("<nobr>") + tooltip + QString("</nobr>");
10441051

10451052
labelBlocksIcon->setToolTip(tooltip);
1046-
overviewPage->setHeight(count);
1053+
overviewPage->setHeight(count, nTotalBlocks, in_sync);
10471054
}
10481055

10491056
void BitcoinGUI::setDifficulty(double difficulty)

src/qt/overviewpage.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,20 @@ void OverviewPage::setBalance(qint64 balance, qint64 stake, qint64 unconfirmedBa
276276
ui->immatureTextLabel->setVisible(showImmature);
277277
}
278278

279-
void OverviewPage::setHeight(int height)
279+
void OverviewPage::setHeight(int height, int height_of_peers, bool in_sync)
280280
{
281-
ui->blocksLabel->setText(QString::number(height));
281+
QString text = QString::number(height);
282+
unsigned int percent_progress = 0;
283+
284+
if (!in_sync && height_of_peers > 0 && height < height_of_peers) {
285+
percent_progress = height * 100 / height_of_peers;
286+
287+
text += QString(" of %1 (%2\%)")
288+
.arg(QString::number(height_of_peers))
289+
.arg(QString::number(percent_progress));
290+
}
291+
292+
ui->blocksLabel->setText(text);
282293
}
283294

284295
void OverviewPage::setDifficulty(double difficulty, double net_weight)

src/qt/overviewpage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class OverviewPage : public QWidget
3131

3232
public slots:
3333
void setBalance(qint64 balance, qint64 stake, qint64 unconfirmedBalance, qint64 immatureBalance);
34-
void setHeight(int height);
34+
void setHeight(int height, int height_of_peers, bool in_sync);
3535
void setDifficulty(double difficulty, double net_weight);
3636
void setCoinWeight(double coin_weight);
3737
void setCurrentPollTitle(const QString& title);

0 commit comments

Comments
 (0)