Skip to content

Commit 6ab3aad

Browse files
committed
[gui] send dialog: split on_sendButton_clicked
This commit does not change behavior.
1 parent 5236b2e commit 6ab3aad

File tree

2 files changed

+52
-44
lines changed

2 files changed

+52
-44
lines changed

src/qt/sendcoinsdialog.cpp

Lines changed: 49 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,8 @@ SendCoinsDialog::~SendCoinsDialog()
219219
delete ui;
220220
}
221221

222-
void SendCoinsDialog::on_sendButton_clicked()
222+
bool SendCoinsDialog::PrepareSendText(QString& question_string, QString& informative_text, QString& detailed_text)
223223
{
224-
if(!model || !model->getOptionsModel())
225-
return;
226-
227224
QList<SendCoinsRecipient> recipients;
228225
bool valid = true;
229226

@@ -246,7 +243,7 @@ void SendCoinsDialog::on_sendButton_clicked()
246243

247244
if(!valid || recipients.isEmpty())
248245
{
249-
return;
246+
return false;
250247
}
251248

252249
fNewRecipientAllowed = false;
@@ -255,11 +252,11 @@ void SendCoinsDialog::on_sendButton_clicked()
255252
{
256253
// Unlock wallet was cancelled
257254
fNewRecipientAllowed = true;
258-
return;
255+
return false;
259256
}
260257

261258
// prepare transaction for getting txFee earlier
262-
WalletModelTransaction currentTransaction(recipients);
259+
m_current_transaction = MakeUnique<WalletModelTransaction>(recipients);
263260
WalletModel::SendCoinsReturn prepareStatus;
264261

265262
// Always use a CCoinControl instance, use the CoinControlDialog instance if CoinControl has been enabled
@@ -269,22 +266,20 @@ void SendCoinsDialog::on_sendButton_clicked()
269266

270267
updateCoinControlState(ctrl);
271268

272-
prepareStatus = model->prepareTransaction(currentTransaction, ctrl);
269+
prepareStatus = model->prepareTransaction(*m_current_transaction, ctrl);
273270

274271
// process prepareStatus and on error generate message shown to user
275272
processSendCoinsReturn(prepareStatus,
276-
BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), currentTransaction.getTransactionFee()));
273+
BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), m_current_transaction->getTransactionFee()));
277274

278275
if(prepareStatus.status != WalletModel::OK) {
279276
fNewRecipientAllowed = true;
280-
return;
277+
return false;
281278
}
282279

283-
CAmount txFee = currentTransaction.getTransactionFee();
284-
285-
// Format confirmation message
280+
CAmount txFee = m_current_transaction->getTransactionFee();
286281
QStringList formatted;
287-
for (const SendCoinsRecipient &rcp : currentTransaction.getRecipients())
282+
for (const SendCoinsRecipient &rcp : m_current_transaction->getRecipients())
288283
{
289284
// generate amount string with wallet name in case of multiwallet
290285
QString amount = BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), rcp.amount);
@@ -311,72 +306,82 @@ void SendCoinsDialog::on_sendButton_clicked()
311306
formatted.append(recipientElement);
312307
}
313308

314-
QString questionString;
315309
if (model->wallet().privateKeysDisabled()) {
316-
questionString.append(tr("Do you want to draft this transaction?"));
310+
question_string.append(tr("Do you want to draft this transaction?"));
317311
} else {
318-
questionString.append(tr("Are you sure you want to send?"));
312+
question_string.append(tr("Are you sure you want to send?"));
319313
}
320314

321-
questionString.append("<br /><span style='font-size:10pt;'>");
315+
question_string.append("<br /><span style='font-size:10pt;'>");
322316
if (model->wallet().privateKeysDisabled()) {
323-
questionString.append(tr("Please, review your transaction proposal. This will produce a Partially Signed Bitcoin Transaction (PSBT) which you can copy and then sign with e.g. an offline %1 wallet, or a PSBT-compatible hardware wallet.").arg(PACKAGE_NAME));
317+
question_string.append(tr("Please, review your transaction proposal. This will produce a Partially Signed Bitcoin Transaction (PSBT) which you can copy and then sign with e.g. an offline %1 wallet, or a PSBT-compatible hardware wallet.").arg(PACKAGE_NAME));
324318
} else {
325-
questionString.append(tr("Please, review your transaction."));
319+
question_string.append(tr("Please, review your transaction."));
326320
}
327-
questionString.append("</span>%1");
321+
question_string.append("</span>%1");
328322

