From 6633353bf3490c5109b359883d843e0981f3d2ea Mon Sep 17 00:00:00 2001 From: tobtoht Date: Thu, 26 May 2022 20:30:39 +0200 Subject: [PATCH] Seed: fix misc UI --- src/MainWindow.cpp | 6 +++--- src/WindowManager.cpp | 5 +++-- src/appcontext.cpp | 6 +++--- src/dialog/DebugInfoDialog.cpp | 7 ++----- src/dialog/SeedDialog.cpp | 12 +++++++----- src/dialog/WalletInfoDialog.cpp | 2 +- src/libwalletqt/Wallet.cpp | 6 ++++++ src/libwalletqt/Wallet.h | 2 ++ 8 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 13b72414..7d7db041 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -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; } diff --git a/src/WindowManager.cpp b/src/WindowManager.cpp index cd0f6390..414eb84d 100644 --- a/src/WindowManager.cpp +++ b/src/WindowManager.cpp @@ -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); } diff --git a/src/appcontext.cpp b/src/appcontext.cpp index 52309349..4149dce3 100644 --- a/src/appcontext.cpp +++ b/src/appcontext.cpp @@ -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; } diff --git a/src/dialog/DebugInfoDialog.cpp b/src/dialog/DebugInfoDialog.cpp index 86a6b74c..58b74688 100644 --- a/src/dialog/DebugInfoDialog.cpp +++ b/src/dialog/DebugInfoDialog.cpp @@ -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](){ diff --git a/src/dialog/SeedDialog.cpp b/src/dialog/SeedDialog.cpp index 9d504121..892c8ed3 100644 --- a/src/dialog/SeedDialog.cpp +++ b/src/dialog/SeedDialog.cpp @@ -22,22 +22,24 @@ SeedDialog::SeedDialog(QSharedPointer 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); }); diff --git a/src/dialog/WalletInfoDialog.cpp b/src/dialog/WalletInfoDialog.cpp index 7826591c..3724b611 100644 --- a/src/dialog/WalletInfoDialog.cpp +++ b/src/dialog/WalletInfoDialog.cpp @@ -17,7 +17,7 @@ WalletInfoDialog::WalletInfoDialog(QSharedPointer 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()); diff --git a/src/libwalletqt/Wallet.cpp b/src/libwalletqt/Wallet.cpp index e996fca9..76bc0982 100644 --- a/src/libwalletqt/Wallet.cpp +++ b/src/libwalletqt/Wallet.cpp @@ -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()); diff --git a/src/libwalletqt/Wallet.h b/src/libwalletqt/Wallet.h index ed30083f..7ead7fa0 100644 --- a/src/libwalletqt/Wallet.h +++ b/src/libwalletqt/Wallet.h @@ -106,6 +106,8 @@ public: //! returns mnemonic seed QString getSeed(const QString &seedOffset) const; + qsizetype seedLength() const; + //! returns seed language QString getSeedLanguage() const; -- 2.52.0