Skip to content

Commit

Permalink
bitcoin#14608: qt: Remove the "Pay only required fee..." checkbox
Browse files Browse the repository at this point in the history
Removed RBF related changes

a16f44c qt: Remove "Pay only required fee" checkbox (Hennadii Stepanov)
8711cc0 qt: Improve BitcoinAmountField class (Hennadii Stepanov)

Pull request description:

  Ref bitcoin#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 bitcoin#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
  • Loading branch information
jonasschnelli authored and christiancfifi committed Aug 28, 2021
1 parent 4488338 commit 786dbd0
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 57 deletions.
50 changes: 46 additions & 4 deletions src/qt/bitcoinamountfield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,19 @@ class AmountLineEdit: public QLineEdit

void fixup(const QString &input)
{
bool valid = false;
CAmount val = parse(input, currentUnit, &valid);
if(valid)
{
bool valid;
CAmount val;

if (input.isEmpty() && !m_allow_empty) {
valid = true;
val = m_min_amount;
} else {
valid = false;
val = parse(input, currentUnit &valid);
}

if (valid) {
val = qBound(m_min_amount, val, m_max_amount);
setText(BitcoinUnits::format(currentUnit, val, false, BitcoinUnits::separatorAlways));
}
}
Expand All @@ -98,6 +107,21 @@ class AmountLineEdit: public QLineEdit
Q_EMIT valueChanged();
}

void SetAllowEmpty(bool allow)
{
m_allow_empty = allow;
}

void SetMinValue(const CAmount& value)
{
m_min_amount = value;
}

void SetMaxValue(const CAmount& value)
{
m_max_amount = value;
}

void setDisplayUnit(int unit)
{
bool valid = false;
Expand Down Expand Up @@ -125,6 +149,9 @@ class AmountLineEdit: public QLineEdit

private:
int currentUnit;
bool m_allow_empty{true};
CAmount m_min_amount{CAmount(0)};
CAmount m_max_amount{BitcoinUnits::maxMoney()};

protected:
bool event(QEvent *event) override
Expand Down Expand Up @@ -233,6 +260,21 @@ void BitcoinAmountField::setValue(const CAmount& value)
amount->setValue(value);
}

void BitcoinAmountField::SetAllowEmpty(bool allow)
{
amount->SetAllowEmpty(allow);
}

void BitcoinAmountField::SetMinValue(const CAmount& value)
{
amount->SetMinValue(value);
}

void BitcoinAmountField::SetMaxValue(const CAmount& value)
{
amount->SetMaxValue(value);
}

void BitcoinAmountField::setReadOnly(bool fReadOnly)
{
amount->setReadOnly(fReadOnly);
Expand Down
9 changes: 9 additions & 0 deletions src/qt/bitcoinamountfield.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ class BitcoinAmountField: public QWidget
CAmount value(bool *value=0) const;
void setValue(const CAmount& value);

/** If allow empty is set to false the field will be set to the minimum allowed value if left empty. **/
void SetAllowEmpty(bool allow);

/** Set the minimum value in satoshis **/
void SetMinValue(const CAmount& value);

/** Set the maximum value in satoshis **/
void SetMaxValue(const CAmount& value);

/** Make read-only **/
void setReadOnly(bool fReadOnly);

Expand Down
28 changes: 3 additions & 25 deletions src/qt/forms/sendcoinsdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -814,28 +814,15 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayoutFee8">
<item>
<widget class="QCheckBox" name="checkBoxMinimumFee">
<property name="toolTip">
<string>Paying only the minimum fee is just fine as long as there is less transaction volume than space in the blocks.&lt;br /&gt;But be aware that this can end up in a never confirming transaction once there is more demand for dash transactions than the network can process.</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labelMinFeeWarning">
<widget class="QLabel" name="labelCustomFeeWarning">
<property name="enabled">
<bool>true</bool>
</property>
<property name="toolTip">
<string>Paying only the minimum fee is just fine as long as there is less transaction volume than space in the blocks.&lt;br /&gt;But be aware that this can end up in a never confirming transaction once there is more demand for dash transactions than the network can process.</string>
<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 Dash transactions than the network can process.</string>
</property>
<property name="text">
<string>(read the tooltip)</string>
</property>
<property name="margin">
<number>5</number>
<string>A too low fee might result in a never confirming transaction (read the tooltip)</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -940,9 +927,6 @@
<property name="text">
<string/>
</property>
<property name="margin">
<number>2</number>
</property>
</widget>
</item>
<item>
Expand All @@ -957,9 +941,6 @@
<property name="text">
<string>(Smart fee not initialized yet. This usually takes a few blocks...)</string>
</property>
<property name="margin">
<number>2</number>
</property>
</widget>
</item>
<item>
Expand All @@ -986,9 +967,6 @@
<property name="text">
<string>Confirmation time target:</string>
</property>
<property name="margin">
<number>2</number>
</property>
</widget>
</item>
</layout>
Expand Down
35 changes: 9 additions & 26 deletions src/qt/sendcoinsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,12 @@ SendCoinsDialog::SendCoinsDialog(bool _fCoinJoin, QWidget* parent) :
settings.setValue("nSmartFeeSliderPosition", 0);
if (!settings.contains("nTransactionFee"))
settings.setValue("nTransactionFee", (qint64)DEFAULT_PAY_TX_FEE);
if (!settings.contains("fPayOnlyMinFee"))
settings.setValue("fPayOnlyMinFee", false);

ui->groupFee->setId(ui->radioSmartFee, 0);
ui->groupFee->setId(ui->radioCustomFee, 1);
ui->groupFee->button((int)std::max(0, std::min(1, settings.value("nFeeRadio").toInt())))->setChecked(true);
ui->customFee->SetAllowEmpty(false);
ui->customFee->setValue(settings.value("nTransactionFee").toLongLong());
ui->checkBoxMinimumFee->setChecked(settings.value("fPayOnlyMinFee").toBool());
minimizeFeeSection(settings.value("fFeeSectionMinimized").toBool());

if (_fCoinJoin) {
Expand Down Expand Up @@ -195,11 +193,12 @@ void SendCoinsDialog::setModel(WalletModel *_model)
connect(ui->groupFee, static_cast<void (QButtonGroup::*)(int)>(&QButtonGroup::buttonClicked), this, &SendCoinsDialog::updateFeeSectionControls);
connect(ui->groupFee, static_cast<void (QButtonGroup::*)(int)>(&QButtonGroup::buttonClicked), this, &SendCoinsDialog::coinControlUpdateLabels);
connect(ui->customFee, &BitcoinAmountField::valueChanged, this, &SendCoinsDialog::coinControlUpdateLabels);
connect(ui->checkBoxMinimumFee, &QCheckBox::stateChanged, this, &SendCoinsDialog::setMinimumFee);
connect(ui->checkBoxMinimumFee, &QCheckBox::stateChanged, this, &SendCoinsDialog::updateFeeSectionControls);
connect(ui->checkBoxMinimumFee, &QCheckBox::stateChanged, this, &SendCoinsDialog::coinControlUpdateLabels);
CAmount requiredFee = model->wallet().getRequiredFee(1000);
ui->customFee->SetMinValue(requiredFee);
if (ui->customFee->value() < requiredFee) {
ui->customFee->setValue(requiredFee);
}
updateFeeSectionControls();
updateMinFeeLabel();
updateSmartFeeLabel();

// set the smartfee-sliders default value (wallets default conf.target or last stored value)
Expand All @@ -225,7 +224,6 @@ SendCoinsDialog::~SendCoinsDialog()
settings.setValue("nFeeRadio", ui->groupFee->checkedId());
settings.setValue("nConfTarget", getConfTargetForIndex(ui->confTargetSelector->currentIndex()));
settings.setValue("nTransactionFee", (qint64)ui->customFee->value());
settings.setValue("fPayOnlyMinFee", ui->checkBoxMinimumFee->isChecked());

delete ui;
}
Expand Down Expand Up @@ -618,7 +616,6 @@ void SendCoinsDialog::updateDisplayUnit()
setBalance(model->wallet().getBalances());
coinControlUpdateLabels();
ui->customFee->setDisplayUnit(model->getOptionsModel()->getDisplayUnit());
updateMinFeeLabel();
updateSmartFeeLabel();
}

