]> Nutra Git (v2) - gamesguru/feather.git/commitdiff
Show warning on corrupted keys
authortobtoht <thotbot@protonmail.com>
Sat, 12 Mar 2022 12:53:46 +0000 (13:53 +0100)
committertobtoht <thotbot@protonmail.com>
Sat, 12 Mar 2022 12:53:46 +0000 (13:53 +0100)
src/MainWindow.cpp
src/MainWindow.h
src/SendWidget.cpp
src/SendWidget.h
src/appcontext.cpp
src/appcontext.h
src/libwalletqt/Subaddress.cpp
src/libwalletqt/Subaddress.h

index 11ca5e18bb75abc0665f3eb068bb3e17f73ef1ef..82c9ea4ef42cfee8997b100579bebea3a6704fd8 100644 (file)
@@ -377,6 +377,7 @@ void MainWindow::initWalletContext() {
     connect(m_ctx.get(), &AppContext::initiateTransaction,      this, &MainWindow::onInitiateTransaction);
     connect(m_ctx.get(), &AppContext::endTransaction,           this, &MainWindow::onEndTransaction);
     connect(m_ctx.get(), &AppContext::customRestoreHeightSet,   this, &MainWindow::onCustomRestoreHeightSet);
+    connect(m_ctx.get(), &AppContext::keysCorrupted,            this, &MainWindow::onKeysCorrupted);
 
     // Nodes
     connect(m_ctx->nodes, &Nodes::updateStatus,    this, &MainWindow::onSetStatusText);
@@ -1439,6 +1440,14 @@ void MainWindow::onCustomRestoreHeightSet(int height) {
     this->menuQuitClicked();
 }
 
+void MainWindow::onKeysCorrupted() {
+    if (!m_criticalWarningShown) {
+        m_criticalWarningShown = true;
+        QMessageBox::warning(this, "Critical error", "WARNING!\n\nThe wallet keys are corrupted.\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();
+    }
+}
+
 void MainWindow::onExportHistoryCSV(bool checked) {
     if (m_ctx->wallet == nullptr)
         return;
index 03271aa455d9ba30143a08efe07e560544ef1a65..97612b850586b102fc115b55ca2723d20cc9efba 100644 (file)
@@ -139,6 +139,7 @@ private slots:
     void onInitiateTransaction();
     void onEndTransaction();
     void onCustomRestoreHeightSet(int height);
+    void onKeysCorrupted();
 
     // libwalletqt
     void onBalanceUpdated(quint64 balance, quint64 spendable);
@@ -274,6 +275,7 @@ private:
     QTimer m_txTimer;
 
     bool cleanedUp = false;
+    bool m_criticalWarningShown = false;
 
     EventFilter *m_eventFilter = nullptr;
     qint64 m_userLastActive = QDateTime::currentSecsSinceEpoch();
index 920ec8a8fa133aa03041057bec6ca95511ae62f8..20f09db22c6d64bc05c45b0db4d1394f823b40db 100644 (file)
@@ -305,7 +305,14 @@ void SendWidget::onInitiateTransaction() {
 }
 
 void SendWidget::onEndTransaction() {
-    ui->btnSend->setEnabled(true);
+    if (!m_sendDisabled) {
+        ui->btnSend->setEnabled(true);
+    }
+}
+
+void SendWidget::disableSendButton() {
+    m_sendDisabled = true;
+    ui->btnSend->setEnabled(false);
 }
 
 void SendWidget::onDataPasted(const QString &data) {
index f961f53f95cc91557b65205b977f3719836ba0ab..bc9bc7340dfdeff8548d476baa45310676102847 100644 (file)
@@ -40,6 +40,7 @@ public slots:
     void onOpenAliasResolveError(const QString &err);
     void onOpenAliasResolved(const QString &openAlias, const QString &address, bool dnssecValid);
     void onPreferredFiatCurrencyChanged();
+    void disableSendButton();
 
     void onInitiateTransaction();
     void onEndTransaction();
@@ -51,10 +52,12 @@ private:
     void setupComboBox();
     double amountDouble();
 
-    QScopedPointer<Ui::SendWidget> ui;
-    QSharedPointer<AppContext> m_ctx;
     quint64 amount();
     double conversionAmount();
+
+    QScopedPointer<Ui::SendWidget> ui;
+    QSharedPointer<AppContext> m_ctx;
+    bool m_sendDisabled = false;
 };
 
 #endif // FEATHER_SENDWIDGET_H
index 06db5949e6596621610bc4b5bad2553bac501241..15420b0cd61a6af28f97a6ed0242e05f48684da4 100644 (file)
@@ -345,7 +345,13 @@ void AppContext::syncStatusUpdated(quint64 height, quint64 target) {
 
 void AppContext::refreshModels() {
     this->wallet->history()->refresh(this->wallet->currentSubaddressAccount());
-    this->wallet->subaddress()->refresh(this->wallet->currentSubaddressAccount());
     this->wallet->coins()->refresh(this->wallet->currentSubaddressAccount());
-    // Todo: set timer for refreshes
+    bool r = this->wallet->subaddress()->refresh(this->wallet->currentSubaddressAccount());
+
+    if (!r) {
+        // This should only happen if wallet keys got corrupted or were tampered with
+        // The list of subaddresses is wiped to prevent loss of funds
+        // Notify MainWindow to display an error message
+        emit keysCorrupted();
+    }
 }
index 9fb7a1012f886e75c049e4614fadfc3cc7de8f1a..dd6fcdebd192b9a2aad5b3f4032768f400f078f7 100644 (file)
@@ -92,6 +92,7 @@ signals:
     void deviceButtonRequest(quint64 code);
     void deviceButtonPressed();
     void deviceError(const QString &message);
+    void keysCorrupted();
 
 private:
     DaemonRpc *m_rpc;
index c39aa27de947314b5200de7e33c4b26e933dd12b..4b635b04ab6d4149fe0090ab7b6868192c380aa6 100644 (file)
@@ -73,10 +73,11 @@ bool Subaddress::setLabel(quint32 accountIndex, quint32 addressIndex, const QStr
     return r;
 }
 
-void Subaddress::refresh(quint32 accountIndex) const
+bool Subaddress::refresh(quint32 accountIndex) const
 {
-    m_subaddressImpl->refresh(accountIndex);
+    bool r = m_subaddressImpl->refresh(accountIndex);
     getAll();
+    return r;
 }
 
 quint64 Subaddress::unusedLookahead() const
index 543fb79ec5b2d987e9ce83aeb3055f196c766daf..a27e435503e58d6969ef95610d95406fa592aefc 100644 (file)
@@ -20,7 +20,7 @@ public:
     bool getRow(int index, std::function<void (Monero::SubaddressRow &row)> callback) const;
     bool addRow(quint32 accountIndex, const QString &label) const;
     bool setLabel(quint32 accountIndex, quint32 addressIndex, const QString &label) const;
-    void refresh(quint32 accountIndex) const;
+    bool refresh(quint32 accountIndex) const;
     quint64 unusedLookahead() const;
     quint64 count() const;
     QString errorString() const;