Skip to content

Commit 9dad603

Browse files
authored
Tweak "Send" popup and refactor related code a bit (#3218)
Few key points: - highlight when not all recipients are displayed, move this info closer to the actual list - clarify fee rounding text for PrivateSend, wasn't accurate - show transactions size and actual fee rate explicitly - show number of inputs PrivateSend tx is going to consume and warn if this number is 10 or higher
1 parent ef55e48 commit 9dad603

File tree

2 files changed

+64
-43
lines changed

2 files changed

+64
-43
lines changed

src/qt/sendcoinsdialog.cpp

Lines changed: 63 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -272,21 +272,6 @@ void SendCoinsDialog::on_sendButton_clicked()
272272
return;
273273
}
274274

275-
QString strFunds = tr("using") + " <b>" + tr("mixed funds") + "</b>";
276-
QString strFee = "";
277-
278-
if(ui->checkUsePrivateSend->isChecked()) {
279-
strFunds = tr("using") + " <b>" + tr("mixed funds") + "</b>";
280-
QString strNearestAmount(
281-
BitcoinUnits::formatWithUnit(
282-
model->getOptionsModel()->getDisplayUnit(), CPrivateSend::GetSmallestDenomination()));
283-
strFee = QString(tr(
284-
"(privatesend requires this amount to be rounded up to the nearest %1)."
285-
).arg(strNearestAmount));
286-
} else {
287-
strFunds = tr("using") + " <b>" + tr("any available funds (not mixed)") + "</b>";
288-
}
289-
290275
fNewRecipientAllowed = false;
291276
// request unlock only if was locked or unlocked for mixing:
292277
// this way we let users unlock by walletpassphrase or by menu
@@ -302,14 +287,14 @@ void SendCoinsDialog::on_sendButton_clicked()
302287
fNewRecipientAllowed = true;
303288
return;
304289
}
305-
send(recipients, strFee, strFunds);
290+
send(recipients);
306291
return;
307292
}
308293
// already unlocked or not encrypted at all
309-
send(recipients, strFee, strFunds);
294+
send(recipients);
310295
}
311296

