Skip to content

Commit bc1be90

Browse files
committed
[Qt] replace fee slider with a Dropdown, extend conf. targets
1 parent 1d4805c commit bc1be90

File tree

2 files changed

+37
-78
lines changed

2 files changed

+37
-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: 33 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()));
@@ -177,10 +199,10 @@ void SendCoinsDialog::setModel(WalletModel *_model)
177199

178200
// set the smartfee-sliders default value (wallets default conf.target or last stored value)
179201
QSettings settings;
180-
if (settings.value("nSmartFeeSliderPosition").toInt() == 0)
181-
ui->sliderSmartFee->setValue(ui->sliderSmartFee->maximum() - model->getDefaultConfirmTarget() + 2);
202+
if (settings.value("nConfTarget").toInt() == 0)
203+
ui->confTargetSelector->setCurrentIndex(getIndexForConfTarget(model->getDefaultConfirmTarget()));
182204
else
183-
ui->sliderSmartFee->setValue(settings.value("nSmartFeeSliderPosition").toInt());
205+
ui->confTargetSelector->setCurrentIndex(getIndexForConfTarget(settings.value("nConfTarget").toInt()));
184206
}
185207
}
186208

@@ -190,7 +212,7 @@ SendCoinsDialog::~SendCoinsDialog()
190212
settings.setValue("fFeeSectionMinimized", fFeeMinimized);
191213
settings.setValue("nFeeRadio", ui->groupFee->checkedId());
192214
settings.setValue("nCustomFeeRadio", ui->groupCustomFee->checkedId());
193-
settings.setValue("nSmartFeeSliderPosition", ui->sliderSmartFee->value());
215+
settings.setValue("nConfTarget", getConfTargetForIndex(ui->confTargetSelector->currentIndex()));
194216
settings.setValue("nTransactionFee", (qint64)ui->customFee->value());
195217
settings.setValue("fPayOnlyMinFee", ui->checkBoxMinimumFee->isChecked());
196218

@@ -244,7 +266,7 @@ void SendCoinsDialog::on_sendButton_clicked()
244266
if (model->getOptionsModel()->getCoinControlFeatures())
245267
ctrl = *CoinControlDialog::coinControl;
246268
if (ui->radioSmartFee->isChecked())
247-
ctrl.nConfirmTarget = ui->sliderSmartFee->maximum() - ui->sliderSmartFee->value() + 2;
269+
ctrl.nConfirmTarget = getConfTargetForIndex(ui->confTargetSelector->currentIndex());
248270
else
249271
ctrl.nConfirmTarget = 0;
250272

@@ -594,14 +616,11 @@ void SendCoinsDialog::setMinimumFee()
594616

595617
void SendCoinsDialog::updateFeeSectionControls()
596618
{
597-
ui->sliderSmartFee ->setEnabled(ui->radioSmartFee->isChecked());
619+
ui->confTargetSelector ->setEnabled(ui->radioSmartFee->isChecked());
598620
ui->labelSmartFee ->setEnabled(ui->radioSmartFee->isChecked());
599621
ui->labelSmartFee2 ->setEnabled(ui->radioSmartFee->isChecked());
600622
ui->labelSmartFee3 ->setEnabled(ui->radioSmartFee->isChecked());
601623
ui->labelFeeEstimation ->setEnabled(ui->radioSmartFee->isChecked());
602-
ui->labelSmartFeeNormal ->setEnabled(ui->radioSmartFee->isChecked());
603-
ui->labelSmartFeeFast ->setEnabled(ui->radioSmartFee->isChecked());
604-
ui->confirmationTargetLabel ->setEnabled(ui->radioSmartFee->isChecked());
605624
ui->checkBoxMinimumFee ->setEnabled(ui->radioCustomFee->isChecked());
606625
ui->labelMinFeeWarning ->setEnabled(ui->radioCustomFee->isChecked());
607626
ui->radioCustomPerKilobyte ->setEnabled(ui->radioCustomFee->isChecked() && !ui->checkBoxMinimumFee->isChecked());
@@ -612,11 +631,7 @@ void SendCoinsDialog::updateGlobalFeeVariables()
612631
{
613632
if (ui->radioSmartFee->isChecked())
614633
{
615-
int nConfirmTarget = ui->sliderSmartFee->maximum() - ui->sliderSmartFee->value() + 2;
616634
payTxFee = CFeeRate(0);
617-
618-
// show the estimated required time for confirmation
619-
ui->confirmationTargetLabel->setText(GUIUtil::formatDurationStr(nConfirmTarget * Params().GetConsensus().nPowTargetSpacing) + " / " + tr("%n block(s)", "", nConfirmTarget));
620635
}
621636
else
622637
{
@@ -650,7 +665,7 @@ void SendCoinsDialog::updateSmartFeeLabel()
650665
if(!model || !model->getOptionsModel())
651666
return;
652667

653-
int nBlocksToConfirm = ui->sliderSmartFee->maximum() - ui->sliderSmartFee->value() + 2;
668+
int nBlocksToConfirm = getConfTargetForIndex(ui->confTargetSelector->currentIndex());
654669
FeeCalculation feeCalc;
655670
CFeeRate feeRate = ::feeEstimator.estimateSmartFee(nBlocksToConfirm, &feeCalc, ::mempool);
656671
if (feeRate <= CFeeRate(0)) // not enough data => minfee
@@ -823,7 +838,7 @@ void SendCoinsDialog::coinControlUpdateLabels()
823838
CoinControlDialog::payAmounts.clear();
824839
CoinControlDialog::fSubtractFeeFromAmount = false;
825840
if (ui->radioSmartFee->isChecked()) {
826-
CoinControlDialog::coinControl->nConfirmTarget = ui->sliderSmartFee->maximum() - ui->sliderSmartFee->value() + 2;
841+
CoinControlDialog::coinControl->nConfirmTarget = getConfTargetForIndex(ui->confTargetSelector->currentIndex());
827842
} else {
828843
CoinControlDialog::coinControl->nConfirmTarget = model->getDefaultConfirmTarget();
829844
}

0 commit comments

Comments
 (0)