Skip to content

Commit cfe77ef

Browse files
committed
[Qt] overhaul smart-fee slider, adjust default confirmation target
1 parent 6f02899 commit cfe77ef

File tree

3 files changed

+47
-11
lines changed

3 files changed

+47
-11
lines changed

src/qt/forms/sendcoinsdialog.ui

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@
411411
</property>
412412
</widget>
413413
</item>
414-
</layout>
414+
</layout>
415415
</item>
416416
<item>
417417
<layout class="QFormLayout" name="formLayoutCoinControl4">
@@ -1031,7 +1031,7 @@
10311031
<item>
10321032
<widget class="QLabel" name="labelSmartFee3">
10331033
<property name="text">
1034-
<string>Confirmation time:</string>
1034+
<string>Confirmation time target:</string>
10351035
</property>
10361036
<property name="margin">
10371037
<number>2</number>
@@ -1095,6 +1095,26 @@
10951095
</property>
10961096
</widget>
10971097
</item>
1098+
<item>
1099+
<spacer name="horizontalSpacer_7">
1100+
<property name="orientation">
1101+
<enum>Qt::Horizontal</enum>
1102+
</property>
1103+
<property name="sizeHint" stdset="0">
1104+
<size>
1105+
<width>40</width>
1106+
<height>20</height>
1107+
</size>
1108+
</property>
1109+
</spacer>
1110+
</item>
1111+
<item>
1112+
<widget class="QLabel" name="confirmationTargetLabel">
1113+
<property name="text">
1114+
<string>(count)</string>
1115+
</property>
1116+
</widget>
1117+
</item>
10981118
<item>
10991119
<spacer name="horizontalSpacer_3">
11001120
<property name="orientation">

src/qt/sendcoinsdialog.cpp

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ SendCoinsDialog::SendCoinsDialog(const PlatformStyle *_platformStyle, QWidget *p
110110
ui->groupCustomFee->setId(ui->radioCustomPerKilobyte, 0);
111111
ui->groupCustomFee->setId(ui->radioCustomAtLeast, 1);
112112
ui->groupCustomFee->button((int)std::max(0, std::min(1, settings.value("nCustomFeeRadio").toInt())))->setChecked(true);
113-
ui->sliderSmartFee->setValue(settings.value("nSmartFeeSliderPosition").toInt());
114113
ui->customFee->setValue(settings.value("nTransactionFee").toLongLong());
115114
ui->checkBoxMinimumFee->setChecked(settings.value("fPayOnlyMinFee").toBool());
116115
minimizeFeeSection(settings.value("fFeeSectionMinimized").toBool());
@@ -172,6 +171,13 @@ void SendCoinsDialog::setModel(WalletModel *_model)
172171
updateMinFeeLabel();
173172
updateSmartFeeLabel();
174173
updateGlobalFeeVariables();
174+
175+
// set the smartfee-sliders default value (wallets default conf.target or last stored value)
176+
QSettings settings;
177+
if (settings.value("nSmartFeeSliderPosition").toInt() == 0)
178+
ui->sliderSmartFee->setValue(ui->sliderSmartFee->maximum() - model->getDefaultConfirmTarget() + 1);
179+
else
180+
ui->sliderSmartFee->setValue(settings.value("nSmartFeeSliderPosition").toInt());
175181
}
176182
}
177183

@@ -229,10 +235,17 @@ void SendCoinsDialog::on_sendButton_clicked()
229235
// prepare transaction for getting txFee earlier
230236
WalletModelTransaction currentTransaction(recipients);
231237
WalletModel::SendCoinsReturn prepareStatus;
232-
if (model->getOptionsModel()->getCoinControlFeatures()) // coin control enabled
233-
prepareStatus = model->prepareTransaction(currentTransaction, CoinControlDialog::coinControl);
238+
239+
// Always use a CCoinControl instance, use the CoinControlDialog instance if CoinControl has been enabled
240+
CCoinControl ctrl;
241+
if (model->getOptionsModel()->getCoinControlFeatures())
242+
ctrl = *CoinControlDialog::coinControl;
243+
if (ui->radioSmartFee->isChecked())
244+
ctrl.nConfirmTarget = ui->sliderSmartFee->maximum() - ui->sliderSmartFee->value() + 1;
234245
else
235-
prepareStatus = model->prepareTransaction(currentTransaction);
246+
ctrl.nConfirmTarget = 0;
247+
248+
prepareStatus = model->prepareTransaction(currentTransaction, &ctrl);
236249

