From 55a89553773f28869d3c965c57dc447fd9a0b686 Mon Sep 17 00:00:00 2001 From: tobtoht Date: Fri, 15 Dec 2023 14:10:55 +0100 Subject: [PATCH] send: disable send button during tx broadcast --- src/MainWindow.cpp | 2 +- src/SendWidget.cpp | 19 +++++++++++-------- src/SendWidget.h | 9 +++++---- src/libwalletqt/Wallet.cpp | 2 ++ src/libwalletqt/Wallet.h | 1 + 5 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index f5417ac..b416a7c 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -1577,7 +1577,7 @@ void MainWindow::onKeysCorrupted() { if (!m_criticalWarningShown) { m_criticalWarningShown = true; Utils::showError(this, "Wallet keys are corrupted", "WARNING!\n\nTo prevent LOSS OF FUNDS do NOT continue to use this wallet file.\n\nRestore your wallet from seed.\n\nPlease report this incident to the Feather developers.\n\nWARNING!"); - m_sendWidget->disableSendButton(); + m_sendWidget->disallowSending(); } } diff --git a/src/SendWidget.cpp b/src/SendWidget.cpp index 03ac74c..108bb3f 100644 --- a/src/SendWidget.cpp +++ b/src/SendWidget.cpp @@ -32,8 +32,10 @@ SendWidget::SendWidget(Wallet *wallet, QWidget *parent) QValidator *validator = new QRegularExpressionValidator(rx, this); ui->lineAmount->setValidator(validator); - connect(m_wallet, &Wallet::initiateTransaction, this, &SendWidget::onInitiateTransaction); - connect(m_wallet, &Wallet::transactionCreated, this, &SendWidget::onEndTransaction); + connect(m_wallet, &Wallet::initiateTransaction, this, &SendWidget::disableSendButton); + connect(m_wallet, &Wallet::transactionCreated, this, &SendWidget::enableSendButton); + connect(m_wallet, &Wallet::beginCommitTransaction, this, &SendWidget::disableSendButton); + connect(m_wallet, &Wallet::transactionCommitted, this, &SendWidget::enableSendButton); connect(WalletManager::instance(), &WalletManager::openAliasResolved, this, &SendWidget::onOpenAliasResolved); @@ -349,18 +351,19 @@ void SendWidget::payToMany() { ui->lineAddress->payToMany(); } -void SendWidget::onInitiateTransaction() { +void SendWidget::disableSendButton() { ui->btnSend->setEnabled(false); } -void SendWidget::onEndTransaction() { - if (!m_sendDisabled) { - ui->btnSend->setEnabled(true); +void SendWidget::enableSendButton() { + if (m_disallowSending) { + return; } + ui->btnSend->setEnabled(true); } -void SendWidget::disableSendButton() { - m_sendDisabled = true; +void SendWidget::disallowSending() { + m_disallowSending = true; ui->btnSend->setEnabled(false); } diff --git a/src/SendWidget.h b/src/SendWidget.h index f379b46..9b74cbb 100644 --- a/src/SendWidget.h +++ b/src/SendWidget.h @@ -38,11 +38,12 @@ public slots: void updateConversionLabel(); void onOpenAliasResolved(const QString &openAlias, const QString &address, bool dnssecValid); void onPreferredFiatCurrencyChanged(); - void disableSendButton(); void setWebsocketEnabled(bool enabled); - void onInitiateTransaction(); - void onEndTransaction(); + void disableSendButton(); + void enableSendButton(); + + void disallowSending(); private slots: void onDataPasted(const QString &data); @@ -57,7 +58,7 @@ private: QScopedPointer ui; Wallet *m_wallet; - bool m_sendDisabled = false; + bool m_disallowSending = false; }; #endif // FEATHER_SENDWIDGET_H diff --git a/src/libwalletqt/Wallet.cpp b/src/libwalletqt/Wallet.cpp index 774fded..77c39ed 100644 --- a/src/libwalletqt/Wallet.cpp +++ b/src/libwalletqt/Wallet.cpp @@ -834,6 +834,8 @@ void Wallet::onTransactionCreated(Monero::PendingTransaction *mtx, const QVector // Phase 3: Commit or dispose void Wallet::commitTransaction(PendingTransaction *tx, const QString &description) { + emit beginCommitTransaction(); + // Clear list of selected transfers this->setSelectedInputs({}); diff --git a/src/libwalletqt/Wallet.h b/src/libwalletqt/Wallet.h index f906981..5321b91 100644 --- a/src/libwalletqt/Wallet.h +++ b/src/libwalletqt/Wallet.h @@ -431,6 +431,7 @@ signals: void deviceButtonPressed(); void deviceError(const QString &message); void walletPassphraseNeeded(bool onDevice); + void beginCommitTransaction(); void transactionCommitted(bool status, PendingTransaction *t, const QStringList& txid, const QMap &txHexMap); void deviceShowAddressShowed(); void transactionProofVerified(TxProofResult result);