Skip to content

Commit 083f535

Browse files
committed
Merge #14608: qt: Remove the "Pay only required fee..." checkbox
a16f44c qt: Remove "Pay only required fee" checkbox (Hennadii Stepanov) 8711cc0 qt: Improve BitcoinAmountField class (Hennadii Stepanov) Pull request description: Ref #13280 This PR removes the "Pay only the required fee..." checkbox from the custom transaction fee section in the "Send" tab. Instead, a minimum value will be enforced on the custom fee input box. All comments from #13280 are addressed. Before: ![screenshot from 2018-10-30 16-42-18](https://user-images.githubusercontent.com/32963518/47726622-866d8e80-dc63-11e8-8670-3f97ff0fa5da.png) After: ![screenshot from 2018-10-30 16-40-37](https://user-images.githubusercontent.com/32963518/47726633-8f5e6000-dc63-11e8-82cf-5b9ff4aae91d.png) cc: @promag @MarcoFalke @Sjors Tree-SHA512: 073577d38d8353b10e8f36fb52e3c6e81dd45d25d84df9b9e4f78f452ff0bdbff3e225bdd6122b5a03839ffdcc2a2a08175f81c2541cf2d12918536abbfa3fd1
2 parents b60f4e3 + a16f44c commit 083f535

File tree

5 files changed

+75
-81
lines changed

5 files changed

+75
-81
lines changed

src/qt/bitcoinamountfield.cpp

Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ class AmountSpinBox: public QAbstractSpinBox
2323

