diff --git a/src/qt/appearancewidget.h b/src/qt/appearancewidget.h index 2fa1f9b8b769..3a56932af28b 100644 --- a/src/qt/appearancewidget.h +++ b/src/qt/appearancewidget.h @@ -44,7 +44,7 @@ private Q_SLOTS: private: Ui::AppearanceWidget* ui; QDataWidgetMapper* mapper; - OptionsModel* model; + OptionsModel* model{nullptr}; bool fAcceptChanges{false}; QString prevTheme; int prevScale; diff --git a/src/qt/clientfeeds.cpp b/src/qt/clientfeeds.cpp index 3383c67a3b81..8460394913a8 100644 --- a/src/qt/clientfeeds.cpp +++ b/src/qt/clientfeeds.cpp @@ -211,6 +211,7 @@ void ProposalFeed::fetch() const auto data_mn = m_feed_masternode.data(); if (!data_mn || !data_mn->m_valid) { + m_retry_pending.store(true); return; } diff --git a/src/qt/clientmodel.cpp b/src/qt/clientmodel.cpp index 85b4b2d805a4..6169c8cee841 100644 --- a/src/qt/clientmodel.cpp +++ b/src/qt/clientmodel.cpp @@ -109,6 +109,8 @@ void ClientModel::stop() { unsubscribeFromCoreSignals(); + m_feeds->stop(); + m_thread->quit(); m_thread->wait(); } diff --git a/src/qt/masternodedialogs.cpp b/src/qt/masternodedialogs.cpp index d2432d64a1e2..d7afd59bd65f 100644 --- a/src/qt/masternodedialogs.cpp +++ b/src/qt/masternodedialogs.cpp @@ -160,6 +160,7 @@ MasternodeActionDialog::MasternodeActionDialog(interfaces::Node& node, WalletMod m_wallet_model{wallet_model}, m_protx_hash{entry.proTxHashRaw()}, m_operator_pubkey{entry.operatorPubKeyBytes()}, + m_is_shared{entry.isShared()}, m_runner{wallet_model ? new MasternodeOperationRunner(node.evo(), wallet_model->wallet(), this) : nullptr} { } @@ -228,10 +229,11 @@ bool MasternodeActionDialog::canSign() const return m_wallet_model != nullptr && !m_wallet_model->wallet().privateKeysDisabled(); } -void MasternodeActionDialog::setOkValid(bool valid) +void MasternodeActionDialog::setOkValid(bool valid, const QString& tooltip) { m_valid = valid; if (m_ok_button) m_ok_button->setEnabled(valid && canSign() && !m_busy); + if (m_ok_button && canSign()) m_ok_button->setToolTip(tooltip); } void MasternodeActionDialog::showError(const QString& message) @@ -279,7 +281,7 @@ void MasternodeActionDialog::setBusy(bool busy) QApplication::restoreOverrideCursor(); } if (m_button_box) m_button_box->setEnabled(!busy); - setOkValid(m_valid); + if (m_ok_button) setOkValid(m_valid, m_ok_button->toolTip()); } void MasternodeActionDialog::resolveOperatorKey(OperatorSecretWidget& widget, SecretCallback callback) @@ -421,6 +423,8 @@ UpdateServiceDialog::UpdateServiceDialog(interfaces::Node& node, WalletModel* wa "payout. Select an address only to override that choice.")); } + connect(m_fee_source, qOverload(&QComboBox::currentIndexChanged), this, &UpdateServiceDialog::validate); + setupUi(m_type == MnType::Evo ? tr("Update EvoNode Service") : tr("Update Masternode Service"), tr("Update the registered service endpoints. A successful update also revives a PoSe-banned " "masternode. Every current value is prefilled so unchanged fields are preserved."), @@ -438,7 +442,9 @@ void UpdateServiceDialog::validate() if (m_type == MnType::Evo) { ok &= IsValidPlatformNodeId(m_platform_node_id_edit->text().trimmed()); } - setOkValid(ok); + const bool has_fee_source{!m_is_shared || !m_fee_source->selectedAddress().isEmpty()}; + setOkValid(ok && has_fee_source, + has_fee_source ? QString{} : tr("Select a wallet address with funds to pay the transaction fee.")); } std::optional UpdateServiceDialog::buildNetInfo(QString& error) const @@ -681,13 +687,20 @@ RevokeDialog::RevokeDialog(interfaces::Node& node, WalletModel* wallet_model, co "payout. Select an address only to override that choice.")); } + connect(m_fee_source, qOverload(&QComboBox::currentIndexChanged), this, &RevokeDialog::validate); + setupUi(tr("Revoke Masternode Service"), tr("Revoking clears the service address and PoSe-bans the masternode until its owner changes the " "operator key. The collateral is not affected."), form, tr("Revoke")); } -void RevokeDialog::validate() { setOkValid(m_operator_key->isValid()); } +void RevokeDialog::validate() +{ + const bool has_fee_source{!m_is_shared || !m_fee_source->selectedAddress().isEmpty()}; + setOkValid(m_operator_key->isValid() && has_fee_source, + has_fee_source ? QString{} : tr("Select a wallet address with funds to pay the transaction fee.")); +} std::optional RevokeDialog::buildRequest(CBLSSecretKey operator_key, QString& error) const { diff --git a/src/qt/masternodedialogs.h b/src/qt/masternodedialogs.h index 0375d5d9bbd5..a997cbb1e43b 100644 --- a/src/qt/masternodedialogs.h +++ b/src/qt/masternodedialogs.h @@ -95,7 +95,7 @@ public Q_SLOTS: FeeSourcePicker* addFeeSourceRow(QFormLayout* form, const QString& automatic_note); bool canSign() const; - void setOkValid(bool valid); + void setOkValid(bool valid, const QString& tooltip = {}); void showError(const QString& message); void clearError(); void abortOperation(const QString& message); @@ -106,6 +106,7 @@ public Q_SLOTS: WalletModel* const m_wallet_model; const uint256 m_protx_hash; const std::vector m_operator_pubkey; + const bool m_is_shared; MasternodeOperationRunner* const m_runner; protected Q_SLOTS: diff --git a/src/qt/optionsdialog.cpp b/src/qt/optionsdialog.cpp index 1d0b4f5eee10..23f9ffd799b6 100644 --- a/src/qt/optionsdialog.cpp +++ b/src/qt/optionsdialog.cpp @@ -110,7 +110,13 @@ OptionsDialog::OptionsDialog(QWidget* parent, bool enableWallet) #endif pageButtons = new QButtonGroup(this); - pageButtons->addButton(ui->btnMain, pageButtons->buttons().size()); + pageButtons->addButton(ui->btnMain, TAB_MAIN); + pageButtons->addButton(ui->btnWallet, TAB_WALLET); + pageButtons->addButton(ui->btnCoinJoin, TAB_COINJOIN); + pageButtons->addButton(ui->btnNetwork, TAB_NETWORK); + pageButtons->addButton(ui->btnDisplay, TAB_DISPLAY); + pageButtons->addButton(ui->btnAppearance, TAB_APPEARANCE); + /* Remove Wallet/CoinJoin tabs and 3rd party-URL textbox in case of -disablewallet */ if (!m_enable_wallet) { ui->stackedWidgetOptions->removeWidget(ui->pageWallet); @@ -124,16 +130,11 @@ OptionsDialog::OptionsDialog(QWidget* parent, bool enableWallet) ui->showGovernanceCycleIcon->hide(); } else { ui->btnCoinJoin->setText(QString::fromStdString(gCoinJoinName)); - pageButtons->addButton(ui->btnWallet, pageButtons->buttons().size()); - pageButtons->addButton(ui->btnCoinJoin, pageButtons->buttons().size()); } - pageButtons->addButton(ui->btnNetwork, pageButtons->buttons().size()); - pageButtons->addButton(ui->btnDisplay, pageButtons->buttons().size()); - pageButtons->addButton(ui->btnAppearance, pageButtons->buttons().size()); connect(pageButtons, &QButtonGroup::idClicked, this, &OptionsDialog::showPage); - showPage(0); + showPage(TAB_MAIN); #ifdef ENABLE_EXTERNAL_SIGNER ui->externalSignerPath->setToolTip(ui->externalSignerPath->toolTip().arg(PACKAGE_NAME)); @@ -416,7 +417,9 @@ void OptionsDialog::showPage(int index) GUIUtil::setFont(vecNormal, GUIUtil::FontWeight::Normal, 16); GUIUtil::updateFonts(); - ui->stackedWidgetOptions->setCurrentIndex(index); + QWidget* const pages[]{ui->pageMain, ui->pageWallet, ui->pageCoinJoin, + ui->pageNetwork, ui->pageDisplay, ui->pageAppearance}; + ui->stackedWidgetOptions->setCurrentWidget(pages[index]); btnActive->setChecked(true); } diff --git a/src/qt/psbtoperationsdialog.cpp b/src/qt/psbtoperationsdialog.cpp index bc834508a130..b281d247173e 100644 --- a/src/qt/psbtoperationsdialog.cpp +++ b/src/qt/psbtoperationsdialog.cpp @@ -160,9 +160,13 @@ void PSBTOperationsDialog::saveTransaction() { if (filename.isEmpty()) { return; } - std::ofstream out{filename.toLocal8Bit().data(), std::ofstream::out | std::ofstream::binary}; + std::ofstream out(GUIUtil::QStringToPath(filename), std::ofstream::out | std::ofstream::binary); out << ssTx.str(); out.close(); + if (!out) { + showStatus(tr("Failed to save PSBT to disk."), StatusLevel::ERR); + return; + } showStatus(tr("PSBT saved to disk."), StatusLevel::INFO); } @@ -190,7 +194,7 @@ QString PSBTOperationsDialog::renderTransaction(const PartiallySignedTransaction PSBTAnalysis analysis = AnalyzePSBT(psbtx); tx_description.append(bullet_point); - if (!*analysis.fee) { + if (!analysis.fee.has_value()) { // This happens if the transaction is missing input UTXO information. tx_description.append(tr("Unable to calculate transaction fee or total transaction amount.")); } else { diff --git a/src/qt/sendcoinsdialog.cpp b/src/qt/sendcoinsdialog.cpp index 26208556083b..b83f75714cd9 100644 --- a/src/qt/sendcoinsdialog.cpp +++ b/src/qt/sendcoinsdialog.cpp @@ -190,7 +190,7 @@ void SendCoinsDialog::setModel(WalletModel *_model) fKeepChangeAddress = _model->getOptionsModel()->getKeepChangeAddress(); QSettings settings; - if (fKeepChangeAddress && settings.contains("sCustomChangeAddress")) { + if (!m_coin_control->IsUsingCoinJoin() && fKeepChangeAddress && settings.contains("sCustomChangeAddress")) { ui->checkBoxCoinControlChange->setChecked(true); ui->lineEditCoinControlChange->setText(settings.value("sCustomChangeAddress").toString()); coinControlChangeEdited(ui->lineEditCoinControlChange->text()); @@ -249,7 +249,7 @@ void SendCoinsDialog::setModel(WalletModel *_model) SendCoinsDialog::~SendCoinsDialog() { QSettings settings; - if (fKeepChangeAddress) { + if (fKeepChangeAddress && !m_coin_control->IsUsingCoinJoin()) { settings.setValue("sCustomChangeAddress", ui->lineEditCoinControlChange->text()); } settings.setValue("fFeeSectionMinimized", fFeeMinimized); @@ -528,9 +528,13 @@ void SendCoinsDialog::presentPSBT(PartiallySignedTransaction& psbtx) if (filename.isEmpty()) { return; } - std::ofstream out{filename.toLocal8Bit().data(), std::ofstream::out | std::ofstream::binary}; + std::ofstream out(GUIUtil::QStringToPath(filename), std::ofstream::out | std::ofstream::binary); out << ssTx.str(); out.close(); + if (!out) { + Q_EMIT message(tr("PSBT save failed"), tr("Failed to save PSBT to disk"), CClientUIInterface::MSG_ERROR); + break; + } //: Popup message when a PSBT has been saved to a file Q_EMIT message(tr("PSBT saved"), tr("PSBT saved to disk"), CClientUIInterface::MSG_INFORMATION); break; diff --git a/src/qt/sharedmndialogs.cpp b/src/qt/sharedmndialogs.cpp index afd83188146a..10e867626b90 100644 --- a/src/qt/sharedmndialogs.cpp +++ b/src/qt/sharedmndialogs.cpp @@ -317,7 +317,6 @@ bool ComputeSharedSignHash(SharedSigCollector::Kind kind, const QString& pro_tx_ UpdateShareDialog::UpdateShareDialog(interfaces::Node& node, WalletModel* wallet_model, const MasternodeEntry& entry, QWidget* parent) : MasternodeActionDialog(node, wallet_model, entry, parent), m_v24_active{node.isV24Active()}, - m_is_shared{entry.isShared()}, m_voting_address{entry.votingAddress()}, m_shares{entry.shares()} { diff --git a/src/qt/sharedmndialogs.h b/src/qt/sharedmndialogs.h index a39536f6f846..8ef926ffb1d5 100644 --- a/src/qt/sharedmndialogs.h +++ b/src/qt/sharedmndialogs.h @@ -64,7 +64,6 @@ class UpdateShareDialog : public MasternodeActionDialog void useNewAddress(); const bool m_v24_active; - const bool m_is_shared; const QString m_voting_address; const std::vector m_shares; diff --git a/src/qt/test/masternodemaintenancetests.cpp b/src/qt/test/masternodemaintenancetests.cpp index 2b9079281a7a..0246c06587c9 100644 --- a/src/qt/test/masternodemaintenancetests.cpp +++ b/src/qt/test/masternodemaintenancetests.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -300,6 +301,39 @@ void MasternodeMaintenanceTests::automaticFeeSource() const auto shared_revocation{shared_revoke.buildRequest(shared->operatorSecret(), error)}; QVERIFY2(shared_revocation.has_value(), qPrintable(error)); QVERIFY(shared_revocation->fee_source == std::optional{funded}); + + const auto empty_wallet{MakeTestWallet(m_node, context, "unfunded_operator")}; + QVERIFY(empty_wallet != nullptr); + guard.keep(empty_wallet); + WalletModel empty_model(interfaces::MakeWallet(context, empty_wallet), models.client); + UpdateServiceDialog unfunded_service(m_node, &empty_model, shared_entry, capabilities, nullptr); + RevokeDialog unfunded_revoke(m_node, &empty_model, shared_entry, nullptr); + auto check_fee_selection = [&](MasternodeActionDialog& dialog, bool has_funds) { + auto* key_widget = dialog.findChild(); + QVERIFY(key_widget); + key_widget->findChild()->setText(QString::fromStdString(shared->operatorSecret().ToString(false))); + QVERIFY(key_widget->isValid()); + auto* fee_picker = dialog.findChild(); + auto* buttons = dialog.findChild(); + QVERIFY(fee_picker); + QVERIFY(buttons); + QCOMPARE(fee_picker->count(), has_funds ? 1 : 0); + auto* ok_button = buttons->button(QDialogButtonBox::Ok); + QCOMPARE(ok_button->isEnabled(), has_funds); + QCOMPARE(ok_button->toolTip().isEmpty(), has_funds); + if (has_funds) { + fee_picker->setCurrentIndex(-1); + QVERIFY(!ok_button->isEnabled()); + QVERIFY(!ok_button->toolTip().isEmpty()); + fee_picker->setCurrentIndex(0); + QVERIFY(ok_button->isEnabled()); + QVERIFY(ok_button->toolTip().isEmpty()); + } + }; + check_fee_selection(unfunded_service, false); + check_fee_selection(unfunded_revoke, false); + check_fee_selection(shared_service, true); + check_fee_selection(shared_revoke, true); } void MasternodeMaintenanceTests::operatorSecretValidation() diff --git a/src/qt/test/optiontests.cpp b/src/qt/test/optiontests.cpp index 2d3ba5d027e5..38fb5bbefd05 100644 --- a/src/qt/test/optiontests.cpp +++ b/src/qt/test/optiontests.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -17,6 +18,7 @@ #include #include #include +#include #include #include @@ -325,3 +327,16 @@ void OptionTests::fontScaleSources() set_sources(none, none, none); GUIUtil::setFontScale(previous_scale); } + +void OptionTests::tabsWithoutWallet() +{ + OptionsDialog dialog{nullptr, /*enableWallet=*/false}; + auto* pages = dialog.findChild("stackedWidgetOptions"); + QVERIFY(pages); + dialog.setCurrentTab(OptionsDialog::TAB_NETWORK); + QCOMPARE(pages->currentWidget()->objectName(), QString{"pageNetwork"}); + dialog.setCurrentTab(OptionsDialog::TAB_DISPLAY); + QCOMPARE(pages->currentWidget()->objectName(), QString{"pageDisplay"}); + dialog.setCurrentTab(OptionsDialog::TAB_APPEARANCE); + QCOMPARE(pages->currentWidget()->objectName(), QString{"pageAppearance"}); +} diff --git a/src/qt/test/optiontests.h b/src/qt/test/optiontests.h index 6548972c092b..7d2eac838eac 100644 --- a/src/qt/test/optiontests.h +++ b/src/qt/test/optiontests.h @@ -25,6 +25,7 @@ private Q_SLOTS: void invalidLangSetting(); void parametersInteraction(); void extractFilter(); + void tabsWithoutWallet(); void effectivePointSize(); void updateFontsWithPixelSizedWidget(); void fontScaleSources(); diff --git a/src/qt/walletcontroller.cpp b/src/qt/walletcontroller.cpp index 8f1d0dded36c..03c721b66ce8 100644 --- a/src/qt/walletcontroller.cpp +++ b/src/qt/walletcontroller.cpp @@ -573,15 +573,27 @@ void MigrateWalletActivity::migrate(WalletModel* wallet_model) "an incorrect migration, the backup can be restored with the \"Restore Wallet\" functionality.")); box.setStandardButtons(QMessageBox::Yes|QMessageBox::Cancel); box.setDefaultButton(QMessageBox::Yes); - if (box.exec() != QMessageBox::Yes) return; + if (box.exec() != QMessageBox::Yes) { + Q_EMIT finished(); + return; + } // Get the passphrase if it is encrypted regardless of it is locked or unlocked. We need the passphrase itself. SecureString passphrase; WalletModel::EncryptionStatus enc_status = wallet_model->getEncryptionStatus(); - if (enc_status == WalletModel::EncryptionStatus::Locked || enc_status == WalletModel::EncryptionStatus::Unlocked) { + if (enc_status == WalletModel::EncryptionStatus::Locked || + enc_status == WalletModel::EncryptionStatus::Unlocked || + enc_status == WalletModel::EncryptionStatus::UnlockedForMixingOnly) { AskPassphraseDialog dlg(AskPassphraseDialog::Unlock, m_parent_widget, &passphrase); dlg.setModel(wallet_model); - dlg.exec(); + if (dlg.exec() != QDialog::Accepted) { + // A failed unlock attempt can leave the wallet unlocked. + if (enc_status != WalletModel::EncryptionStatus::Unlocked) { + wallet_model->setWalletLocked(true, {}, enc_status == WalletModel::EncryptionStatus::UnlockedForMixingOnly); + } + Q_EMIT finished(); + return; + } } // GUI needs to remove the wallet so that it can actually be unloaded by migration