312-
void SendCoinsDialog::send(QList<SendCoinsRecipient> recipients, QString strFee, QString strFunds)
297+
void SendCoinsDialog::send(QList<SendCoinsRecipient> recipients)
313298
{
314299
// prepare transaction for getting txFee earlier
315300
WalletModelTransaction currentTransaction(recipients);
@@ -335,15 +320,13 @@ void SendCoinsDialog::send(QList<SendCoinsRecipient> recipients, QString strFee,
335320
return;
336321
}
337322

338-
CAmount txFee = currentTransaction.getTransactionFee();
339-
340323
// Format confirmation message
341324
QStringList formatted;
342325
for (const SendCoinsRecipient &rcp : currentTransaction.getRecipients())
343326
{
344327
// generate bold amount string
345328
QString amount = "<b>" + BitcoinUnits::formatHtmlWithUnit(model->getOptionsModel()->getDisplayUnit(), rcp.amount);
346-
amount.append("</b> ").append(strFunds);
329+
amount.append("</b> ");
347330

348331
// generate monospace address string
349332
QString address = "<span style='font-family: monospace;'>" + rcp.address;
@@ -375,8 +358,39 @@ void SendCoinsDialog::send(QList<SendCoinsRecipient> recipients, QString strFee,
375358
formatted.append(recipientElement);
376359
}
377360

361+
// Limit number of displayed entries
362+
int messageEntries = formatted.size();
363+
int displayedEntries = 0;
364+
for(int i = 0; i < formatted.size(); i++){
365+
if(i >= MAX_SEND_POPUP_ENTRIES){
366+
formatted.removeLast();
367+
i--;
368+
}
369+
else{
370+
displayedEntries = i+1;
371+
}
372+
}
373+
378374
QString questionString = tr("Are you sure you want to send?");
379-
questionString.append("<br /><br />%1");
375+
questionString.append("<br /><br />");
376+
questionString.append(formatted.join("<br />"));
377+
questionString.append("<br />");
378+
379+
380+
if(ctrl.IsUsingPrivateSend()) {
381+
questionString.append(tr("using") + " <b>" + tr("mixed funds") + "</b>");
382+
} else {
383+
questionString.append(tr("using") + " <b>" + tr("any available funds (not mixed)") + "</b>");
384+
}
385+
386+
if (displayedEntries < messageEntries) {
387+
questionString.append("<br />");
388+
questionString.append("<span style='" + GUIUtil::getThemedStyleQString(GUIUtil::ThemedStyle::TS_ERROR) + "'>");
389+
questionString.append(tr("<b>(%1 of %2 entries displayed)</b>").arg(displayedEntries).arg(messageEntries));
390+
questionString.append("</span>");
391+
}
392+
393+
CAmount txFee = currentTransaction.getTransactionFee();
380394

381395
if(txFee > 0)
382396
{
@@ -385,11 +399,33 @@ void SendCoinsDialog::send(QList<SendCoinsRecipient> recipients, QString strFee,
385399
questionString.append(BitcoinUnits::formatHtmlWithUnit(model->getOptionsModel()->getDisplayUnit(), txFee));
386400
questionString.append("</span> ");
387401
questionString.append(tr("are added as transaction fee"));
388-
questionString.append(" ");
389-
questionString.append(strFee);
390402

391-
// append transaction size
392-
questionString.append(" (" + QString::number((double)currentTransaction.getTransactionSize() / 1000) + " kB)");
403+
if (ctrl.IsUsingPrivateSend()) {
404+
questionString.append(" " + tr("(PrivateSend transactions have higher fees usually due to no change output being allowed)"));
405+
}
406+
}
407+
408+
// Show some additioinal information
409+
questionString.append("<hr />");
410+
// append transaction size
411+
questionString.append(tr("Transaction size: %1").arg(QString::number((double)currentTransaction.getTransactionSize() / 1000)) + " kB");
412+
questionString.append("<br />");
413+
CFeeRate feeRate(txFee, currentTransaction.getTransactionSize());
414+
questionString.append(tr("Fee rate: %1").arg(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), feeRate.GetFeePerK())) + "/kB");
415+
416+
if (ctrl.IsUsingPrivateSend()) {
417+
// append number of inputs
418+
questionString.append("<hr />");
419+
int nInputs = currentTransaction.getTransaction()->tx->vin.size();
420+
questionString.append(tr("This transaction will consume %n input(s)", "", nInputs));
421+
422+
// warn about potential privacy issues when spending too many inputs at once
423+
if (nInputs >= 10 && ctrl.IsUsingPrivateSend()) {
424+
questionString.append("<br />");
425+
questionString.append("<span style='" + GUIUtil::getThemedStyleQString(GUIUtil::ThemedStyle::TS_ERROR) + "'>");
426+
questionString.append(tr("Warning: Using PrivateSend with %1 or more inputs can harm your privacy and is not recommended").arg(10));
427+
questionString.append("</span> ");
428+
}
393429
}
394430

395431
// add total amount in all subdivision units
@@ -407,24 +443,9 @@ void SendCoinsDialog::send(QList<SendCoinsRecipient> recipients, QString strFee,
407443
.arg(BitcoinUnits::formatHtmlWithUnit(model->getOptionsModel()->getDisplayUnit(), totalAmount))
408444
.arg(alternativeUnits.join("<br />= ")));
409445

410-
// Limit number of displayed entries
411-
int messageEntries = formatted.size();
412-
int displayedEntries = 0;
413-
for(int i = 0; i < formatted.size(); i++){
414-
if(i >= MAX_SEND_POPUP_ENTRIES){
415-
formatted.removeLast();
416-
i--;
417-
}
418-
else{
419-
displayedEntries = i+1;
420-
}
421-
}
422-
questionString.append("<hr />");
423-
questionString.append(tr("<b>(%1 of %2 entries displayed)</b>").arg(displayedEntries).arg(messageEntries));
424-
425446
// Display message box
426447
SendConfirmationDialog confirmationDialog(tr("Confirm send coins"),
427-
questionString.arg(formatted.join("<br />")), SEND_CONFIRM_DELAY, this);
448+
questionString, SEND_CONFIRM_DELAY, this);
428449
confirmationDialog.exec();
429450
QMessageBox::StandardButton retval = (QMessageBox::StandardButton)confirmationDialog.result();
430451

src/qt/sendcoinsdialog.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public Q_SLOTS:
6161
ClientModel *clientModel;
6262
WalletModel *model;
6363
bool fNewRecipientAllowed;
64-
void send(QList<SendCoinsRecipient> recipients, QString strFee, QString strFunds);
64+
void send(QList<SendCoinsRecipient> recipients);
6565
bool fFeeMinimized;
6666
const PlatformStyle *platformStyle;
6767

0 commit comments

Comments
 (0)