2424
public:
2525
explicit AmountSpinBox(QWidget *parent):
26-
QAbstractSpinBox(parent),
27-
currentUnit(BitcoinUnits::BTC),
28-
singleStep(100000) // satoshis
26+
QAbstractSpinBox(parent)
2927
{
3028
setAlignment(Qt::AlignRight);
3129

@@ -44,10 +42,19 @@ class AmountSpinBox: public QAbstractSpinBox
4442

4543
void fixup(QString &input) const
4644
{
47-
bool valid = false;
48-
CAmount val = parse(input, &valid);
49-
if(valid)
50-
{
45+
bool valid;
46+
CAmount val;
47+
48+
if (input.isEmpty() && !m_allow_empty) {
49+
valid = true;
50+
val = m_min_amount;
51+
} else {
52+
valid = false;
53+
val = parse(input, &valid);
54+
}
55+
56+
if (valid) {
57+
val = qBound(m_min_amount, val, m_max_amount);
5158
input = BitcoinUnits::format(currentUnit, val, false, BitcoinUnits::separatorAlways);
5259
lineEdit()->setText(input);
5360
}
@@ -64,12 +71,27 @@ class AmountSpinBox: public QAbstractSpinBox
6471
Q_EMIT valueChanged();
6572
}
6673

74+
void SetAllowEmpty(bool allow)
75+
{
76+
m_allow_empty = allow;
77+
}
78+
79+
void SetMinValue(const CAmount& value)
80+
{
81+
m_min_amount = value;
82+
}
83+
84+
void SetMaxValue(const CAmount& value)
85+
{
86+
m_max_amount = value;
87+
}
88+
6789
void stepBy(int steps)
6890
{
6991
bool valid = false;
7092
CAmount val = value(&valid);
7193
val = val + steps * singleStep;
72-
val = qMin(qMax(val, CAmount(0)), BitcoinUnits::maxMoney());
94+
val = qBound(m_min_amount, val, m_max_amount);
7395
setValue(val);
7496
}
7597

@@ -125,9 +147,12 @@ class AmountSpinBox: public QAbstractSpinBox
125147
}
126148

127149
private:
128-
int currentUnit;
129-
CAmount singleStep;
150+
int currentUnit{BitcoinUnits::BTC};
151+
CAmount singleStep{CAmount(100000)}; // satoshis
130152
mutable QSize cachedMinimumSizeHint;
153+
bool m_allow_empty{true};
154+
CAmount m_min_amount{CAmount(0)};
155+
CAmount m_max_amount{BitcoinUnits::maxMoney()};
131156

132157
/**
133158
* Parse a string into a number of base monetary units and
@@ -174,11 +199,10 @@ class AmountSpinBox: public QAbstractSpinBox
174199
StepEnabled rv = 0;
175200
bool valid = false;
176201
CAmount val = value(&valid);
177-
if(valid)
178-
{
179-
if(val > 0)
202+
if (valid) {
203+
if (val > m_min_amount)
180204
rv |= StepDownEnabled;
181-
if(val < BitcoinUnits::maxMoney())
205+
if (val < m_max_amount)
182206
rv |= StepUpEnabled;
183207
}
184208
return rv;
@@ -275,6 +299,21 @@ void BitcoinAmountField::setValue(const CAmount& value)
275299
amount->setValue(value);
276300
}
277301

302+
void BitcoinAmountField::SetAllowEmpty(bool allow)
303+
{
304+
amount->SetAllowEmpty(allow);
305+
}
306+
307+
void BitcoinAmountField::SetMinValue(const CAmount& value)
308+
{
309+
amount->SetMinValue(value);
310+
}
311+
312+
void BitcoinAmountField::SetMaxValue(const CAmount& value)
313+
{
314+
amount->SetMaxValue(value);
315+
}
316+
278317
void BitcoinAmountField::setReadOnly(bool fReadOnly)
279318
{
280319
amount->setReadOnly(fReadOnly);

src/qt/bitcoinamountfield.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ class BitcoinAmountField: public QWidget
3131
CAmount value(bool *value=0) const;
3232
void setValue(const CAmount& value);
3333

34+
/** If allow empty is set to false the field will be set to the minimum allowed value if left empty. **/
35+
void SetAllowEmpty(bool allow);
36+
37+
/** Set the minimum value in satoshis **/
38+
void SetMinValue(const CAmount& value);
39+
40+
/** Set the maximum value in satoshis **/
41+
void SetMaxValue(const CAmount& value);
42+
3443
/** Set single step in satoshis **/
3544
void setSingleStep(const CAmount& step);
3645

src/qt/forms/sendcoinsdialog.ui

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -878,28 +878,15 @@ Note: Since the fee is calculated on a per-byte basis, a fee of "100 satoshis p
878878
<item>
879879
<layout class="QHBoxLayout" name="horizontalLayoutFee8">
880880
<item>
881-
<widget class="QCheckBox" name="checkBoxMinimumFee">
882-
<property name="toolTip">
883-
<string>Paying only the minimum fee is just fine as long as there is less transaction volume than space in the blocks. But be aware that this can end up in a never confirming transaction once there is more demand for bitcoin transactions than the network can process.</string>
884-
</property>
885-
<property name="text">
886-
<string/>
887-
</property>
888-
</widget>
889-
</item>
890-
<item>
891-
<widget class="QLabel" name="labelMinFeeWarning">
881+
<widget class="QLabel" name="labelCustomFeeWarning">
892882
<property name="enabled">
893883
<bool>true</bool>
894884
</property>
895885
<property name="toolTip">
896-
<string>Paying only the minimum fee is just fine as long as there is less transaction volume than space in the blocks. But be aware that this can end up in a never confirming transaction once there is more demand for bitcoin transactions than the network can process.</string>
886+
<string>When there is less transaction volume than space in the blocks, miners as well as relaying nodes may enforce a minimum fee. Paying only this minimum fee is just fine, but be aware that this can result in a never confirming transaction once there is more demand for bitcoin transactions than the network can process.</string>
897887
</property>
898888
<property name="text">
899-
<string>(read the tooltip)</string>
900-
</property>
901-
<property name="margin">
902-
<number>5</number>
889+
<string>A too low fee might result in a never confirming transaction (read the tooltip)</string>
903890
</property>
904891
</widget>
905892
</item>
@@ -992,9 +979,6 @@ Note: Since the fee is calculated on a per-byte basis, a fee of "100 satoshis p
992979
<property name="text">
993980
<string/>
994981
</property>
995-
<property name="margin">
996-
<number>2</number>
997-
</property>
998982
</widget>
999983
</item>
1000984
<item>
@@ -1009,9 +993,6 @@ Note: Since the fee is calculated on a per-byte basis, a fee of "100 satoshis p
1009993
<property name="text">
1010994
<string>(Smart fee not initialized yet. This usually takes a few blocks...)</string>
1011995
</property>
1012-
<property name="margin">
1013-
<number>2</number>
1014-
</property>
1015996
</widget>
1016997
</item>
1017998
<item>
@@ -1038,24 +1019,8 @@ Note: Since the fee is calculated on a per-byte basis, a fee of "100 satoshis p
10381019
<property name="text">
10391020
<string>Confirmation time target:</string>
10401021
</property>
1041-
<property name="margin">
1042-
<number>2</number>
1043-
</property>
10441022
</widget>
10451023
</item>
1046-
<item>
1047-
<spacer name="verticalSpacer_3">
1048-
<property name="orientation">
1049-
<enum>Qt::Vertical</enum>
1050-
</property>
1051-
<property name="sizeHint" stdset="0">
1052-
<size>
1053-
<width>1</width>
1054-
<height>1</height>
1055-
</size>
1056-
</property>
1057-
</spacer>
1058-
</item>
10591024
</layout>
10601025
</item>
10611026
<item>

src/qt/sendcoinsdialog.cpp

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,11 @@ SendCoinsDialog::SendCoinsDialog(const PlatformStyle *_platformStyle, QWidget *p
119119
settings.setValue("nSmartFeeSliderPosition", 0);
120120
if (!settings.contains("nTransactionFee"))
121121
settings.setValue("nTransactionFee", (qint64)DEFAULT_PAY_TX_FEE);
122-
if (!settings.contains("fPayOnlyMinFee"))
123-
settings.setValue("fPayOnlyMinFee", false);
124122
ui->groupFee->setId(ui->radioSmartFee, 0);
125123
ui->groupFee->setId(ui->radioCustomFee, 1);
126124
ui->groupFee->button((int)std::max(0, std::min(1, settings.value("nFeeRadio").toInt())))->setChecked(true);
125+
ui->customFee->SetAllowEmpty(false);
127126
ui->customFee->setValue(settings.value("nTransactionFee").toLongLong());
128-
ui->checkBoxMinimumFee->setChecked(settings.value("fPayOnlyMinFee").toBool());
129127
minimizeFeeSection(settings.value("fFeeSectionMinimized").toBool());
130128
}
131129

@@ -174,14 +172,15 @@ void SendCoinsDialog::setModel(WalletModel *_model)
174172
connect(ui->groupFee, static_cast<void (QButtonGroup::*)(int)>(&QButtonGroup::buttonClicked), this, &SendCoinsDialog::updateFeeSectionControls);
175173
connect(ui->groupFee, static_cast<void (QButtonGroup::*)(int)>(&QButtonGroup::buttonClicked), this, &SendCoinsDialog::coinControlUpdateLabels);
176174
connect(ui->customFee, &BitcoinAmountField::valueChanged, this, &SendCoinsDialog::coinControlUpdateLabels);
177-
connect(ui->checkBoxMinimumFee, &QCheckBox::stateChanged, this, &SendCoinsDialog::setMinimumFee);
178-
connect(ui->checkBoxMinimumFee, &QCheckBox::stateChanged, this, &SendCoinsDialog::updateFeeSectionControls);
179-
connect(ui->checkBoxMinimumFee, &QCheckBox::stateChanged, this, &SendCoinsDialog::coinControlUpdateLabels);
180175
connect(ui->optInRBF, &QCheckBox::stateChanged, this, &SendCoinsDialog::updateSmartFeeLabel);
181176
connect(ui->optInRBF, &QCheckBox::stateChanged, this, &SendCoinsDialog::coinControlUpdateLabels);
182-
ui->customFee->setSingleStep(model->wallet().getRequiredFee(1000));
177+
CAmount requiredFee = model->wallet().getRequiredFee(1000);
178+
ui->customFee->SetMinValue(requiredFee);
179+
if (ui->customFee->value() < requiredFee) {
180+
ui->customFee->setValue(requiredFee);
181+
}
182+
ui->customFee->setSingleStep(requiredFee);
183183
updateFeeSectionControls();
184-
updateMinFeeLabel();
185184
updateSmartFeeLabel();
186185

187186
// set default rbf checkbox state
@@ -210,7 +209,6 @@ SendCoinsDialog::~SendCoinsDialog()
210209
settings.setValue("nFeeRadio", ui->groupFee->checkedId());
211210
settings.setValue("nConfTarget", getConfTargetForIndex(ui->confTargetSelector->currentIndex()));
212211
settings.setValue("nTransactionFee", (qint64)ui->customFee->value());
213-
settings.setValue("fPayOnlyMinFee", ui->checkBoxMinimumFee->isChecked());
214212

215213
delete ui;
216214
}
@@ -542,7 +540,6 @@ void SendCoinsDialog::updateDisplayUnit()
542540
{
543541
setBalance(model->wallet().getBalances());
544542
ui->customFee->setDisplayUnit(model->getOptionsModel()->getDisplayUnit());
545-
updateMinFeeLabel();
546543
updateSmartFeeLabel();
547544
}
548545

