Skip to content

Commit fe11f65

Browse files
committed
qt: hide Create Unsigned button behind an expert mode option
1 parent fbe887f commit fe11f65

File tree

6 files changed

+51
-8
lines changed

6 files changed

+51
-8
lines changed

src/qt/forms/optionsdialog.ui

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,16 @@
252252
</property>
253253
</widget>
254254
</item>
255+
<item>
256+
<widget class="QCheckBox" name="m_enable_psbt_controls">
257+
<property name="text">
258+
<string extracomment="An options window setting to enable advanced PSBT controls.">Enable advanced &amp;PSBT controls</string>
259+
</property>
260+
<property name="toolTip">
261+
<string extracomment="Tooltip text for options window setting that enables advanced PSBT controls.">Whether to show advanced PSBT controls.</string>
262+
</property>
263+
</widget>
264+
</item>
255265
</layout>
256266
</widget>
257267
</item>

src/qt/optionsdialog.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ void OptionsDialog::setMapper()
242242
mapper->addMapping(ui->coinControlFeatures, OptionsModel::CoinControlFeatures);
243243
mapper->addMapping(ui->subFeeFromAmount, OptionsModel::SubFeeFromAmount);
244244
mapper->addMapping(ui->externalSignerPath, OptionsModel::ExternalSignerPath);
245+
mapper->addMapping(ui->m_enable_psbt_controls, OptionsModel::EnablePSBTControls);
245246

246247
/* Network */
247248
mapper->addMapping(ui->mapPortUpnp, OptionsModel::MapPortUPnP);

src/qt/optionsmodel.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ void OptionsModel::Init(bool resetSettings)
8383
settings.setValue("fCoinControlFeatures", false);
8484
fCoinControlFeatures = settings.value("fCoinControlFeatures", false).toBool();
8585

86+
if (!settings.contains("fEnablePSBTControls")) {
87+
settings.setValue("fEnablePSBTControls", false);
88+
}
89+
fEnablePSBTControls = settings.value("fEnablePSBTControls", false).toBool();
90+
8691
// These are shared with the core or have a command-line parameter
8792
// and we want command-line parameters to overwrite the GUI settings.
8893
//
@@ -372,6 +377,8 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const
372377
return settings.value("fListen");
373378
case Server:
374379
return settings.value("server");
380+
case EnablePSBTControls:
381+
return settings.value("fEnablePSBTControls");
375382
default:
376383
return QVariant();
377384
}
@@ -543,6 +550,10 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
543550
setRestartRequired(true);
544551
}
545552
break;
553+
case EnablePSBTControls:
554+
fEnablePSBTControls = value.toBool();
555+
settings.setValue("fEnablePSBTControls", fEnablePSBTControls);
556+
break;
546557
default:
547558
break;
548559
}

src/qt/optionsmodel.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class OptionsModel : public QAbstractListModel
7070
SpendZeroConfChange, // bool
7171
Listen, // bool
7272
Server, // bool
73+
EnablePSBTControls, // bool
7374
OptionIDRowCount,
7475
};
7576

@@ -91,6 +92,7 @@ class OptionsModel : public QAbstractListModel
9192
bool getUseEmbeddedMonospacedFont() const { return m_use_embedded_monospaced_font; }
9293
bool getCoinControlFeatures() const { return fCoinControlFeatures; }
9394
bool getSubFeeFromAmount() const { return m_sub_fee_from_amount; }
95+
bool getEnablePSBTControls() const { return fEnablePSBTControls; }
9496
const QString& getOverriddenByCommandLine() { return strOverriddenByCommandLine; }
9597

9698
/* Explicit setters */
@@ -116,6 +118,7 @@ class OptionsModel : public QAbstractListModel
116118
bool m_use_embedded_monospaced_font;
117119
bool fCoinControlFeatures;
118120
bool m_sub_fee_from_amount;
121+
bool fEnablePSBTControls;
119122
/* settings that were overridden by command-line */
120123
QString strOverriddenByCommandLine;
121124

