Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change staking tooltip to display frequency #1611

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,12 @@ bool IsSuperBlock(CBlockIndex* pIndex);

double GetEstimatedNetworkWeight(unsigned int nPoSInterval = 40);
double GetAverageDifficulty(unsigned int nPoSInterval = 40);
//double GetEstimatedTimetoStake(unsigned int nPoSInterval = 40, double dConfidence = 0.8);
// Note that dDiff cannot be = 0 normally. This is set as default because you can't specify the output of
// GetAverageDifficulty(nPosInterval) = to dDiff here.
double GetEstimatedTimetoStake(double dDiff = 0.0, double dConfidence = 0.8);
// The defeult confidence is 1-1/e which is the mean for the geometric distribution.

const double DEFAULT_ETTS_CONFIDENCE = 0.632120558829;
double GetEstimatedTimetoStake(double dDiff = 0.0, double dConfidence = DEFAULT_ETTS_CONFIDENCE);

NN::ClaimOption GetClaimByIndex(const CBlockIndex* const pblockindex);

Expand Down
42 changes: 29 additions & 13 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1425,25 +1425,42 @@ void BitcoinGUI::timerfire()

}

QString BitcoinGUI::GetEstimatedTime(unsigned int nEstimateTime)
QString BitcoinGUI::GetEstimatedStakingFrequency(unsigned int nEstimateTime)
{
QString text;
if (nEstimateTime < 60)

if (!nEstimateTime)
{
text = tr("%n second(s)", "", nEstimateTime);
text = tr("undefined");

return text;
}
else if (nEstimateTime < 60*60)

// Start with 1/yr
double frequency = 3600.0 * 24.0 * 365.0 / nEstimateTime;
QString unit = tr("year");
double next_unit_threshold = 1.0;

if (frequency >= next_unit_threshold * 12.0)
{
text = tr("%n minute(s)", "", nEstimateTime/60);
frequency /= 12.0;
unit = tr("month");
}
else if (nEstimateTime < 24*60*60)

if (frequency >= next_unit_threshold * 30.0)
{
text = tr("%n hour(s)", "", nEstimateTime/(60*60));
frequency /= 30.0;
unit = tr("day");
}
else

if (frequency >= next_unit_threshold * 24.0)
{
text = tr("%n day(s)", "", nEstimateTime/(60*60*24));
frequency /= 24.0;
unit = tr("hour");
}

text = tr("%1 times per %2").arg(QString(RoundToString(frequency, 2).c_str())).arg(unit);

return text;
}

Expand All @@ -1454,21 +1471,20 @@ void BitcoinGUI::updateStakingIcon()
uint64_t nWeight, nLastInterval;
std::string ReasonNotStaking;
{ LOCK(MinerStatus.lock);
// not using real weight to not break calculation - fixed - but retaining GRC units for instead of internal weight units.
// nWeight is in GRC units rather than miner weight units because this is more familiar to users.
nWeight = MinerStatus.WeightSum / 80.0;
nLastInterval = MinerStatus.nLastCoinStakeSearchInterval;
ReasonNotStaking = MinerStatus.ReasonNotStaking;
}

uint64_t nNetworkWeight = GetEstimatedNetworkWeight() / 80.0;
bool staking = nLastInterval && nWeight;
uint64_t nEstimateTime = GetEstimatedTimetoStake();

if (staking)
{
QString text = GetEstimatedTime(nEstimateTime);
QString text = GetEstimatedStakingFrequency(GetEstimatedTimetoStake());
labelStakingIcon->setPixmap(QIcon(":/icons/staking_on").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
labelStakingIcon->setToolTip(tr("Staking.<br>Your weight is %1<br>Network weight is %2<br><b>Estimated</b> time to earn reward is %3.")
labelStakingIcon->setToolTip(tr("Staking.<br>Your weight is %1<br>Network weight is %2<br><b>Estimated</b> staking frequency is %3.")
.arg(nWeight).arg(nNetworkWeight).arg(text));
}
else
Expand Down
2 changes: 1 addition & 1 deletion src/qt/bitcoingui.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ private slots:
void updateStakingIcon();
void updateScraperIcon(int scraperEventtype, int status);

QString GetEstimatedTime(unsigned int nEstimateTime);
QString GetEstimatedStakingFrequency(unsigned int nEstimateTime);

void timerfire();

Expand Down