31
31
#include < QTextDocument>
32
32
#include < QTimer>
33
33
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
+
34
53
SendCoinsDialog::SendCoinsDialog (const PlatformStyle *_platformStyle, QWidget *parent) :
35
54
QDialog(parent),
36
55
ui(new Ui::SendCoinsDialog),
@@ -152,9 +171,12 @@ void SendCoinsDialog::setModel(WalletModel *_model)
152
171
coinControlUpdateLabels ();
153
172
154
173
// 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 ()));
158
180
connect (ui->groupFee , SIGNAL (buttonClicked (int )), this , SLOT (updateFeeSectionControls ()));
159
181
connect (ui->groupFee , SIGNAL (buttonClicked (int )), this , SLOT (updateGlobalFeeVariables ()));
160
182
connect (ui->groupFee , SIGNAL (buttonClicked (int )), this , SLOT (coinControlUpdateLabels ()));
@@ -179,10 +201,17 @@ void SendCoinsDialog::setModel(WalletModel *_model)
179
201
180
202
// set the smartfee-sliders default value (wallets default conf.target or last stored value)
181
203
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 ()));
184
213
else
185
- ui->sliderSmartFee -> setValue ( settings.value (" nSmartFeeSliderPosition " ).toInt ());
214
+ ui->confTargetSelector -> setCurrentIndex ( getIndexForConfTarget ( settings.value (" nConfTarget " ).toInt () ));
186
215
}
187
216
}
188
217
@@ -192,7 +221,7 @@ SendCoinsDialog::~SendCoinsDialog()
192
221
settings.setValue (" fFeeSectionMinimized" , fFeeMinimized );
193
222
settings.setValue (" nFeeRadio" , ui->groupFee ->checkedId ());
194
223
settings.setValue (" nCustomFeeRadio" , ui->groupCustomFee ->checkedId ());
195
- settings.setValue (" nSmartFeeSliderPosition " , ui->sliderSmartFee -> value ( ));
224
+ settings.setValue (" nConfTarget " , getConfTargetForIndex ( ui->confTargetSelector -> currentIndex () ));
196
225
settings.setValue (" nTransactionFee" , (qint64)ui->customFee ->value ());
197
226
settings.setValue (" fPayOnlyMinFee" , ui->checkBoxMinimumFee ->isChecked ());
198
227
@@ -246,7 +275,7 @@ void SendCoinsDialog::on_sendButton_clicked()
246
275
if (model->getOptionsModel ()->getCoinControlFeatures ())
247
276
ctrl = *CoinControlDialog::coinControl;
248
277
if (ui->radioSmartFee ->isChecked ())
249
- ctrl.nConfirmTarget = ui-> sliderSmartFee -> maximum () - ui->sliderSmartFee -> value () + 2 ;
278
+ ctrl.nConfirmTarget = getConfTargetForIndex ( ui->confTargetSelector -> currentIndex ()) ;
250
279
else
251
280
ctrl.nConfirmTarget = 0 ;
252
281
@@ -596,14 +625,11 @@ void SendCoinsDialog::setMinimumFee()
596
625
597
626
void SendCoinsDialog::updateFeeSectionControls ()
598
627
{
599
- ui->sliderSmartFee ->setEnabled (ui->radioSmartFee ->isChecked ());
628
+ ui->confTargetSelector ->setEnabled (ui->radioSmartFee ->isChecked ());
600
629
ui->labelSmartFee ->setEnabled (ui->radioSmartFee ->isChecked ());
601
630
ui->labelSmartFee2 ->setEnabled (ui->radioSmartFee ->isChecked ());
602
631
ui->labelSmartFee3 ->setEnabled (ui->radioSmartFee ->isChecked ());
603
632
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 ());
607
633
ui->checkBoxMinimumFee ->setEnabled (ui->radioCustomFee ->isChecked ());
608
634
ui->labelMinFeeWarning ->setEnabled (ui->radioCustomFee ->isChecked ());
609
635
ui->radioCustomPerKilobyte ->setEnabled (ui->radioCustomFee ->isChecked () && !ui->checkBoxMinimumFee ->isChecked ());
@@ -614,11 +640,7 @@ void SendCoinsDialog::updateGlobalFeeVariables()
614
640
{
615
641
if (ui->radioSmartFee ->isChecked ())
616
642
{
617
- int nConfirmTarget = ui->sliderSmartFee ->maximum () - ui->sliderSmartFee ->value () + 2 ;
618
643
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));
622
644
}
623
645
else
624
646
{
@@ -652,7 +674,7 @@ void SendCoinsDialog::updateSmartFeeLabel()
652
674
if (!model || !model->getOptionsModel ())
653
675
return ;
654
676
655
- int nBlocksToConfirm = ui-> sliderSmartFee -> maximum () - ui->sliderSmartFee -> value () + 2 ;
677
+ int nBlocksToConfirm = getConfTargetForIndex ( ui->confTargetSelector -> currentIndex ()) ;
656
678
FeeCalculation feeCalc;
657
679
bool conservative_estimate = CalculateEstimateType (FeeEstimateMode::UNSET, ui->optInRBF ->isChecked ());
658
680
CFeeRate feeRate = ::feeEstimator.estimateSmartFee (nBlocksToConfirm, &feeCalc, ::mempool, conservative_estimate);
@@ -826,7 +848,7 @@ void SendCoinsDialog::coinControlUpdateLabels()
826
848
CoinControlDialog::payAmounts.clear ();
827
849
CoinControlDialog::fSubtractFeeFromAmount = false ;
828
850
if (ui->radioSmartFee ->isChecked ()) {
829
- CoinControlDialog::coinControl->nConfirmTarget = ui-> sliderSmartFee -> maximum () - ui->sliderSmartFee -> value () + 2 ;
851
+ CoinControlDialog::coinControl->nConfirmTarget = getConfTargetForIndex ( ui->confTargetSelector -> currentIndex ()) ;
830
852
} else {
831
853
CoinControlDialog::coinControl->nConfirmTarget = model->getDefaultConfirmTarget ();
832
854
}
0 commit comments