]> Nutra Git (v1) - gamesguru/feather.git/commitdiff
Seed: fix misc UI
authortobtoht <thotbot@protonmail.com>
Thu, 26 May 2022 18:30:39 +0000 (20:30 +0200)
committertobtoht <thotbot@protonmail.com>
Thu, 26 May 2022 18:30:39 +0000 (20:30 +0200)
src/MainWindow.cpp
src/WindowManager.cpp
src/appcontext.cpp
src/dialog/DebugInfoDialog.cpp
src/dialog/SeedDialog.cpp
src/dialog/WalletInfoDialog.cpp
src/libwalletqt/Wallet.cpp
src/libwalletqt/Wallet.h

index 13b724142b79bdbe595847a9d797b30a09765d43..7d7db041d34ac9f64fac2bbff540a3835aeb5c47 100644 (file)
@@ -788,9 +788,9 @@ void MainWindow::updatePasswordIcon() {
 
 void MainWindow::showRestoreHeightDialog() {
     // settings custom restore height is only available for 25 word seeds
-    auto seed = m_ctx->wallet->getCacheAttribute("feather.seed");
-    if(!seed.isEmpty()) { // TODO: update this warning (import tx, delete cache, restore from seed)
-        const auto msg = "This wallet has a 14 word mnemonic seed which has the restore height embedded.";
+    auto seedLength = m_ctx->wallet->seedLength();
+    if (seedLength == 14 || seedLength == 16) { // TODO: update this warning (import tx, delete cache, restore from seed)
+        const auto msg = "This wallet has a mnemonic seed with an embedded restore height.";
         QMessageBox::warning(this, "Cannot set custom restore height", msg);
         return;
     }
index cd0f6390840f13b7d6576c0378a7664e940ac9dd..414eb84df95fb60acb5519486b2be6d1b11bc604 100644 (file)
@@ -266,8 +266,6 @@ void WindowManager::tryCreateWallet(Seed seed, const QString &path, const QStrin
     Wallet *wallet = nullptr;
     if (seed.type == Seed::Type::POLYSEED || seed.type == Seed::Type::TEVADOR) {
         wallet = m_walletManager->createDeterministicWalletFromSpendKey(path, password, seed.language, constants::networkType, seed.spendKey, seed.restoreHeight, constants::kdfRounds, seedOffset);
-        wallet->setCacheAttribute("feather.seed", seed.mnemonic.join(" "));
-        wallet->setCacheAttribute("feather.seedoffset", seedOffset);
     }
     else if (seed.type == Seed::Type::MONERO) {
         wallet = m_walletManager->recoveryWallet(path, password, seed.mnemonic.join(" "), seedOffset, constants::networkType, seed.restoreHeight, constants::kdfRounds);
@@ -278,6 +276,9 @@ void WindowManager::tryCreateWallet(Seed seed, const QString &path, const QStrin
         return;
     }
 
+    wallet->setCacheAttribute("feather.seed", seed.mnemonic.join(" "));
+    wallet->setCacheAttribute("feather.seedoffset", seedOffset);
+
     this->onWalletOpened(wallet);
 }
 
index 523093492456826ed0ea39ca5f1098dad4327056..4149dce350255e91a2756631053bc6fbcff60dc0 100644 (file)
@@ -200,9 +200,9 @@ void AppContext::onTorSettingsChanged() {
 }
 
 void AppContext::onSetRestoreHeight(quint64 height){
-    auto seed = this->wallet->getCacheAttribute("feather.seed");
-    if(!seed.isEmpty()) {
-        const auto msg = "This wallet has a 14 word mnemonic seed which has the restore height embedded.";
+    auto seedLength = this->wallet->seedLength();
+    if (seedLength == 14 || seedLength == 16) {
+        const auto msg = "This wallet has a mnemonic seed with an embedded restore height.";
         emit setRestoreHeightError(msg);
         return;
     }
index 86a6b74c841decc5fe9c904d0dff5fabeb07608c..58b74688a84335bc550515b44176503be85944db 100644 (file)
@@ -67,11 +67,8 @@ void DebugInfoDialog::updateInfo() {
 
     QString seedType = [this](){
         if (m_ctx->wallet->isHwBacked())
-            return "Hardware";
-        if (m_ctx->wallet->getCacheAttribute("feather.seed").isEmpty())
-            return "25 word";
-        else
-            return "14 word";
+            return QString("Hardware");
+        return QString("%1 word").arg(m_ctx->wallet->seedLength());
     }();
 
     QString deviceType = [this](){
index 9d504121cd50bb0a9745a0c8952308cb4e7d5255..892c8ed36cf10007ff623f4b5dc73fb7bd8e6e69 100644 (file)
@@ -22,22 +22,24 @@ SeedDialog::SeedDialog(QSharedPointer<AppContext> ctx, QWidget *parent)
     }
 
     QString seedOffset = m_ctx->wallet->getCacheAttribute("feather.seedoffset");
-    QString seed_14_words = m_ctx->wallet->getCacheAttribute("feather.seed");
+    QString seed = m_ctx->wallet->getCacheAttribute("feather.seed");
+    auto seedLength = m_ctx->wallet->seedLength();
+
     QString seed_25_words = m_ctx->wallet->getSeed(seedOffset);
 
-    if (seed_14_words.isEmpty()) {
+    if (seedLength >= 24) {
         ui->check_toggleSeedType->hide();
         this->setSeed(seed_25_words);
     } else {
-        this->setSeed(seed_14_words);
+        this->setSeed(seed);
         ui->frameRestoreHeight->setVisible(false);
     }
 
     ui->frameSeedOffset->setVisible(!seedOffset.isEmpty());
     ui->line_seedOffset->setText(seedOffset);
 
-    connect(ui->check_toggleSeedType, &QCheckBox::toggled, [this, seed_25_words, seed_14_words](bool toggled){
-        this->setSeed(toggled ? seed_25_words : seed_14_words);
+    connect(ui->check_toggleSeedType, &QCheckBox::toggled, [this, seed_25_words, seed](bool toggled){
+        this->setSeed(toggled ? seed_25_words : seed);
         ui->frameRestoreHeight->setVisible(toggled);
     });
 
index 7826591c5e93b3c4c1c19aafeb2bd806022feb50..3724b61182dd54119f9867d930f44b261fde06e4 100644 (file)
@@ -17,7 +17,7 @@ WalletInfoDialog::WalletInfoDialog(QSharedPointer<AppContext> ctx, QWidget *pare
 
     ui->label_walletName->setText(QFileInfo(m_ctx->wallet->cachePath()).fileName());
     ui->label_netType->setText(Utils::QtEnumToString(m_ctx->wallet->nettype()));
-    ui->label_seedType->setText(m_ctx->wallet->getCacheAttribute("feather.seed").isEmpty() ? "25 word" : "14 word");
+    ui->label_seedType->setText(QString("%1 word").arg(m_ctx->wallet->seedLength()));
     ui->label_viewOnly->setText(m_ctx->wallet->viewOnly() ? "True" : "False");
     ui->label_keysFile->setText(m_ctx->wallet->keysPath());
     ui->label_cacheFile->setText(m_ctx->wallet->cachePath());
index e996fca955382837b357cb63b8fb21bdcd535c76..76bc09821541388a2603d115b100338ad9f2b630 100644 (file)
@@ -39,6 +39,12 @@ QString Wallet::getSeed(const QString &seedOffset) const
     return QString::fromStdString(m_walletImpl->seed(seedOffset.toStdString()));
 }
 
+qsizetype Wallet::seedLength() const
+{
+    auto seedLength = this->getCacheAttribute("feather.seed").split(" ").length();
+    return seedLength ? seedLength : 25;
+}
+
 QString Wallet::getSeedLanguage() const
 {
     return QString::fromStdString(m_walletImpl->getSeedLanguage());
index ed30083f1bd782067d305a978a943db78196c1a7..7ead7fa0b712349b3d3d2cfd71da04a80d026e8c 100644 (file)
@@ -106,6 +106,8 @@ public:
     //! returns mnemonic seed
     QString getSeed(const QString &seedOffset) const;
 
+    qsizetype seedLength() const;
+
     //! returns seed language
     QString getSeedLanguage() const;