10
10
#include < qt/walletmodel.h>
11
11
#include < qt/veil/qtutils.h>
12
12
#include < iostream>
13
+ #include < timedata.h>
13
14
#ifdef ENABLE_WALLET
14
15
#include < wallet/wallet.h> // For DEFAULT_DISABLE_WALLET
15
16
#endif
@@ -51,6 +52,7 @@ void VeilStatusBar::updateSyncIndicator(int height){
51
52
52
53
void VeilStatusBar::setSyncStatusVisible (bool fVisible ) {
53
54
ui->btnSync ->setVisible (fVisible );
55
+ syncFlag = fVisible ;
54
56
}
55
57
56
58
void VeilStatusBar::onBtnSyncClicked (){
@@ -59,6 +61,39 @@ void VeilStatusBar::onBtnSyncClicked(){
59
61
60
62
#ifdef ENABLE_WALLET
61
63
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
+
62
97
void VeilStatusBar::onCheckStakingClicked (bool res) {
63
98
if (gArgs .GetBoolArg (" -disablewallet" , DEFAULT_DISABLE_WALLET))
64
99
return ;
@@ -77,16 +112,19 @@ void VeilStatusBar::onCheckStakingClicked(bool res) {
77
112
openToastDialog (dialogMsg, mainWindow);
78
113
fBlockNextStakeCheckSignal = true ;
79
114
ui->checkStaking ->setChecked (false );
115
+ setStakingText ();
80
116
return ;
81
117
}else {
82
118
this ->walletModel ->setStakingEnabled (true );
83
119
mainWindow->updateWalletStatus ();
84
120
openToastDialog (" Staking enabled" , mainWindow);
121
+ setStakingText ();
85
122
}
86
123
} else {
87
124
this ->walletModel ->setStakingEnabled (false );
88
125
mainWindow->updateWalletStatus ();
89
- openToastDialog (" Staking disabled" , mainWindow);
126
+ openToastDialog (" Staking disabled - this may take up to 70 seconds" , mainWindow);
127
+ setStakingText ();
90
128
}
91
129
92
130
}
@@ -192,11 +230,15 @@ void VeilStatusBar::updateStakingCheckbox()
192
230
193
231
if (walletModel) {
194
232
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;
196
238
if (ui->checkStaking ->isChecked () != stakingStatus) {
197
239
fBlockNextStakeCheckSignal = true ;
198
240
ui->checkStaking ->setChecked (stakingStatus);
199
- return ;
241
+ return ;
200
242
}
201
243
}
202
244
}
0 commit comments