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,52 @@ 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 some time (activeStakingMaxTime) 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 < ACTIVE_STAKING_MAX_TIME;
79
+
80
+ WalletModel::EncryptionStatus eStatus = this ->walletModel ->getEncryptionStatus ();
81
+
82
+ if (syncFlag){
83
+ ui->checkStaking ->setText (" Staking Disabled while Syncing" );
84
+ }else if (WalletModel::Locked == eStatus) {
85
+ ui->checkStaking ->setText (" Unlock wallet for Staking" );
86
+ }else if (this ->walletModel ->isStakingEnabled ()) {
87
+ if (fStakingActive ) {
88
+ ui->checkStaking ->setText (" Staking Enabled" );
89
+ }else {
90
+
91
+ interfaces::Wallet& wallet = walletModel->wallet ();
92
+ interfaces::WalletBalances balances = wallet.getBalances ();
93
+ int64_t zerocoin_balance = balances.zerocoin_balance ;
94
+
95
+ if (0.0 < zerocoin_balance) {
96
+ ui->checkStaking ->setText (" Enabling..." );
97
+ }else {
98
+ ui->checkStaking ->setText (" You need some zerocoin" );
99
+ }
100
+ }
101
+ }else {
102
+ if (fStakingActive ) {
103
+ ui->checkStaking ->setText (" Disabling..." );
104
+ }else {
105
+ ui->checkStaking ->setText (" Staking Disabled" );
106
+ }
107
+ }
108
+ }
109
+
62
110
void VeilStatusBar::onCheckStakingClicked (bool res) {
63
111
if (gArgs .GetBoolArg (" -disablewallet" , DEFAULT_DISABLE_WALLET))
64
112
return ;
@@ -77,16 +125,19 @@ void VeilStatusBar::onCheckStakingClicked(bool res) {
77
125
openToastDialog (dialogMsg, mainWindow);
78
126
fBlockNextStakeCheckSignal = true ;
79
127
ui->checkStaking ->setChecked (false );
128
+ setStakingText ();
80
129
return ;
81
130
}else {
82
131
this ->walletModel ->setStakingEnabled (true );
83
132
mainWindow->updateWalletStatus ();
84
133
openToastDialog (" Staking enabled" , mainWindow);
134
+ setStakingText ();
85
135
}
86
136
} else {
87
137
this ->walletModel ->setStakingEnabled (false );
88
138
mainWindow->updateWalletStatus ();
89
- openToastDialog (" Staking disabled" , mainWindow);
139
+ openToastDialog (" Staking disabled - this may a few minutes" , mainWindow);
140
+ setStakingText ();
90
141
}
91
142
92
143
}
@@ -192,11 +243,15 @@ void VeilStatusBar::updateStakingCheckbox()
192
243
193
244
if (walletModel) {
194
245
WalletModel::EncryptionStatus lockState = walletModel->getEncryptionStatus ();
195
- bool stakingStatus = walletModel->isStakingEnabled () && lockState != WalletModel::Locked;
246
+
247
+ ui->checkStaking ->setEnabled (!syncFlag);
248
+ setStakingText ();
249
+
250
+ bool stakingStatus = walletModel->isStakingEnabled () && lockState != WalletModel::Locked && !syncFlag;
196
251
if (ui->checkStaking ->isChecked () != stakingStatus) {
197
252
fBlockNextStakeCheckSignal = true ;
198
253
ui->checkStaking ->setChecked (stakingStatus);
199
- return ;
254
+ return ;
200
255
}
201
256
}
202
257
}
0 commit comments