329323
if(txFee > 0)
330324
{
331325
// append fee string if a fee is required
332-
questionString.append("<hr /><b>");
333-
questionString.append(tr("Transaction fee"));
334-
questionString.append("</b>");
326+
question_string.append("<hr /><b>");
327+
question_string.append(tr("Transaction fee"));
328+
question_string.append("</b>");
335329

336330
// append transaction size
337-
questionString.append(" (" + QString::number((double)currentTransaction.getTransactionSize() / 1000) + " kB): ");
331+
question_string.append(" (" + QString::number((double)m_current_transaction->getTransactionSize() / 1000) + " kB): ");
338332

339333
// append transaction fee value
340-
questionString.append("<span style='color:#aa0000; font-weight:bold;'>");
341-
questionString.append(BitcoinUnits::formatHtmlWithUnit(model->getOptionsModel()->getDisplayUnit(), txFee));
342-
questionString.append("</span><br />");
334+
question_string.append("<span style='color:#aa0000; font-weight:bold;'>");
335+
question_string.append(BitcoinUnits::formatHtmlWithUnit(model->getOptionsModel()->getDisplayUnit(), txFee));
336+
question_string.append("</span><br />");
343337

344338
// append RBF message according to transaction's signalling
345-
questionString.append("<span style='font-size:10pt; font-weight:normal;'>");
339+
question_string.append("<span style='font-size:10pt; font-weight:normal;'>");
346340
if (ui->optInRBF->isChecked()) {
347-
questionString.append(tr("You can increase the fee later (signals Replace-By-Fee, BIP-125)."));
341+
question_string.append(tr("You can increase the fee later (signals Replace-By-Fee, BIP-125)."));
348342
} else {
349-
questionString.append(tr("Not signalling Replace-By-Fee, BIP-125."));
343+
question_string.append(tr("Not signalling Replace-By-Fee, BIP-125."));
350344
}
351-
questionString.append("</span>");
345+
question_string.append("</span>");
352346
}
353347

