Skip to content

Commit 8fdd23a

Browse files
committed
Merge #10769: [Qt] replace fee slider with a Dropdown, extend conf. targets
2aef1f1 [Qt] migrate old fee slider value to new dropbown Always round up (conservative) (Jonas Schnelli) bc1be90 [Qt] replace fee slider with a Dropdown, extend conf. targets (Jonas Schnelli) Tree-SHA512: 53796cf0b434dd3db5d4680dbeb6231a7df8f15d88187178fd4db8917cd7fc60091ce2c1589fd93668fc94bb13f989aba5b7ef3792fa95ee1f9f21a15709e2d3
2 parents 1c011ff + 2aef1f1 commit 8fdd23a

File tree

2 files changed

+44
-78
lines changed

2 files changed

+44
-78
lines changed

src/qt/forms/sendcoinsdialog.ui

Lines changed: 4 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,44 +1068,15 @@
10681068
<number>30</number>
10691069
</property>
10701070
<item>
1071-
<widget class="QSlider" name="sliderSmartFee">
1072-
<property name="minimum">
1071+
<layout class="QHBoxLayout" name="horizontalLayoutConfTarget">
1072+
<property name="bottomMargin">
10731073
<number>0</number>
10741074
</property>
1075-
<property name="maximum">
1076-
<number>23</number>
1077-
</property>
1078-
<property name="pageStep">
1079-
<number>1</number>
1080-
</property>
1081-
<property name="value">
1082-
<number>0</number>
1083-
</property>
1084-
<property name="orientation">
1085-
<enum>Qt::Horizontal</enum>
1086-
</property>
1087-
<property name="invertedAppearance">
1088-
<bool>false</bool>
1089-
</property>
1090-
<property name="invertedControls">
1091-
<bool>false</bool>
1092-
</property>
1093-
<property name="tickPosition">
1094-
<enum>QSlider::NoTicks</enum>
1095-
</property>
1096-
</widget>
1097-
</item>
1098-
<item>
1099-
<layout class="QHBoxLayout" name="horizontalLayoutFee10">
11001075
<item>
1101-
<widget class="QLabel" name="labelSmartFeeNormal">
1102-
<property name="text">
1103-
<string>normal</string>
1104-
</property>
1105-
</widget>
1076+
<widget class="QComboBox" name="confTargetSelector"/>
11061077
</item>
11071078
<item>
1108-
<spacer name="horizontalSpacer_7">
1079+
<spacer name="horizontalSpacerConfTarget">
11091080
<property name="orientation">
11101081
<enum>Qt::Horizontal</enum>
11111082
</property>
@@ -1117,33 +1088,6 @@
11171088
</property>
11181089
</spacer>
11191090
</item>
1120-
<item>
1121-
<widget class="QLabel" name="confirmationTargetLabel">
1122-
<property name="text">
1123-
<string notr="true">(count)</string>
1124-
</property>
1125-
</widget>
1126-
</item>
1127-
<item>
1128-
<spacer name="horizontalSpacer_3">
1129-
<property name="orientation">
1130-
<enum>Qt::Horizontal</enum>
1131-
</property>
1132-
<property name="sizeHint" stdset="0">
1133-
<size>
1134-
<width>40</width>
1135-
<height>20</height>
1136-
</size>
1137-
</property>
1138-
</spacer>
1139-
</item>
1140-
<item>
1141-
<widget class="QLabel" name="labelSmartFeeFast">
1142-
<property name="text">
1143-
<string>fast</string>
1144-
</property>
1145-
</widget>
1146-
</item>
11471091
</layout>
11481092
</item>
11491093
</layout>

src/qt/sendcoinsdialog.cpp

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,25 @@
3131
#include <QTextDocument>
3232
#include <QTimer>
3333

