]> Nutra Git (v2) - gamesguru/feather.git/commitdiff
Trezor: add passphrase support
authortobtoht <thotbot@protonmail.com>
Thu, 8 Jul 2021 00:34:27 +0000 (02:34 +0200)
committertobtoht <thotbot@protonmail.com>
Thu, 8 Jul 2021 00:34:27 +0000 (02:34 +0200)
src/MainWindow.cpp
src/MainWindow.h
src/WindowManager.cpp
src/WindowManager.h
src/libwalletqt/WalletManager.cpp

index 2cc7816cc9ae8483af516fcd392ac016f37423d1..c36717cf299b6fbd719abdf2ec0a59b2c1b63dc7 100644 (file)
@@ -377,6 +377,7 @@ void MainWindow::initWalletContext() {
     // Wallet
     connect(m_ctx->wallet, &Wallet::connectionStatusChanged, this, &MainWindow::onConnectionStatusChanged);
     connect(m_ctx->wallet, &Wallet::currentSubaddressAccountChanged, this, &MainWindow::updateTitle);
+    connect(m_ctx->wallet, &Wallet::walletPassphraseNeeded, this, &MainWindow::onWalletPassphraseNeeded);
 }
 
 void MainWindow::menuToggleTabVisible(const QString &key){
@@ -1190,6 +1191,25 @@ void MainWindow::onDeviceButtonPressed() {
     m_splashDialog->hide();
 }
 
+void MainWindow::onWalletPassphraseNeeded(bool on_device) {
+    auto button = QMessageBox::question(nullptr, "Wallet Passphrase Needed", "Enter passphrase on hardware wallet?\n\n"
+                                                                             "It is recommended to enter passphrase on "
+                                                                             "the hardware wallet for better security.",
+                                        QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
+    if (button == QMessageBox::Yes) {
+        m_ctx->wallet->onPassphraseEntered("", true, false);
+        return;
+    }
+
+    bool ok;
+    QString passphrase = QInputDialog::getText(nullptr, "Wallet Passphrase Needed", "Enter passphrase:", QLineEdit::EchoMode::Password, "", &ok);
+    if (ok) {
+        m_ctx->wallet->onPassphraseEntered(passphrase, false, false);
+    } else {
+        m_ctx->wallet->onPassphraseEntered(passphrase, false, true);
+    }
+}
+
 void MainWindow::updateNetStats() {
     if (!m_ctx->wallet || m_ctx->wallet->connectionStatus() == Wallet::ConnectionStatus_Disconnected
                        || m_ctx->wallet->connectionStatus() == Wallet::ConnectionStatus_Synchronized)
index 41272f892f861aca3aa4a2b45e896dc2fb17da0b..aa90fa44b7d613f1910dc94b4592dccb7f77789c 100644 (file)
@@ -174,6 +174,7 @@ private slots:
     void onDeviceError(const QString &error);
     void onDeviceButtonRequest(quint64 code);
     void onDeviceButtonPressed();
+    void onWalletPassphraseNeeded(bool on_device);
     void menuHwDeviceClicked();
     void onUpdatesAvailable(const QJsonObject &updates);
     void toggleSearchbar(bool enabled);
index b67b5c651c2569f709bee46b0e4604b5b424b617..33dd4cc85b8459e04aea29b909f257d01c08d6e7 100644 (file)
@@ -3,6 +3,7 @@
 
 #include "WindowManager.h"
 
+#include <QInputDialog>
 #include <QMessageBox>
 
 #include "constants.h"
@@ -24,6 +25,7 @@ WindowManager::WindowManager() {
     connect(m_walletManager, &WalletManager::deviceButtonRequest, this, &WindowManager::onDeviceButtonRequest);
     connect(m_walletManager, &WalletManager::deviceButtonPressed, this, &WindowManager::onDeviceButtonPressed);
     connect(m_walletManager, &WalletManager::deviceError,         this, &WindowManager::onDeviceError);
+    connect(m_walletManager, &WalletManager::walletPassphraseNeeded, this, &WindowManager::onWalletPassphraseNeeded);
 
     connect(qApp, &QGuiApplication::lastWindowClosed, this, &WindowManager::quitAfterLastWindow);
 
@@ -393,6 +395,25 @@ void WindowManager::onDeviceError(const QString &errorMessage) {
     qCritical() << Q_FUNC_INFO << errorMessage;
 }
 
+void WindowManager::onWalletPassphraseNeeded(bool on_device) {
+    auto button = QMessageBox::question(nullptr, "Wallet Passphrase Needed", "Enter passphrase on hardware wallet?\n\n"
+                                                                             "It is recommended to enter passphrase on "
+                                                                             "the hardware wallet for better security.",
+                                        QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
+    if (button == QMessageBox::Yes) {
+        m_walletManager->onPassphraseEntered("", true, false);
+        return;
+    }
+
+    bool ok;
+    QString passphrase = QInputDialog::getText(nullptr, "Wallet Passphrase Needed", "Enter passphrase:", QLineEdit::EchoMode::Password, "", &ok);
+    if (ok) {
+        m_walletManager->onPassphraseEntered(passphrase, false, false);
+    } else {
+        m_walletManager->onPassphraseEntered(passphrase, false, true);
+    }
+}
+
 // ######################## TRAY ########################
 
 void WindowManager::buildTrayMenu() {
index 1bf852fc1b8659c22b91a7ca5a823a905e273230..801d537d8917a10eae9a240e8441f5d4732a2aeb 100644 (file)
@@ -41,6 +41,7 @@ private slots:
     void onDeviceButtonRequest(quint64 code);
     void onDeviceButtonPressed();
     void onDeviceError(const QString &errorMessage);
+    void onWalletPassphraseNeeded(bool on_device);
 
 private:
     void tryCreateWallet(FeatherSeed seed, const QString &path, const QString &password, const QString &seedOffset);
index 0c1d655ac8b18831c7e5c65dff74b86587996f68..9c47dd854277d34473317833cd38c134eb3b3195 100644 (file)
@@ -9,40 +9,40 @@
 class WalletPassphraseListenerImpl : public  Monero::WalletListener, public PassphraseReceiver
 {
 public:
-    WalletPassphraseListenerImpl(WalletManager * mgr): m_mgr(mgr), m_phelper(mgr) {}
+    explicit WalletPassphraseListenerImpl(WalletManager * mgr): m_mgr(mgr), m_phelper(mgr) {}
 
-    virtual void moneySpent(const std::string &txId, uint64_t amount) override { (void)txId; (void)amount; };
-    virtual void moneyReceived(const std::string &txId, uint64_t amount) override { (void)txId; (void)amount; };
-    virtual void unconfirmedMoneyReceived(const std::string &txId, uint64_t amount) override { (void)txId; (void)amount; };
-    virtual void newBlock(uint64_t height) override { (void) height; };
-    virtual void updated() override {};
-    virtual void refreshed(bool success) override {};
+    void moneySpent(const std::string &txId, uint64_t amount) override { (void)txId; (void)amount; };
+    void moneyReceived(const std::string &txId, uint64_t amount) override { (void)txId; (void)amount; };
+    void unconfirmedMoneyReceived(const std::string &txId, uint64_t amount) override { (void)txId; (void)amount; };
+    void newBlock(uint64_t height) override { (void) height; };
+    void updated() override {};
+    void refreshed(bool success) override {};
 
-    virtual void onPassphraseEntered(const QString &passphrase, bool enter_on_device, bool entry_abort) override
+    void onPassphraseEntered(const QString &passphrase, bool enter_on_device, bool entry_abort) override
     {
         qDebug() << __FUNCTION__;
         m_phelper.onPassphraseEntered(passphrase, enter_on_device, entry_abort);
     }
 
-//    virtual Monero::optional<std::string> onDevicePassphraseRequest(bool & on_device) override
-//    {
-//        qDebug() << __FUNCTION__;
-//        return m_phelper.onDevicePassphraseRequest(on_device);
-//    }
-//
-    virtual void onDeviceButtonRequest(uint64_t code) override
+    Monero::optional<std::string> onDevicePassphraseRequest(bool & on_device) override
+    {
+        qDebug() << __FUNCTION__;
+        return m_phelper.onDevicePassphraseRequest(on_device);
+    }
+
+    void onDeviceButtonRequest(uint64_t code) override
     {
         qDebug() << __FUNCTION__;
         emit m_mgr->deviceButtonRequest(code);
     }
-//
-    virtual void onDeviceButtonPressed() override
+
+    void onDeviceButtonPressed() override
     {
         qDebug() << __FUNCTION__;
         emit m_mgr->deviceButtonPressed();
     }
 
-    virtual void onDeviceError(const std::string &message) override
+    void onDeviceError(const std::string &message) override
     {
         qDebug() << __FUNCTION__;
         emit m_mgr->deviceError(QString::fromStdString(message));