Expand Down Expand Up @@ -712,22 +709,16 @@ void SendCoinsDialog::useAvailableBalance(SendCoinsEntry* entry)
}
}

void SendCoinsDialog::setMinimumFee()
{
ui->customFee->setValue(model->wallet().getRequiredFee(1000));
}

void SendCoinsDialog::updateFeeSectionControls()
{
ui->confTargetSelector ->setEnabled(ui->radioSmartFee->isChecked());
ui->labelSmartFee ->setEnabled(ui->radioSmartFee->isChecked());
ui->labelSmartFee2 ->setEnabled(ui->radioSmartFee->isChecked());
ui->labelSmartFee3 ->setEnabled(ui->radioSmartFee->isChecked());
ui->labelFeeEstimation ->setEnabled(ui->radioSmartFee->isChecked());
ui->checkBoxMinimumFee ->setEnabled(ui->radioCustomFee->isChecked());
ui->labelMinFeeWarning ->setEnabled(ui->radioCustomFee->isChecked());
ui->labelCustomPerKilobyte ->setEnabled(ui->radioCustomFee->isChecked() && !ui->checkBoxMinimumFee->isChecked());
ui->customFee ->setEnabled(ui->radioCustomFee->isChecked() && !ui->checkBoxMinimumFee->isChecked());
ui->labelCustomFeeWarning ->setEnabled(ui->radioCustomFee->isChecked());
ui->labelCustomPerKilobyte ->setEnabled(ui->radioCustomFee->isChecked());
ui->customFee ->setEnabled(ui->radioCustomFee->isChecked());
}

void SendCoinsDialog::updateFeeMinimizedLabel()
Expand All @@ -742,14 +733,6 @@ void SendCoinsDialog::updateFeeMinimizedLabel()
}
}

void SendCoinsDialog::updateMinFeeLabel()
{
if (model && model->getOptionsModel())
ui->checkBoxMinimumFee->setText(tr("Pay only the required fee of %1").arg(
BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), model->wallet().getRequiredFee(1000)) + "/kB")
);
}

void SendCoinsDialog::updateCoinControlState(CCoinControl& ctrl)
{
if (ui->radioCustomFee->isChecked()) {
Expand Down
2 changes: 0 additions & 2 deletions src/qt/sendcoinsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ private Q_SLOTS:
void coinControlClipboardBytes();
void coinControlClipboardLowOutput();
void coinControlClipboardChange();
void setMinimumFee();
void updateFeeSectionControls();
void updateMinFeeLabel();
void updateSmartFeeLabel();

Q_SIGNALS:
Expand Down

0 comments on commit 786dbd0

Please sign in to comment.