237250
// process prepareStatus and on error generate message shown to user
238251
processSendCoinsReturn(prepareStatus,
@@ -576,6 +589,7 @@ void SendCoinsDialog::updateFeeSectionControls()
576589
ui->labelFeeEstimation ->setEnabled(ui->radioSmartFee->isChecked());
577590
ui->labelSmartFeeNormal ->setEnabled(ui->radioSmartFee->isChecked());
578591
ui->labelSmartFeeFast ->setEnabled(ui->radioSmartFee->isChecked());
592+
ui->confirmationTargetLabel ->setEnabled(ui->radioSmartFee->isChecked());
579593
ui->checkBoxMinimumFee ->setEnabled(ui->radioCustomFee->isChecked());
580594
ui->labelMinFeeWarning ->setEnabled(ui->radioCustomFee->isChecked());
581595
ui->radioCustomPerKilobyte ->setEnabled(ui->radioCustomFee->isChecked() && !ui->checkBoxMinimumFee->isChecked());
@@ -587,15 +601,17 @@ void SendCoinsDialog::updateGlobalFeeVariables()
587601
{
588602
if (ui->radioSmartFee->isChecked())
589603
{
590-
nTxConfirmTarget = defaultConfirmTarget - ui->sliderSmartFee->value();
604+
int nConfirmTarget = ui->sliderSmartFee->maximum() - ui->sliderSmartFee->value() + 1;
591605
payTxFee = CFeeRate(0);
592606

593607
// set nMinimumTotalFee to 0 to not accidentally pay a custom fee
594608
CoinControlDialog::coinControl->nMinimumTotalFee = 0;
609+
610+
// show the estimated reuquired time for confirmation
611+
ui->confirmationTargetLabel->setText(GUIUtil::formatDurationStr(nConfirmTarget*600)+" / "+tr("%n block(s)", "", nConfirmTarget));
595612
}
596613
else
597614
{
598-
nTxConfirmTarget = defaultConfirmTarget;
599615
payTxFee = CFeeRate(ui->customFee->value());
600616

601617
// if user has selected to set a minimum absolute fee, pass the value to coincontrol
@@ -630,7 +646,7 @@ void SendCoinsDialog::updateSmartFeeLabel()
630646
if(!model || !model->getOptionsModel())
631647
return;
632648

633-
int nBlocksToConfirm = defaultConfirmTarget - ui->sliderSmartFee->value();
649+
int nBlocksToConfirm = ui->sliderSmartFee->maximum() - ui->sliderSmartFee->value() + 1;
634650
int estimateFoundAtBlocks = nBlocksToConfirm;
635651
CFeeRate feeRate = mempool.estimateSmartFee(nBlocksToConfirm, &estimateFoundAtBlocks);
636652
if (feeRate <= CFeeRate(0)) // not enough data => minfee
@@ -701,6 +717,8 @@ void SendCoinsDialog::coinControlFeatureChanged(bool checked)
701717
if (!checked && model) // coin control features disabled
702718
CoinControlDialog::coinControl->SetNull();
703719

720+
// make sure we set back the confirmation target
721+
updateGlobalFeeVariables();
704722
coinControlUpdateLabels();
705723
}
706724

src/qt/sendcoinsdialog.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ QT_BEGIN_NAMESPACE
2626
class QUrl;
2727
QT_END_NAMESPACE
2828

29-
const int defaultConfirmTarget = 25;
30-
3129
/** Dialog for sending bitcoins */
3230
class SendCoinsDialog : public QDialog
3331
{

0 commit comments

Comments
 (0)