34+
static const std::array<int, 9> confTargets = { {2, 4, 6, 12, 24, 48, 144, 504, 1008} };
35+
int getConfTargetForIndex(int index) {
36+
if (index+1 > static_cast<int>(confTargets.size())) {
37+
return confTargets.back();
38+
}
39+
if (index < 0) {
40+
return confTargets[0];
41+
}
42+
return confTargets[index];
43+
}
44+
int getIndexForConfTarget(int target) {
45+
for (unsigned int i = 0; i < confTargets.size(); i++) {
46+
if (confTargets[i] >= target) {
47+
return i;
48+
}
49+
}
50+
return confTargets.size() - 1;
51+
}
52+
3453
SendCoinsDialog::SendCoinsDialog(const PlatformStyle *_platformStyle, QWidget *parent) :
3554
QDialog(parent),
3655
ui(new Ui::SendCoinsDialog),
@@ -152,9 +171,12 @@ void SendCoinsDialog::setModel(WalletModel *_model)
152171
coinControlUpdateLabels();
153172

154173
// fee section
155-
connect(ui->sliderSmartFee, SIGNAL(valueChanged(int)), this, SLOT(updateSmartFeeLabel()));
156-
connect(ui->sliderSmartFee, SIGNAL(valueChanged(int)), this, SLOT(updateGlobalFeeVariables()));
157-
connect(ui->sliderSmartFee, SIGNAL(valueChanged(int)), this, SLOT(coinControlUpdateLabels()));
174+
for (const int &n : confTargets) {
175+
ui->confTargetSelector->addItem(tr("%1 (%2 blocks)").arg(GUIUtil::formatNiceTimeOffset(n*Params().GetConsensus().nPowTargetSpacing)).arg(n));
176+
}
177+
connect(ui->confTargetSelector, SIGNAL(currentIndexChanged(int)), this, SLOT(updateSmartFeeLabel()));
178+
connect(ui->confTargetSelector, SIGNAL(currentIndexChanged(int)), this, SLOT(updateGlobalFeeVariables()));
179+
connect(ui->confTargetSelector, SIGNAL(currentIndexChanged(int)), this, SLOT(coinControlUpdateLabels()));
158180
connect(ui->groupFee, SIGNAL(buttonClicked(int)), this, SLOT(updateFeeSectionControls()));
159181
connect(ui->groupFee, SIGNAL(buttonClicked(int)), this, SLOT(updateGlobalFeeVariables()));
160182
connect(ui->groupFee, SIGNAL(buttonClicked(int)), this, SLOT(coinControlUpdateLabels()));
@@ -179,10 +201,17 @@ void SendCoinsDialog::setModel(WalletModel *_model)
179201

180202
// set the smartfee-sliders default value (wallets default conf.target or last stored value)
181203
QSettings settings;
182-
if (settings.value("nSmartFeeSliderPosition").toInt() == 0)
183-
ui->sliderSmartFee->setValue(ui->sliderSmartFee->maximum() - model->getDefaultConfirmTarget() + 2);
204+
if (settings.value("nSmartFeeSliderPosition").toInt() != 0) {
205+
// migrate nSmartFeeSliderPosition to nConfTarget
206+
// nConfTarget is available since 0.15 (replaced nSmartFeeSliderPosition)
207+
int nConfirmTarget = 25 - settings.value("nSmartFeeSliderPosition").toInt(); // 25 == old slider range
208+
settings.setValue("nConfTarget", nConfirmTarget);
209+
settings.remove("nSmartFeeSliderPosition");
210+
}
211+
if (settings.value("nConfTarget").toInt() == 0)
212+
ui->confTargetSelector->setCurrentIndex(getIndexForConfTarget(model->getDefaultConfirmTarget()));
184213
else
185-
ui->sliderSmartFee->setValue(settings.value("nSmartFeeSliderPosition").toInt());
214+
ui->confTargetSelector->setCurrentIndex(getIndexForConfTarget(settings.value("nConfTarget").toInt()));
186215
}
187216
}
188217

@@ -192,7 +221,7 @@ SendCoinsDialog::~SendCoinsDialog()
192221
settings.setValue("fFeeSectionMinimized", fFeeMinimized);
193222
settings.setValue("nFeeRadio", ui->groupFee->checkedId());
194223
settings.setValue("nCustomFeeRadio", ui->groupCustomFee->checkedId());
195-
settings.setValue("nSmartFeeSliderPosition", ui->sliderSmartFee->value());
224+
settings.setValue("nConfTarget", getConfTargetForIndex(ui->confTargetSelector->currentIndex()));
196225
settings.setValue("nTransactionFee", (qint64)ui->customFee->value());
197226
settings.setValue("fPayOnlyMinFee", ui->checkBoxMinimumFee->isChecked());
198227

