Skip to content

Commit 8299e3e

Browse files
committed
[GUI] SettingsWalletOptions: validate stake split threshold on save
1 parent c2dc5a5 commit 8299e3e

File tree

6 files changed

+50
-3
lines changed

6 files changed

+50
-3
lines changed

src/qt/optionsmodel.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ void OptionsModel::Init()
4747

4848
// Ensure restart flag is unset on client startup
4949
setRestartRequired(false);
50+
setSSTChanged(false);
5051

5152
// These are Qt-only settings:
5253

@@ -379,6 +380,7 @@ bool OptionsModel::setData(const QModelIndex& index, const QVariant& value, int
379380
case StakeSplitThreshold:
380381
// Write double as qlonglong/CAmount
381382
setStakeSplitThreshold(static_cast<CAmount>(value.toDouble() * COIN));
383+
setSSTChanged(true);
382384
break;
383385
case DisplayUnit:
384386
setDisplayUnit(value);
@@ -485,6 +487,23 @@ void OptionsModel::setStakeSplitThreshold(const CAmount nStakeSplitThreshold)
485487
}
486488
}
487489

490+
/* returns default minimum value for stake split threshold as doulbe */
491+
double OptionsModel::getSSTMinimum() const
492+
{
493+
return static_cast<double>(CWallet::minStakeSplitThreshold / COIN);
494+
}
495+
496+
/* Verify that StakeSplitThreshold's value is either 0 or above the min. Else reset */
497+
bool OptionsModel::isSSTValid()
498+
{
499+
if (pwalletMain && pwalletMain->nStakeSplitThreshold &&
500+
pwalletMain->nStakeSplitThreshold < CWallet::minStakeSplitThreshold) {
501+
setStakeSplitThreshold(CWallet::minStakeSplitThreshold);
502+
return false;
503+
}
504+
return true;
505+
}
506+
488507
/* Update Custom Fee value in wallet */
489508
void OptionsModel::setUseCustomFee(bool fUse)
490509
{
@@ -541,3 +560,14 @@ bool OptionsModel::isRestartRequired()
541560
return settings.value("fRestartRequired", false).toBool();
542561
}
543562

563+
void OptionsModel::setSSTChanged(bool fChanged)
564+
{
565+
QSettings settings;
566+
return settings.setValue("fSSTChanged", fChanged);
567+
}
568+
569+
bool OptionsModel::isSSTChanged()
570+
{
571+
QSettings settings;
572+
return settings.value("fSSTChanged", false).toBool();
573+
}

src/qt/optionsmodel.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ class OptionsModel : public QAbstractListModel
7373
void setDisplayUnit(const QVariant& value);
7474
/* Update StakeSplitThreshold's value in wallet */
7575
void setStakeSplitThreshold(const CAmount value);
76+
double getSSTMinimum() const;
77+
bool isSSTValid();
7678
/* Update Custom Fee value in wallet */
7779
void setUseCustomFee(bool fUse);
7880
void setCustomFeeValue(const CAmount& value);
@@ -90,6 +92,8 @@ class OptionsModel : public QAbstractListModel
9092
/* Restart flag helper */
9193
void setRestartRequired(bool fRequired);
9294
bool isRestartRequired();
95+
void setSSTChanged(bool fChanged);
96+
bool isSSTChanged();
9397
bool resetSettings;
9498

9599
bool isColdStakingScreenEnabled() { return showColdStakingScreen; }

src/qt/pivx/settings/forms/settingswalletoptionswidget.ui

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,10 @@
124124
<item>
125125
<widget class="QDoubleSpinBox" name="spinBoxStakeSplitThreshold">
126126
<property name="decimals">
127-
<number>3</number>
127+
<number>8</number>
128128
</property>
129129
<property name="minimum">
130-
<number>1</number>
130+
<number>0</number>
131131
</property>
132132
<property name="maximum">
133133
<number>999999</number>

src/qt/pivx/settings/settingswalletoptionswidget.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ void SettingsWalletOptionsWidget::setMapper(QDataWidgetMapper *mapper){
7979
mapper->addMapping(ui->lineEditPort, OptionsModel::ProxyPort);
8080
}
8181

82+
void SettingsWalletOptionsWidget::setSpinBoxStakeSplitThreshold(double val)
83+
{
84+
ui->spinBoxStakeSplitThreshold->setValue(val);
85+
}
86+
8287
SettingsWalletOptionsWidget::~SettingsWalletOptionsWidget(){
8388
delete ui;
8489
}

src/qt/pivx/settings/settingswalletoptionswidget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class SettingsWalletOptionsWidget : public PWidget
2121
~SettingsWalletOptionsWidget();
2222

2323
void setMapper(QDataWidgetMapper *mapper);
24+
void setSpinBoxStakeSplitThreshold(double val);
2425

2526
Q_SIGNALS:
2627
void saveSettings();

src/qt/pivx/settings/settingswidget.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,15 @@ void SettingsWidget::onResetAction()
231231
void SettingsWidget::onSaveOptionsClicked()
232232
{
233233
if (mapper->submit()) {
234+
OptionsModel* optionsModel = this->clientModel->getOptionsModel();
235+
if (optionsModel->isSSTChanged() && !optionsModel->isSSTValid()) {
236+
const double stakeSplitMinimum = optionsModel->getSSTMinimum();
237+
settingsWalletOptionsWidget->setSpinBoxStakeSplitThreshold(stakeSplitMinimum);
238+
inform(tr("Stake Split too low, it shall be either >= %1 or equal to 0 (to disable stake splitting)").arg(stakeSplitMinimum));
239+
return;
240+
}
234241
pwalletMain->MarkDirty();
235-
if (this->clientModel->getOptionsModel()->isRestartRequired()) {
242+
if (optionsModel->isRestartRequired()) {
236243
bool fAcceptRestart = openStandardDialog(tr("Restart required"), tr("Your wallet needs to be restarted to apply the changes\n"), tr("Restart Now"), tr("Restart Later"));
237244

238245
if (fAcceptRestart) {

0 commit comments

Comments
 (0)