Skip to content

Commit

Permalink
[GUI] Update Staking Slider to be reflective of status
Browse files Browse the repository at this point in the history
  • Loading branch information
WetOne committed Dec 6, 2020
1 parent 2f83d92 commit 73fe46f
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,8 @@ void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate, double nVer
tooltip += tr("Transactions after this will not yet be visible.");
}

veilStatusBar->updateStakingCheckbox();

// Don't word-wrap this (fixed-width) tooltip
tooltip = QString("<nobr>") + tooltip + QString("</nobr>");

Expand Down
48 changes: 45 additions & 3 deletions src/qt/veil/veilstatusbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <qt/walletmodel.h>
#include <qt/veil/qtutils.h>
#include <iostream>
#include <timedata.h>
#ifdef ENABLE_WALLET
#include <wallet/wallet.h> // For DEFAULT_DISABLE_WALLET
#endif
Expand Down Expand Up @@ -51,6 +52,7 @@ void VeilStatusBar::updateSyncIndicator(int height){

void VeilStatusBar::setSyncStatusVisible(bool fVisible) {
ui->btnSync->setVisible(fVisible);
syncFlag = fVisible;
}

void VeilStatusBar::onBtnSyncClicked(){
Expand All @@ -59,6 +61,39 @@ void VeilStatusBar::onBtnSyncClicked(){

#ifdef ENABLE_WALLET
bool fBlockNextStakeCheckSignal = false;
void VeilStatusBar::setStakingText() {

// 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.
int64_t nTimeLastHashing = 0;
if (!mapHashedBlocks.empty()) {
auto pindexBest = chainActive.Tip();
if (mapHashedBlocks.count(pindexBest->GetBlockHash())) {
nTimeLastHashing = mapHashedBlocks.at(pindexBest->GetBlockHash());
} else if (mapHashedBlocks.count(pindexBest->pprev->GetBlockHash())) {
nTimeLastHashing = mapHashedBlocks.at(pindexBest->pprev->GetBlockHash());
}
}
bool fStakingActive = false;
if (nTimeLastHashing)
fStakingActive = GetAdjustedTime() + MAX_FUTURE_BLOCK_TIME - nTimeLastHashing < 70;

if (this->walletModel->isStakingEnabled()) {
if (fStakingActive) {
ui->checkStaking->setText("Staking Enabled");
}else{
ui->checkStaking->setText("Enabling...");
}
}else if (syncFlag){
ui->checkStaking->setText("Staking Disabled while Syncing");
}else{
if (fStakingActive) {
ui->checkStaking->setText("Disabling...");
}else{
ui->checkStaking->setText("Staking Disabled");
}
}
}

void VeilStatusBar::onCheckStakingClicked(bool res) {
if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET))
return;
Expand All @@ -77,16 +112,19 @@ void VeilStatusBar::onCheckStakingClicked(bool res) {
openToastDialog(dialogMsg, mainWindow);
fBlockNextStakeCheckSignal = true;
ui->checkStaking->setChecked(false);
setStakingText();
return;
}else{
this->walletModel->setStakingEnabled(true);
mainWindow->updateWalletStatus();
openToastDialog("Staking enabled", mainWindow);
setStakingText();
}
} else {
this->walletModel->setStakingEnabled(false);
mainWindow->updateWalletStatus();
openToastDialog("Staking disabled", mainWindow);
openToastDialog("Staking disabled - this may take up to 70 seconds", mainWindow);
setStakingText();
}

}
Expand Down Expand Up @@ -192,11 +230,15 @@ void VeilStatusBar::updateStakingCheckbox()

if(walletModel) {
WalletModel::EncryptionStatus lockState = walletModel->getEncryptionStatus();
bool stakingStatus = walletModel->isStakingEnabled() && lockState != WalletModel::Locked;

ui->checkStaking->setEnabled(!syncFlag);
setStakingText();

bool stakingStatus = walletModel->isStakingEnabled() && lockState != WalletModel::Locked && !syncFlag;
if (ui->checkStaking->isChecked() != stakingStatus) {
fBlockNextStakeCheckSignal = true;
ui->checkStaking->setChecked(stakingStatus);
return;
return;
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/qt/veil/veilstatusbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,12 @@ private Q_SLOTS:
WalletModel *walletModel = nullptr;
ClientModel *clientModel = nullptr;
UnlockPasswordDialog *unlockPasswordDialog = nullptr;
#ifdef ENABLE_WALLET
void setStakingText();
#endif

bool preparingFlag = false;
bool syncFlag = true;
};

#endif // VEILSTATUSBAR_H
3 changes: 3 additions & 0 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3388,6 +3388,7 @@ static UniValue getwalletinfo(const JSONRPCRequest& request)
" \"hdseedid\": \"<hash160>\" (string, optional) the Hash160 of the HD seed (only present when HD is enabled)\n"
" \"hdmasterkeyid\": \"<hash160>\" (string, optional) alias for hdseedid retained for backwards-compatibility. Will be removed in V0.18.\n"
" \"private_keys_enabled\": true|false (boolean) false if privatekeys are disabled for this wallet (enforced watch-only wallet)\n"
" \"staking_enabled\" : true|false (boolean) true if staking is enabled\n"
" \"staking_active\": true|false (boolean) true if wallet is actively trying to create new blocks using proof of stake\n"
"}\n"
"\nExamples:\n"
Expand Down Expand Up @@ -3426,6 +3427,8 @@ static UniValue getwalletinfo(const JSONRPCRequest& request)
}
obj.pushKV("private_keys_enabled", !pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS));

obj.pushKV("staking_enabled", pwallet->IsStakingEnabled());

// 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.
int64_t nTimeLastHashing = 0;
if (!mapHashedBlocks.empty()) {
Expand Down

0 comments on commit 73fe46f

Please sign in to comment.