@@ -642,22 +639,16 @@ void SendCoinsDialog::useAvailableBalance(SendCoinsEntry* entry)
642639
}
643640
}
644641

645-
void SendCoinsDialog::setMinimumFee()
646-
{
647-
ui->customFee->setValue(model->wallet().getRequiredFee(1000));
648-
}
649-
650642
void SendCoinsDialog::updateFeeSectionControls()
651643
{
652644
ui->confTargetSelector ->setEnabled(ui->radioSmartFee->isChecked());
653645
ui->labelSmartFee ->setEnabled(ui->radioSmartFee->isChecked());
654646
ui->labelSmartFee2 ->setEnabled(ui->radioSmartFee->isChecked());
655647
ui->labelSmartFee3 ->setEnabled(ui->radioSmartFee->isChecked());
656648
ui->labelFeeEstimation ->setEnabled(ui->radioSmartFee->isChecked());
657-
ui->checkBoxMinimumFee ->setEnabled(ui->radioCustomFee->isChecked());
658-
ui->labelMinFeeWarning ->setEnabled(ui->radioCustomFee->isChecked());
659-
ui->labelCustomPerKilobyte ->setEnabled(ui->radioCustomFee->isChecked() && !ui->checkBoxMinimumFee->isChecked());
660-
ui->customFee ->setEnabled(ui->radioCustomFee->isChecked() && !ui->checkBoxMinimumFee->isChecked());
649+
ui->labelCustomFeeWarning ->setEnabled(ui->radioCustomFee->isChecked());
650+
ui->labelCustomPerKilobyte ->setEnabled(ui->radioCustomFee->isChecked());
651+
ui->customFee ->setEnabled(ui->radioCustomFee->isChecked());
661652
}
662653

663654
void SendCoinsDialog::updateFeeMinimizedLabel()
@@ -672,14 +663,6 @@ void SendCoinsDialog::updateFeeMinimizedLabel()
672663
}
673664
}
674665

675-
void SendCoinsDialog::updateMinFeeLabel()
676-
{
677-
if (model && model->getOptionsModel())
678-
ui->checkBoxMinimumFee->setText(tr("Pay only the required fee of %1").arg(
679-
BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), model->wallet().getRequiredFee(1000)) + "/kB")
680-
);
681-
}
682-
683666
void SendCoinsDialog::updateCoinControlState(CCoinControl& ctrl)
684667
{
685668
if (ui->radioCustomFee->isChecked()) {

src/qt/sendcoinsdialog.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,7 @@ private Q_SLOTS:
9292
void coinControlClipboardBytes();
9393
void coinControlClipboardLowOutput();
9494
void coinControlClipboardChange();
95-
void setMinimumFee();
9695
void updateFeeSectionControls();
97-
void updateMinFeeLabel();
9896
void updateSmartFeeLabel();
9997

10098
Q_SIGNALS:

0 commit comments

Comments
 (0)