@@ -246,7 +275,7 @@ void SendCoinsDialog::on_sendButton_clicked()
246275
if (model->getOptionsModel()->getCoinControlFeatures())
247276
ctrl = *CoinControlDialog::coinControl;
248277
if (ui->radioSmartFee->isChecked())
249-
ctrl.nConfirmTarget = ui->sliderSmartFee->maximum() - ui->sliderSmartFee->value() + 2;
278+
ctrl.nConfirmTarget = getConfTargetForIndex(ui->confTargetSelector->currentIndex());
250279
else
251280
ctrl.nConfirmTarget = 0;
252281

@@ -596,14 +625,11 @@ void SendCoinsDialog::setMinimumFee()
596625

597626
void SendCoinsDialog::updateFeeSectionControls()
598627
{
599-
ui->sliderSmartFee ->setEnabled(ui->radioSmartFee->isChecked());
628+
ui->confTargetSelector ->setEnabled(ui->radioSmartFee->isChecked());
600629
ui->labelSmartFee ->setEnabled(ui->radioSmartFee->isChecked());
601630
ui->labelSmartFee2 ->setEnabled(ui->radioSmartFee->isChecked());
602631
ui->labelSmartFee3 ->setEnabled(ui->radioSmartFee->isChecked());
603632
ui->labelFeeEstimation ->setEnabled(ui->radioSmartFee->isChecked());
604-
ui->labelSmartFeeNormal ->setEnabled(ui->radioSmartFee->isChecked());
605-
ui->labelSmartFeeFast ->setEnabled(ui->radioSmartFee->isChecked());
606-
ui->confirmationTargetLabel ->setEnabled(ui->radioSmartFee->isChecked());
607633
ui->checkBoxMinimumFee ->setEnabled(ui->radioCustomFee->isChecked());
608634
ui->labelMinFeeWarning ->setEnabled(ui->radioCustomFee->isChecked());
609635
ui->radioCustomPerKilobyte ->setEnabled(ui->radioCustomFee->isChecked() && !ui->checkBoxMinimumFee->isChecked());
@@ -614,11 +640,7 @@ void SendCoinsDialog::updateGlobalFeeVariables()
614640
{
615641
if (ui->radioSmartFee->isChecked())
616642
{
617-
int nConfirmTarget = ui->sliderSmartFee->maximum() - ui->sliderSmartFee->value() + 2;
618643
payTxFee = CFeeRate(0);
619-
620-
// show the estimated required time for confirmation
621-
ui->confirmationTargetLabel->setText(GUIUtil::formatDurationStr(nConfirmTarget * Params().GetConsensus().nPowTargetSpacing) + " / " + tr("%n block(s)", "", nConfirmTarget));
622644
}
623645
else
624646
{
@@ -652,7 +674,7 @@ void SendCoinsDialog::updateSmartFeeLabel()
652674
if(!model || !model->getOptionsModel())
653675
return;
654676

655-
int nBlocksToConfirm = ui->sliderSmartFee->maximum() - ui->sliderSmartFee->value() + 2;
677+
int nBlocksToConfirm = getConfTargetForIndex(ui->confTargetSelector->currentIndex());
656678
FeeCalculation feeCalc;
657679
bool conservative_estimate = CalculateEstimateType(FeeEstimateMode::UNSET, ui->optInRBF->isChecked());
658680
CFeeRate feeRate = ::feeEstimator.estimateSmartFee(nBlocksToConfirm, &feeCalc, ::mempool, conservative_estimate);
@@ -826,7 +848,7 @@ void SendCoinsDialog::coinControlUpdateLabels()
826848
CoinControlDialog::payAmounts.clear();
827849
CoinControlDialog::fSubtractFeeFromAmount = false;
828850
if (ui->radioSmartFee->isChecked()) {
829-
CoinControlDialog::coinControl->nConfirmTarget = ui->sliderSmartFee->maximum() - ui->sliderSmartFee->value() + 2;
851+
CoinControlDialog::coinControl->nConfirmTarget = getConfTargetForIndex(ui->confTargetSelector->currentIndex());
830852
} else {
831853
CoinControlDialog::coinControl->nConfirmTarget = model->getDefaultConfirmTarget();
832854
}

0 commit comments

Comments
 (0)