Skip to content

Commit 73fe46f

Browse files
committed
[GUI] Update Staking Slider to be reflective of status
1 parent 2f83d92 commit 73fe46f

File tree

4 files changed

+54
-3
lines changed

4 files changed

+54
-3
lines changed

src/qt/bitcoingui.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,8 @@ void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate, double nVer
988988
tooltip += tr("Transactions after this will not yet be visible.");
989989
}
990990

991+
veilStatusBar->updateStakingCheckbox();
992+
991993
// Don't word-wrap this (fixed-width) tooltip
992994
tooltip = QString("<nobr>") + tooltip + QString("</nobr>");
993995

src/qt/veil/veilstatusbar.cpp

+45-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <qt/walletmodel.h>
1111
#include <qt/veil/qtutils.h>
1212
#include <iostream>
13+
#include <timedata.h>
1314
#ifdef ENABLE_WALLET
1415
#include <wallet/wallet.h> // For DEFAULT_DISABLE_WALLET
1516
#endif
@@ -51,6 +52,7 @@ void VeilStatusBar::updateSyncIndicator(int height){
5152

5253
void VeilStatusBar::setSyncStatusVisible(bool fVisible) {
5354
ui->btnSync->setVisible(fVisible);
55+
syncFlag = fVisible;
5456
}
5557

5658
void VeilStatusBar::onBtnSyncClicked(){
@@ -59,6 +61,39 @@ void VeilStatusBar::onBtnSyncClicked(){
5961

6062
#ifdef ENABLE_WALLET
6163
bool fBlockNextStakeCheckSignal = false;
64+
void VeilStatusBar::setStakingText() {
65+
66+
// Determine if staking is recently active. Note that this is not immediate effect. Staking could be disabled and it could take up to 70 seconds to update state.
67+
int64_t nTimeLastHashing = 0;
68+
if (!mapHashedBlocks.empty()) {
69+
auto pindexBest = chainActive.Tip();
70+
if (mapHashedBlocks.count(pindexBest->GetBlockHash())) {
71+
nTimeLastHashing = mapHashedBlocks.at(pindexBest->GetBlockHash());
72+
} else if (mapHashedBlocks.count(pindexBest->pprev->GetBlockHash())) {
73+
nTimeLastHashing = mapHashedBlocks.at(pindexBest->pprev->GetBlockHash());
74+
}
75+
}
76+
bool fStakingActive = false;
77+
if (nTimeLastHashing)
78+
fStakingActive = GetAdjustedTime() + MAX_FUTURE_BLOCK_TIME - nTimeLastHashing < 70;
79+
80+
if (this->walletModel->isStakingEnabled()) {
81+
if (fStakingActive) {
82+
ui->checkStaking->setText("Staking Enabled");
83+
}else{
84+
ui->checkStaking->setText("Enabling...");
85+
}
86+
}else if (syncFlag){
87+
ui->checkStaking->setText("Staking Disabled while Syncing");
88+
}else{
89+
if (fStakingActive) {
90+
ui->checkStaking->setText("Disabling...");
91+
}else{
92+
ui->checkStaking->setText("Staking Disabled");
93+
}
94+
}
95+
}
96+
6297
void VeilStatusBar::onCheckStakingClicked(bool res) {
6398
if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET))
6499
return;
@@ -77,16 +112,19 @@ void VeilStatusBar::onCheckStakingClicked(bool res) {
77112
openToastDialog(dialogMsg, mainWindow);
78113
fBlockNextStakeCheckSignal = true;
79114
ui->checkStaking->setChecked(false);
115+
setStakingText();
80116
return;
81117
}else{
82118
this->walletModel->setStakingEnabled(true);
83119
mainWindow->updateWalletStatus();
84120
openToastDialog("Staking enabled", mainWindow);
121+
setStakingText();
85122
}
86123
} else {
87124
this->walletModel->setStakingEnabled(false);
88125
mainWindow->updateWalletStatus();
89-
openToastDialog("Staking disabled", mainWindow);
126+
openToastDialog("Staking disabled - this may take up to 70 seconds", mainWindow);
127+
setStakingText();
90128
}
91129

92130
}
@@ -192,11 +230,15 @@ void VeilStatusBar::updateStakingCheckbox()
192230

193231
if(walletModel) {
194232
WalletModel::EncryptionStatus lockState = walletModel->getEncryptionStatus();
195-
bool stakingStatus = walletModel->isStakingEnabled() && lockState != WalletModel::Locked;
233+
234+
ui->checkStaking->setEnabled(!syncFlag);
235+
setStakingText();
236+
237+
bool stakingStatus = walletModel->isStakingEnabled() && lockState != WalletModel::Locked && !syncFlag;
196238
if (ui->checkStaking->isChecked() != stakingStatus) {
197239
fBlockNextStakeCheckSignal = true;
198240
ui->checkStaking->setChecked(stakingStatus);
199-
return;
241+
return;
200242
}
201243
}
202244
}

src/qt/veil/veilstatusbar.h

+4
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,12 @@ private Q_SLOTS:
5252
WalletModel *walletModel = nullptr;
5353
ClientModel *clientModel = nullptr;
5454
UnlockPasswordDialog *unlockPasswordDialog = nullptr;
55+
#ifdef ENABLE_WALLET
56+
void setStakingText();
57+
#endif
5558

5659
bool preparingFlag = false;
60+
bool syncFlag = true;
5761
};
5862

5963
#endif // VEILSTATUSBAR_H

src/wallet/rpcwallet.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -3388,6 +3388,7 @@ static UniValue getwalletinfo(const JSONRPCRequest& request)
33883388
" \"hdseedid\": \"<hash160>\" (string, optional) the Hash160 of the HD seed (only present when HD is enabled)\n"
33893389
" \"hdmasterkeyid\": \"<hash160>\" (string, optional) alias for hdseedid retained for backwards-compatibility. Will be removed in V0.18.\n"
33903390
" \"private_keys_enabled\": true|false (boolean) false if privatekeys are disabled for this wallet (enforced watch-only wallet)\n"
3391+
" \"staking_enabled\" : true|false (boolean) true if staking is enabled\n"
33913392
" \"staking_active\": true|false (boolean) true if wallet is actively trying to create new blocks using proof of stake\n"
33923393
"}\n"
33933394
"\nExamples:\n"
@@ -3426,6 +3427,8 @@ static UniValue getwalletinfo(const JSONRPCRequest& request)
34263427
}
34273428
obj.pushKV("private_keys_enabled", !pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS));
34283429

3430+
obj.pushKV("staking_enabled", pwallet->IsStakingEnabled());
3431+
34293432
// Determine if staking is recently active. Note that this is not immediate effect. Staking could be disabled and it could take up to 70 seconds to update state.
34303433
int64_t nTimeLastHashing = 0;
34313434
if (!mapHashedBlocks.empty()) {

0 commit comments

Comments
 (0)