src/qt/sendcoinsdialog.cpp

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,17 @@ bool SendCoinsDialog::PrepareSendText(QString& question_string, QString& informa
329329
question_string.append(tr("Do you want to create this transaction?"));
330330
question_string.append("<br /><span style='font-size:10pt;'>");
331331
if (model->wallet().privateKeysDisabled() && !model->wallet().hasExternalSigner()) {
332+
/*: Text to inform a user attempting to create a transaction of their current options. At this stage,
333+
a user can only create a PSBT. This string is displayed when private keys are disabled and an external
334+
signer is not available. */
332335
question_string.append(tr("Please, review your transaction proposal. This will produce a Partially Signed Bitcoin Transaction (PSBT) which you can save or copy and then sign with e.g. an offline %1 wallet, or a PSBT-compatible hardware wallet.").arg(PACKAGE_NAME));
336+
} else if (model->getOptionsModel()->getEnablePSBTControls()) {
337+
/*: Text to inform a user attempting to create a transaction of their current options. At this stage,
338+
a user can send their transaction or create a PSBT. This string is displayed when both private keys
339+
and PSBT controls are enabled. */
340+
question_string.append(tr("Please, review your transaction. You can create and send this transaction or create a Partially Signed Bitcoin Transaction (PSBT), which you can save or copy and then sign with, e.g., an offline %1 wallet, or a PSBT-compatible hardware wallet.").arg(PACKAGE_NAME));
333341
} else {
342+
/*: Text to prompt a user to review the details of the transaction they are attempting to send. */
334343
question_string.append(tr("Please, review your transaction."));
335344
}
336345
question_string.append("</span>%1");
@@ -397,7 +406,11 @@ void SendCoinsDialog::sendButtonClicked([[maybe_unused]] bool checked)
397406
const QString confirmation = tr("Confirm send coins");
398407
const QString confirmButtonText = tr("Send");
399408
const QString psbt_button_text = tr("Create Unsigned");
400-
auto confirmationDialog = new SendConfirmationDialog(confirmation, question_string, informative_text, detailed_text, SEND_CONFIRM_DELAY, confirmButtonText, !model->wallet().privateKeysDisabled(), psbt_button_text, this);
409+
410+
// Show the Create Unsigned button if set in the options or if private keys are disabled.
411+
bool show_unsigned_button = model->getOptionsModel()->getEnablePSBTControls() || model->wallet().privateKeysDisabled();
412+
413+
auto confirmationDialog = new SendConfirmationDialog(confirmation, question_string, informative_text, detailed_text, SEND_CONFIRM_DELAY, confirmButtonText, !model->wallet().privateKeysDisabled(), psbt_button_text, show_unsigned_button, this);
401414
confirmationDialog->setAttribute(Qt::WA_DeleteOnClose);
402415
// TODO: Replace QDialog::exec() with safer QDialog::show().
403416
const auto retval = static_cast<QMessageBox::StandardButton>(confirmationDialog->exec());
@@ -1030,15 +1043,16 @@ void SendCoinsDialog::coinControlUpdateLabels()
10301043
}
10311044
}
10321045

1033-
SendConfirmationDialog::SendConfirmationDialog(const QString& title, const QString& text, const QString& informative_text, const QString& detailed_text, int _secDelay, const QString& _confirmButtonText, bool enable_send, const QString& psbt_button_text, QWidget* parent)
1046+
SendConfirmationDialog::SendConfirmationDialog(const QString& title, const QString& text, const QString& informative_text, const QString& detailed_text, int _secDelay, const QString& _confirmButtonText, bool enable_send, const QString& psbt_button_text, bool show_unsigned, QWidget* parent)
10341047
: QMessageBox(parent), secDelay(_secDelay), confirmButtonText(_confirmButtonText), m_enable_send(enable_send), m_psbt_button_text(psbt_button_text)
10351048
{
10361049
setIcon(QMessageBox::Question);
10371050
setWindowTitle(title); // On macOS, the window title is ignored (as required by the macOS Guidelines).
10381051
setText(text);
10391052
setInformativeText(informative_text);
10401053
setDetailedText(detailed_text);
1041-
setStandardButtons(QMessageBox::Save | QMessageBox::Yes | QMessageBox::Cancel);
1054+
setStandardButtons(QMessageBox::Yes | QMessageBox::Cancel);
1055+
if (show_unsigned) addButton(QMessageBox::Save);
10421056
setDefaultButton(QMessageBox::Cancel);
10431057
yesButton = button(QMessageBox::Yes);
10441058
if (confirmButtonText.isEmpty()) {
@@ -1073,14 +1087,18 @@ void SendConfirmationDialog::updateButtons()
10731087
{
10741088
yesButton->setEnabled(false);
10751089
yesButton->setText(confirmButtonText + (m_enable_send ? (" (" + QString::number(secDelay) + ")") : QString("")));
1076-
m_psbt_button->setEnabled(false);
1077-
m_psbt_button->setText(m_psbt_button_text + " (" + QString::number(secDelay) + ")");
1090+
if (m_psbt_button) {
1091+
m_psbt_button->setEnabled(false);
1092+
m_psbt_button->setText(m_psbt_button_text + " (" + QString::number(secDelay) + ")");
1093+
}
10781094
}
10791095
else
10801096
{
10811097
yesButton->setEnabled(m_enable_send);
10821098
yesButton->setText(confirmButtonText);
1083-
m_psbt_button->setEnabled(true);
1084-
m_psbt_button->setText(m_psbt_button_text);
1099+
if (m_psbt_button) {
1100+
m_psbt_button->setEnabled(true);
1101+
m_psbt_button->setText(m_psbt_button_text);
1102+
}
10851103
}
10861104
}

src/qt/sendcoinsdialog.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class SendConfirmationDialog : public QMessageBox
114114
Q_OBJECT
115115

116116
public:
117-
SendConfirmationDialog(const QString& title, const QString& text, const QString& informative_text = "", const QString& detailed_text = "", int secDelay = SEND_CONFIRM_DELAY, const QString& confirmText = "", bool enable_send = true, const QString& psbt_text = "Create Unsigned", QWidget* parent = nullptr);
117+
SendConfirmationDialog(const QString& title, const QString& text, const QString& informative_text = "", const QString& detailed_text = "", int secDelay = SEND_CONFIRM_DELAY, const QString& confirmText = "", bool enable_send = true, const QString& psbt_text = "Create Unsigned", bool show_unsigned = false, QWidget* parent = nullptr);
118118
int exec() override;
119119

120120
private Q_SLOTS:

0 commit comments

Comments
 (0)