354348
// add total amount in all subdivision units
355-
questionString.append("<hr />");
356-
CAmount totalAmount = currentTransaction.getTotalTransactionAmount() + txFee;
349+
question_string.append("<hr />");
350+
CAmount totalAmount = m_current_transaction->getTotalTransactionAmount() + txFee;
357351
QStringList alternativeUnits;
358352
for (const BitcoinUnits::Unit u : BitcoinUnits::availableUnits())
359353
{
360354
if(u != model->getOptionsModel()->getDisplayUnit())
361355
alternativeUnits.append(BitcoinUnits::formatHtmlWithUnit(u, totalAmount));
362356
}
363-
questionString.append(QString("<b>%1</b>: <b>%2</b>").arg(tr("Total Amount"))
357+
question_string.append(QString("<b>%1</b>: <b>%2</b>").arg(tr("Total Amount"))
364358
.arg(BitcoinUnits::formatHtmlWithUnit(model->getOptionsModel()->getDisplayUnit(), totalAmount)));
365-
questionString.append(QString("<br /><span style='font-size:10pt; font-weight:normal;'>(=%1)</span>")
359+
question_string.append(QString("<br /><span style='font-size:10pt; font-weight:normal;'>(=%1)</span>")
366360
.arg(alternativeUnits.join(" " + tr("or") + " ")));
367361

368-
QString informative_text;
369-
QString detailed_text;
370362
if (formatted.size() > 1) {
371-
questionString = questionString.arg("");
363+
question_string = question_string.arg("");
372364
informative_text = tr("To review recipient list click \"Show Details...\"");
373365
detailed_text = formatted.join("\n\n");
374366
} else {
375-
questionString = questionString.arg("<br /><br />" + formatted.at(0));
367+
question_string = question_string.arg("<br /><br />" + formatted.at(0));
376368
}
369+
370+
return true;
371+
}
372+
373+
void SendCoinsDialog::on_sendButton_clicked()
374+
{
375+
if(!model || !model->getOptionsModel())
376+
return;
377+
378+
QString question_string, informative_text, detailed_text;
379+
if (!PrepareSendText(question_string, informative_text, detailed_text)) return;
380+
assert(m_current_transaction);
381+
377382
const QString confirmation = model->wallet().privateKeysDisabled() ? tr("Confirm transaction proposal") : tr("Confirm send coins");
378383
const QString confirmButtonText = model->wallet().privateKeysDisabled() ? tr("Copy PSBT to clipboard") : tr("Send");
379-
SendConfirmationDialog confirmationDialog(confirmation, questionString, informative_text, detailed_text, SEND_CONFIRM_DELAY, confirmButtonText, this);
384+
SendConfirmationDialog confirmationDialog(confirmation, question_string, informative_text, detailed_text, SEND_CONFIRM_DELAY, confirmButtonText, this);
380385
confirmationDialog.exec();
381386
QMessageBox::StandardButton retval = static_cast<QMessageBox::StandardButton>(confirmationDialog.result());
382387

@@ -388,7 +393,7 @@ void SendCoinsDialog::on_sendButton_clicked()
388393

389394
bool send_failure = false;
390395
if (model->wallet().privateKeysDisabled()) {
391-
CMutableTransaction mtx = CMutableTransaction{*(currentTransaction.getWtx())};
396+
CMutableTransaction mtx = CMutableTransaction{*(m_current_transaction->getWtx())};
392397
PartiallySignedTransaction psbtx(mtx);
393398
bool complete = false;
394399
const TransactionError err = model->wallet().fillPSBT(SIGHASH_ALL, false /* sign */, true /* bip32derivs */, psbtx, complete);
@@ -401,12 +406,12 @@ void SendCoinsDialog::on_sendButton_clicked()
401406
Q_EMIT message(tr("PSBT copied"), "Copied to clipboard", CClientUIInterface::MSG_INFORMATION);
402407
} else {
403408
// now send the prepared transaction
404-
WalletModel::SendCoinsReturn sendStatus = model->sendCoins(currentTransaction);
409+
WalletModel::SendCoinsReturn sendStatus = model->sendCoins(*m_current_transaction);
405410
// process sendStatus and on error generate message shown to user
406411
processSendCoinsReturn(sendStatus);
407412

408413
if (sendStatus.status == WalletModel::OK) {
409-
Q_EMIT coinsSent(currentTransaction.getWtx()->GetHash());
414+
Q_EMIT coinsSent(m_current_transaction->getWtx()->GetHash());
410415
} else {
411416
send_failure = true;
412417
}

src/qt/sendcoinsdialog.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public Q_SLOTS:
6060
Ui::SendCoinsDialog *ui;
6161
ClientModel *clientModel;
6262
WalletModel *model;
63+
std::unique_ptr<WalletModelTransaction> m_current_transaction;
6364
bool fNewRecipientAllowed;
6465
bool fFeeMinimized;
6566
const PlatformStyle *platformStyle;
@@ -69,6 +70,8 @@ public Q_SLOTS:
6970
// Additional parameter msgArg can be used via .arg(msgArg).
7071
void processSendCoinsReturn(const WalletModel::SendCoinsReturn &sendCoinsReturn, const QString &msgArg = QString());
7172
void minimizeFeeSection(bool fMinimize);
73+
// Format confirmation message
74+
bool PrepareSendText(QString& question_string, QString& informative_text, QString& detailed_text);
7275
void updateFeeMinimizedLabel();
7376
// Update the passed in CCoinControl with state from the GUI
7477
void updateCoinControlState(CCoinControl& ctrl);

0 commit comments

Comments
 (0)