Merge #14608: qt: Remove the "Pay only required fee..." checkbox

a16f44c04 qt: Remove "Pay only required fee" checkbox (Hennadii Stepanov)
8711cc0c7 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
This commit is contained in:
Jonas Schnelli 2018-11-13 15:35:25 +07:00 committed by munkybooty
parent d413109da5
commit 13ff3d6291
5 changed files with 68 additions and 59 deletions

View File

@ -79,10 +79,19 @@ public:
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));
}
}
@ -98,6 +107,21 @@ public:
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;
@ -124,7 +148,10 @@ public:
}
private:
int currentUnit;
int currentUnit{BitcoinUnits::DASH};
bool m_allow_empty{true};
CAmount m_min_amount{CAmount(0)};
CAmount m_max_amount{BitcoinUnits::maxMoney()};
protected:
bool event(QEvent *event) override
@ -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);

View File

@ -33,6 +33,15 @@ public:
CAmount value(bool *value=nullptr) 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);

View File

@ -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>
@ -940,9 +927,6 @@
<property name="text">
<string/>
</property>
<property name="margin">
<number>2</number>
</property>
</widget>
</item>
<item>
@ -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>
@ -986,9 +967,6 @@
<property name="text">
<string>Confirmation time target:</string>
</property>
<property name="margin">
<number>2</number>
</property>
</widget>
</item>
</layout>

View File

@ -134,14 +134,11 @@ 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) {
@ -200,11 +197,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)
@ -230,7 +228,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;
}
@ -613,7 +610,6 @@ void SendCoinsDialog::updateDisplayUnit()
setBalance(model->wallet().getBalances());
coinControlUpdateLabels();
ui->customFee->setDisplayUnit(model->getOptionsModel()->getDisplayUnit());
updateMinFeeLabel();
updateSmartFeeLabel();
}
@ -702,11 +698,6 @@ void SendCoinsDialog::useAvailableBalance(SendCoinsEntry* entry)
}
}
void SendCoinsDialog::setMinimumFee()
{
ui->customFee->setValue(model->wallet().getRequiredFee(1000));
}
void SendCoinsDialog::updateFeeSectionControls()
{
ui->confTargetSelector ->setEnabled(ui->radioSmartFee->isChecked());
@ -714,10 +705,9 @@ void SendCoinsDialog::updateFeeSectionControls()
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()
@ -732,14 +722,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()) {

View File

@ -96,9 +96,7 @@ private Q_SLOTS:
void coinControlClipboardBytes();
void coinControlClipboardLowOutput();
void coinControlClipboardChange();
void setMinimumFee();
void updateFeeSectionControls();
void updateMinFeeLabel();
void updateSmartFeeLabel();
Q_SIGNALS: