From a7a06d841366fada3907b124ce6d1d69250e9807 Mon Sep 17 00:00:00 2001 From: tobtoht Date: Tue, 24 Jan 2023 22:35:47 +0100 Subject: [PATCH] wizard: allow setting subaddress lookahead --- monero | 2 +- src/WindowManager.cpp | 12 ++--- src/WindowManager.h | 6 +-- src/dialog/WalletInfoDialog.cpp | 1 + src/dialog/WalletInfoDialog.ui | 26 +++++++--- src/libwalletqt/Wallet.cpp | 7 +++ src/libwalletqt/Wallet.h | 1 + src/libwalletqt/WalletManager.cpp | 11 ++-- src/libwalletqt/WalletManager.h | 9 ++-- src/wizard/PageHardwareDevice.cpp | 34 ++++++++++-- src/wizard/PageHardwareDevice.h | 2 + src/wizard/PageHardwareDevice.ui | 28 +++++++++- src/wizard/PageMenu.cpp | 2 + src/wizard/PageSetRestoreHeight.cpp | 10 +++- src/wizard/PageSetSeedPassphrase.cpp | 4 ++ src/wizard/PageSetSubaddressLookahead.cpp | 43 +++++++++++++++ ...eDevice.h => PageSetSubaddressLookahead.h} | 18 +++---- src/wizard/PageSetSubaddressLookahead.ui | 45 ++++++++++++++++ src/wizard/PageWalletRestoreKeys.cpp | 25 +++++++++ src/wizard/PageWalletRestoreKeys.h | 2 + src/wizard/PageWalletRestoreKeys.ui | 24 +++++++++ src/wizard/PageWalletRestoreSeed.cpp | 52 +++++++++++++++---- src/wizard/PageWalletRestoreSeed.h | 1 + src/wizard/PageWalletRestoreSeed.ui | 48 ++++++++--------- src/wizard/PageWalletSeed.cpp | 7 +-- src/wizard/PageWalletSeed.ui | 14 +---- src/wizard/WalletWizard.cpp | 12 +++-- src/wizard/WalletWizard.h | 30 ++++++++--- 28 files changed, 376 insertions(+), 100 deletions(-) create mode 100644 src/wizard/PageSetSubaddressLookahead.cpp copy src/wizard/{PageHardwareDevice.h => PageSetSubaddressLookahead.h} (50%) create mode 100644 src/wizard/PageSetSubaddressLookahead.ui diff --git a/monero b/monero index 7f9d4b9b..18bdad87 160000 --- a/monero +++ b/monero @@ -1 +1 @@ -Subproject commit 7f9d4b9b21d776551dd3809bfc4f9e11d7c7b933 +Subproject commit 18bdad879d9f25f35f065354aedf1236e6b0a60b diff --git a/src/WindowManager.cpp b/src/WindowManager.cpp index 1a088a90..ec0fda71 100644 --- a/src/WindowManager.cpp +++ b/src/WindowManager.cpp @@ -251,7 +251,7 @@ bool WindowManager::autoOpenWallet() { // ######################## WALLET CREATION ######################## void WindowManager::tryCreateWallet(Seed seed, const QString &path, const QString &password, const QString &seedLanguage, - const QString &seedOffset) { + const QString &seedOffset, const QString &subaddressLookahead) { if(Utils::fileExists(path)) { auto err = QString("Failed to write wallet to path: \"%1\"; file already exists.").arg(path); this->handleWalletError(err); @@ -265,7 +265,7 @@ 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 = m_walletManager->createDeterministicWalletFromSpendKey(path, password, seed.language, constants::networkType, seed.spendKey, seed.restoreHeight, constants::kdfRounds, seedOffset, subaddressLookahead); } else if (seed.type == Seed::Type::MONERO) { wallet = m_walletManager->recoveryWallet(path, password, seed.mnemonic.join(" "), seedOffset, constants::networkType, seed.restoreHeight, constants::kdfRounds); @@ -282,7 +282,7 @@ void WindowManager::tryCreateWallet(Seed seed, const QString &path, const QStrin this->onWalletOpened(wallet); } -void WindowManager::tryCreateWalletFromDevice(const QString &path, const QString &password, const QString &deviceName, int restoreHeight) +void WindowManager::tryCreateWalletFromDevice(const QString &path, const QString &password, const QString &deviceName, int restoreHeight, const QString &subaddressLookahead) { if (Utils::fileExists(path)) { auto err = QString("Failed to write wallet to path: \"%1\"; file already exists.").arg(path); @@ -291,11 +291,11 @@ void WindowManager::tryCreateWalletFromDevice(const QString &path, const QString } m_openingWallet = true; - m_walletManager->createWalletFromDeviceAsync(path, password, constants::networkType, deviceName, restoreHeight); + m_walletManager->createWalletFromDeviceAsync(path, password, constants::networkType, deviceName, restoreHeight, subaddressLookahead); } void WindowManager::tryCreateWalletFromKeys(const QString &path, const QString &password, const QString &address, - const QString &viewkey, const QString &spendkey, quint64 restoreHeight) { + const QString &viewkey, const QString &spendkey, quint64 restoreHeight, const QString &subaddressLookahead) { if (Utils::fileExists(path)) { auto err = QString("Failed to write wallet to path: \"%1\"; file already exists.").arg(path); this->handleWalletError(err); @@ -320,7 +320,7 @@ void WindowManager::tryCreateWalletFromKeys(const QString &path, const QString & return; } - Wallet *wallet = m_walletManager->createWalletFromKeys(path, password, constants::seedLanguage, constants::networkType, address, viewkey, spendkey, restoreHeight); + Wallet *wallet = m_walletManager->createWalletFromKeys(path, password, constants::seedLanguage, constants::networkType, address, viewkey, spendkey, restoreHeight, constants::kdfRounds, subaddressLookahead); m_openingWallet = true; m_walletManager->walletOpened(wallet); } diff --git a/src/WindowManager.h b/src/WindowManager.h index c73997e5..6df35db3 100644 --- a/src/WindowManager.h +++ b/src/WindowManager.h @@ -50,9 +50,9 @@ private slots: void onWalletPassphraseNeeded(bool on_device); private: - void tryCreateWallet(Seed seed, const QString &path, const QString &password, const QString &seedLanguage, const QString &seedOffset); - void tryCreateWalletFromDevice(const QString &path, const QString &password, const QString &deviceName, int restoreHeight); - void tryCreateWalletFromKeys(const QString &path, const QString &password, const QString &address, const QString &viewkey, const QString &spendkey, quint64 restoreHeight); + void tryCreateWallet(Seed seed, const QString &path, const QString &password, const QString &seedLanguage, const QString &seedOffset, const QString &subaddressLookahead); + void tryCreateWalletFromDevice(const QString &path, const QString &password, const QString &deviceName, int restoreHeight, const QString &subaddressLookahead); + void tryCreateWalletFromKeys(const QString &path, const QString &password, const QString &address, const QString &viewkey, const QString &spendkey, quint64 restoreHeight, const QString &subaddressLookahead); bool autoOpenWallet(); diff --git a/src/dialog/WalletInfoDialog.cpp b/src/dialog/WalletInfoDialog.cpp index 1f7339d4..f494f2aa 100644 --- a/src/dialog/WalletInfoDialog.cpp +++ b/src/dialog/WalletInfoDialog.cpp @@ -19,6 +19,7 @@ WalletInfoDialog::WalletInfoDialog(QSharedPointer ctx, QWidget *pare ui->label_netType->setText(Utils::QtEnumToString(m_ctx->wallet->nettype())); ui->label_seedType->setText(QString("%1 word").arg(m_ctx->wallet->seedLength())); ui->label_viewOnly->setText(m_ctx->wallet->viewOnly() ? "True" : "False"); + ui->label_subaddressLookahead->setText(m_ctx->wallet->getSubaddressLookahead()); ui->label_keysFile->setText(m_ctx->wallet->keysPath()); ui->label_cacheFile->setText(m_ctx->wallet->cachePath()); ui->label_cacheSize->setText(QString("%1 MB").arg(QString::number(cache.size() / 1e6, 'f', 2))); diff --git a/src/dialog/WalletInfoDialog.ui b/src/dialog/WalletInfoDialog.ui index aff675d3..4d18a89a 100644 --- a/src/dialog/WalletInfoDialog.ui +++ b/src/dialog/WalletInfoDialog.ui @@ -84,14 +84,14 @@ - + Keys file: - + TextLabel @@ -101,14 +101,14 @@ - + Cache size: - + TextLabel @@ -118,14 +118,14 @@ - + Cache file: - + TextLabel @@ -135,6 +135,20 @@ + + + + Lookahead: + + + + + + + TextLabel + + + diff --git a/src/libwalletqt/Wallet.cpp b/src/libwalletqt/Wallet.cpp index 935d0451..6ecccdfb 100644 --- a/src/libwalletqt/Wallet.cpp +++ b/src/libwalletqt/Wallet.cpp @@ -411,6 +411,13 @@ void Wallet::deviceShowAddressAsync(quint32 accountIndex, quint32 addressIndex, }); } +QString Wallet::getSubaddressLookahead() const +{ + auto lookahead = m_walletImpl->getSubaddressLookahead(); + + return QString("%1:%2").arg(QString::number(lookahead.first), QString::number(lookahead.second)); +} + bool Wallet::refreshHeights() { // daemonHeight and targetHeight will be 0 if call to get_info fails diff --git a/src/libwalletqt/Wallet.h b/src/libwalletqt/Wallet.h index d4c94c7d..e30b4e65 100644 --- a/src/libwalletqt/Wallet.h +++ b/src/libwalletqt/Wallet.h @@ -213,6 +213,7 @@ public: QString getSubaddressLabel(quint32 accountIndex, quint32 addressIndex) const; void setSubaddressLabel(quint32 accountIndex, quint32 addressIndex, const QString &label); void deviceShowAddressAsync(quint32 accountIndex, quint32 addressIndex, const QString &paymentId); + QString getSubaddressLookahead() const; //! hw-device backed wallets bool isHwBacked() const; diff --git a/src/libwalletqt/WalletManager.cpp b/src/libwalletqt/WalletManager.cpp index 7785dbe5..211f27a6 100644 --- a/src/libwalletqt/WalletManager.cpp +++ b/src/libwalletqt/WalletManager.cpp @@ -110,7 +110,7 @@ void WalletManager::openWalletAsync(const QString &path, const QString &password } -Wallet *WalletManager::recoveryWallet(const QString &path, const QString &password, const QString &seed, const QString &seed_offset, NetworkType::Type nettype, quint64 restoreHeight, quint64 kdfRounds) +Wallet *WalletManager::recoveryWallet(const QString &path, const QString &password, const QString &seed, const QString &seed_offset, NetworkType::Type nettype, quint64 restoreHeight, quint64 kdfRounds, const QString &subaddressLookahead) { QMutexLocker locker(&m_mutex); @@ -120,20 +120,21 @@ Wallet *WalletManager::recoveryWallet(const QString &path, const QString &passwo Wallet *WalletManager::createWalletFromKeys(const QString &path, const QString &password, const QString &language, NetworkType::Type nettype, const QString &address, const QString &viewkey, - const QString &spendkey, quint64 restoreHeight, quint64 kdfRounds) + const QString &spendkey, quint64 restoreHeight, quint64 kdfRounds, const QString &subaddressLookahead) { QMutexLocker locker(&m_mutex); Monero::Wallet * w = m_pimpl->createWalletFromKeys(path.toStdString(), password.toStdString(), language.toStdString(), static_cast(nettype), restoreHeight, - address.toStdString(), viewkey.toStdString(), spendkey.toStdString(), kdfRounds); + address.toStdString(), viewkey.toStdString(), spendkey.toStdString(), kdfRounds, subaddressLookahead.toStdString()); return new Wallet(w); } Wallet *WalletManager::createDeterministicWalletFromSpendKey(const QString &path, const QString &password, const QString &language, NetworkType::Type nettype, - const QString &spendkey, quint64 restoreHeight, quint64 kdfRounds, const QString &offset_passphrase) + const QString &spendkey, quint64 restoreHeight, quint64 kdfRounds, const QString &offset_passphrase, + const QString &subaddressLookahead) { QMutexLocker locker(&m_mutex); Monero::Wallet * w = m_pimpl->createDeterministicWalletFromSpendKey(path.toStdString(), password.toStdString(), language.toStdString(), static_cast(nettype), restoreHeight, - spendkey.toStdString(), kdfRounds, offset_passphrase.toStdString()); + spendkey.toStdString(), kdfRounds, offset_passphrase.toStdString(), subaddressLookahead.toStdString()); return new Wallet(w); } diff --git a/src/libwalletqt/WalletManager.h b/src/libwalletqt/WalletManager.h index 8b5fd07e..ea8216ae 100644 --- a/src/libwalletqt/WalletManager.h +++ b/src/libwalletqt/WalletManager.h @@ -44,7 +44,7 @@ public: void openWalletAsync(const QString &path, const QString &password, NetworkType::Type nettype = NetworkType::MAINNET, quint64 kdfRounds = 1, const QString &ringDatabasePath = ""); Wallet * recoveryWallet(const QString &path, const QString &password, const QString &seed, const QString &seed_offset, - NetworkType::Type nettype = NetworkType::MAINNET, quint64 restoreHeight = 0, quint64 kdfRounds = 1); + NetworkType::Type nettype = NetworkType::MAINNET, quint64 restoreHeight = 0, quint64 kdfRounds = 1, const QString &subaddressLookahead = ""); Wallet * createWalletFromKeys(const QString &path, const QString &password, @@ -54,7 +54,9 @@ public: const QString &viewkey, const QString &spendkey = "", quint64 restoreHeight = 0, - quint64 kdfRounds = 1); + quint64 kdfRounds = 1, + const QString &subaddressLookahead = "" + ); Wallet * createDeterministicWalletFromSpendKey(const QString &path, const QString &password, @@ -63,7 +65,8 @@ public: const QString &spendkey, quint64 restoreHeight, quint64 kdfRounds, - const QString &offset_passphrase = ""); + const QString &offset_passphrase = "", + const QString &subaddressLookahead = ""); Wallet * createWalletFromDevice(const QString &path, const QString &password, diff --git a/src/wizard/PageHardwareDevice.cpp b/src/wizard/PageHardwareDevice.cpp index a9f282e8..bec6de02 100644 --- a/src/wizard/PageHardwareDevice.cpp +++ b/src/wizard/PageHardwareDevice.cpp @@ -5,7 +5,10 @@ #include "ui_PageHardwareDevice.h" #include "WalletWizard.h" +#include +#include #include +#include PageHardwareDevice::PageHardwareDevice(WizardFields *fields, QWidget *parent) : QWizardPage(parent) @@ -16,6 +19,8 @@ PageHardwareDevice::PageHardwareDevice(WizardFields *fields, QWidget *parent) ui->combo_deviceType->addItem("Ledger Nano S (PLUS) / X", DeviceType::LEDGER); ui->combo_deviceType->addItem("Trezor Model T", DeviceType::TREZOR); + + connect(ui->btnOptions, &QPushButton::clicked, this, &PageHardwareDevice::onOptionsClicked); } void PageHardwareDevice::initializePage() { @@ -23,18 +28,39 @@ void PageHardwareDevice::initializePage() { } int PageHardwareDevice::nextId() const { - if (ui->radioNewWallet->isChecked()) - return WalletWizard::Page_WalletFile; - if (ui->radioRestoreWallet->isChecked()) + if (m_fields->showSetRestoreHeightPage) { return WalletWizard::Page_SetRestoreHeight; - return 0; + } + + return WalletWizard::Page_WalletFile; } bool PageHardwareDevice::validatePage() { m_fields->deviceType = static_cast(ui->combo_deviceType->currentData().toInt()); + m_fields->showSetRestoreHeightPage = ui->radioRestoreWallet->isChecked(); return true; } bool PageHardwareDevice::isComplete() const { return true; +} + +void PageHardwareDevice::onOptionsClicked() { + QDialog dialog(this); + dialog.setWindowTitle("Options"); + + QVBoxLayout layout; + QCheckBox check_subaddressLookahead("Set subaddress lookahead"); + check_subaddressLookahead.setChecked(m_fields->showSetSubaddressLookaheadPage); + + layout.addWidget(&check_subaddressLookahead); + QDialogButtonBox buttons(QDialogButtonBox::Ok); + layout.addWidget(&buttons); + dialog.setLayout(&layout); + connect(&buttons, &QDialogButtonBox::accepted, [&dialog]{ + dialog.close(); + }); + dialog.exec(); + + m_fields->showSetSubaddressLookaheadPage = check_subaddressLookahead.isChecked(); } \ No newline at end of file diff --git a/src/wizard/PageHardwareDevice.h b/src/wizard/PageHardwareDevice.h index d92df80b..0e0ba65f 100644 --- a/src/wizard/PageHardwareDevice.h +++ b/src/wizard/PageHardwareDevice.h @@ -28,6 +28,8 @@ public: bool isComplete() const override; private: + void onOptionsClicked(); + Ui::PageHardwareDevice *ui; WizardFields *m_fields; }; diff --git a/src/wizard/PageHardwareDevice.ui b/src/wizard/PageHardwareDevice.ui index 9d2cc951..a4f51f69 100644 --- a/src/wizard/PageHardwareDevice.ui +++ b/src/wizard/PageHardwareDevice.ui @@ -6,8 +6,8 @@ 0 0 - 558 - 431 + 968 + 630 @@ -118,6 +118,30 @@ + + + + + + Options + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + diff --git a/src/wizard/PageMenu.cpp b/src/wizard/PageMenu.cpp index 61bde471..45c9ee8b 100644 --- a/src/wizard/PageMenu.cpp +++ b/src/wizard/PageMenu.cpp @@ -49,6 +49,8 @@ int PageMenu::nextId() const { } bool PageMenu::validatePage() { + m_fields->clearFields(); + if (ui->radioCreate->isChecked()) { m_fields->mode = WizardMode::CreateWallet; m_fields->modeText = "Create wallet"; diff --git a/src/wizard/PageSetRestoreHeight.cpp b/src/wizard/PageSetRestoreHeight.cpp index 5ec276f7..25fd77be 100644 --- a/src/wizard/PageSetRestoreHeight.cpp +++ b/src/wizard/PageSetRestoreHeight.cpp @@ -46,7 +46,7 @@ void PageSetRestoreHeight::initializePage() { ui->frame_scanWarning->hide(); ui->frame_walletAgeWarning->hide(); - if (m_fields->seedCreationDateOverridden) { + if (m_fields->showSetRestoreHeightPage && m_fields->mode == WizardMode::RestoreFromSeed) { auto creationDate = QDateTime::fromSecsSinceEpoch(m_fields->seed.time); ui->line_creationDate->setText(creationDate.toString("yyyy-MM-dd")); this->onCreationDateEdited(); @@ -103,6 +103,14 @@ bool PageSetRestoreHeight::validatePage() { } int PageSetRestoreHeight::nextId() const { + if (m_fields->showSetSeedPassphrasePage) { + return WalletWizard::Page_SetSeedPassphrase; + } + + if (m_fields->showSetSubaddressLookaheadPage) { + return WalletWizard::Page_SetSubaddressLookahead; + } + return WalletWizard::Page_WalletFile; } diff --git a/src/wizard/PageSetSeedPassphrase.cpp b/src/wizard/PageSetSeedPassphrase.cpp index 5b08f5cd..cc595872 100644 --- a/src/wizard/PageSetSeedPassphrase.cpp +++ b/src/wizard/PageSetSeedPassphrase.cpp @@ -25,5 +25,9 @@ bool PageSetSeedPassphrase::validatePage() { } int PageSetSeedPassphrase::nextId() const { + if (m_fields->showSetSubaddressLookaheadPage) { + return WalletWizard::Page_SetSubaddressLookahead; + } + return WalletWizard::Page_WalletFile; } \ No newline at end of file diff --git a/src/wizard/PageSetSubaddressLookahead.cpp b/src/wizard/PageSetSubaddressLookahead.cpp new file mode 100644 index 00000000..1504d059 --- /dev/null +++ b/src/wizard/PageSetSubaddressLookahead.cpp @@ -0,0 +1,43 @@ +// SPDX-License-Identifier: BSD-3-Clause +// SPDX-FileCopyrightText: 2020-2023 The Monero Project + +#include "PageSetSubaddressLookahead.h" +#include "ui_PageSetSubaddressLookahead.h" +#include "WalletWizard.h" + +#include + +PageSetSubaddressLookahead::PageSetSubaddressLookahead(WizardFields *fields, QWidget *parent) + : QWizardPage(parent) + , ui(new Ui::PageSetSubaddressLookahead) + , m_fields(fields) +{ + ui->setupUi(this); + + // uint32_t can go up to 4294967294, but this isn't realistic + auto indexValidator = new QIntValidator(1, 2147483647, this); + + ui->line_major->setValidator(indexValidator); + ui->line_minor->setValidator(indexValidator); + + this->setTitle("Subaddress Lookahead"); +} + +void PageSetSubaddressLookahead::initializePage() { + if (m_fields->mode == WizardMode::CreateWalletFromDevice) { + ui->line_major->setText("5"); + ui->line_minor->setText("20"); + } else { + ui->line_major->setText("50"); + ui->line_minor->setText("200"); + } +} + +bool PageSetSubaddressLookahead::validatePage() { + m_fields->subaddressLookahead = QString("%1:%2").arg(ui->line_major->text(), ui->line_minor->text()); + return true; +} + +int PageSetSubaddressLookahead::nextId() const { + return WalletWizard::Page_WalletFile; +} \ No newline at end of file diff --git a/src/wizard/PageHardwareDevice.h b/src/wizard/PageSetSubaddressLookahead.h similarity index 50% copy from src/wizard/PageHardwareDevice.h copy to src/wizard/PageSetSubaddressLookahead.h index d92df80b..ae26f082 100644 --- a/src/wizard/PageHardwareDevice.h +++ b/src/wizard/PageSetSubaddressLookahead.h @@ -1,36 +1,34 @@ // SPDX-License-Identifier: BSD-3-Clause // SPDX-FileCopyrightText: 2020-2023 The Monero Project -#ifndef FEATHER_PAGEHARDWAREDEVICE_H -#define FEATHER_PAGEHARDWAREDEVICE_H +#ifndef FEATHER_PAGESETSUBADDRESSLOOKAHEAD_H +#define FEATHER_PAGESETSUBADDRESSLOOKAHEAD_H -#include #include #include -#include #include "appcontext.h" #include "WalletWizard.h" namespace Ui { - class PageHardwareDevice; + class PageSetSubaddressLookahead; } -class PageHardwareDevice : public QWizardPage +class PageSetSubaddressLookahead : public QWizardPage { Q_OBJECT public: - explicit PageHardwareDevice(WizardFields *fields, QWidget *parent = nullptr); + explicit PageSetSubaddressLookahead(WizardFields *fields, QWidget *parent = nullptr); void initializePage() override; bool validatePage() override; int nextId() const override; - bool isComplete() const override; private: - Ui::PageHardwareDevice *ui; + Ui::PageSetSubaddressLookahead *ui; + WizardFields *m_fields; }; -#endif //FEATHER_PAGEHARDWAREDEVICE_H +#endif //FEATHER_PAGESETSUBADDRESSLOOKAHEAD_H diff --git a/src/wizard/PageSetSubaddressLookahead.ui b/src/wizard/PageSetSubaddressLookahead.ui new file mode 100644 index 00000000..6fd4d8f4 --- /dev/null +++ b/src/wizard/PageSetSubaddressLookahead.ui @@ -0,0 +1,45 @@ + + + PageSetSubaddressLookahead + + + + 0 + 0 + 568 + 341 + + + + WizardPage + + + + + + + + Major (account) + + + + + + + Minor (subaddress) + + + + + + + + + + + + + + + + diff --git a/src/wizard/PageWalletRestoreKeys.cpp b/src/wizard/PageWalletRestoreKeys.cpp index df1c8397..34bdbd40 100644 --- a/src/wizard/PageWalletRestoreKeys.cpp +++ b/src/wizard/PageWalletRestoreKeys.cpp @@ -4,7 +4,10 @@ #include "PageWalletRestoreKeys.h" #include "ui_PageWalletRestoreKeys.h" +#include +#include #include +#include #include "WalletWizard.h" #include "constants.h" @@ -31,6 +34,8 @@ PageWalletRestoreKeys::PageWalletRestoreKeys(WizardFields *fields, QWidget *pare } else if (constants::networkType == NetworkType::Type::STAGENET) { ui->line_address->setPlaceholderText("5..."); } + + connect(ui->btnOptions, &QPushButton::clicked, this, &PageWalletRestoreKeys::onOptionsClicked); } void PageWalletRestoreKeys::initializePage() { @@ -80,3 +85,23 @@ bool PageWalletRestoreKeys::validatePage() { m_fields->secretSpendKey = spendkey; return true; } + +void PageWalletRestoreKeys::onOptionsClicked() { + QDialog dialog(this); + dialog.setWindowTitle("Options"); + + QVBoxLayout layout; + QCheckBox check_subaddressLookahead("Set subaddress lookahead"); + check_subaddressLookahead.setChecked(m_fields->showSetSubaddressLookaheadPage); + + layout.addWidget(&check_subaddressLookahead); + QDialogButtonBox buttons(QDialogButtonBox::Ok); + layout.addWidget(&buttons); + dialog.setLayout(&layout); + connect(&buttons, &QDialogButtonBox::accepted, [&dialog]{ + dialog.close(); + }); + dialog.exec(); + + m_fields->showSetSubaddressLookaheadPage = check_subaddressLookahead.isChecked(); +} \ No newline at end of file diff --git a/src/wizard/PageWalletRestoreKeys.h b/src/wizard/PageWalletRestoreKeys.h index 19ac3c0f..36febe11 100644 --- a/src/wizard/PageWalletRestoreKeys.h +++ b/src/wizard/PageWalletRestoreKeys.h @@ -28,6 +28,8 @@ public: int nextId() const override; private: + void onOptionsClicked(); + Ui::PageWalletRestoreKeys *ui; WizardFields *m_fields; }; diff --git a/src/wizard/PageWalletRestoreKeys.ui b/src/wizard/PageWalletRestoreKeys.ui index b321cb34..90227c1e 100644 --- a/src/wizard/PageWalletRestoreKeys.ui +++ b/src/wizard/PageWalletRestoreKeys.ui @@ -217,6 +217,30 @@ + + + + + + Options + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + diff --git a/src/wizard/PageWalletRestoreSeed.cpp b/src/wizard/PageWalletRestoreSeed.cpp index 9c123d3a..83f4b3e4 100644 --- a/src/wizard/PageWalletRestoreSeed.cpp +++ b/src/wizard/PageWalletRestoreSeed.cpp @@ -5,7 +5,10 @@ #include "PageWalletRestoreSeed.h" #include "ui_PageWalletRestoreSeed.h" +#include +#include #include +#include #include #include // tevador 14 word @@ -57,6 +60,7 @@ PageWalletRestoreSeed::PageWalletRestoreSeed(WizardFields *fields, QWidget *pare connect(ui->seedBtnGroup, QOverload::of(&QButtonGroup::buttonClicked), this, &PageWalletRestoreSeed::onSeedTypeToggled); connect(ui->combo_seedLanguage, &QComboBox::currentTextChanged, this, &PageWalletRestoreSeed::onSeedLanguageChanged); + connect(ui->btnOptions, &QPushButton::clicked, this, &PageWalletRestoreSeed::onOptionsClicked); } @@ -66,21 +70,18 @@ void PageWalletRestoreSeed::onSeedTypeToggled() { m_fields->seedType = Seed::Type::POLYSEED; ui->seedEdit->setPlaceholderText("Enter 16 word seed.."); ui->group_seedLanguage->hide(); - ui->check_overrideCreationDate->setVisible(true); } if (ui->radio14->isChecked()) { m_mode = &m_tevador; m_fields->seedType = Seed::Type::TEVADOR; ui->seedEdit->setPlaceholderText("Enter 14 word seed.."); ui->group_seedLanguage->hide(); - ui->check_overrideCreationDate->setVisible(true); } else if (ui->radio25->isChecked()) { m_mode = &m_legacy; m_fields->seedType = Seed::Type::MONERO; ui->seedEdit->setPlaceholderText("Enter 25 word seed.."); ui->group_seedLanguage->show(); - ui->check_overrideCreationDate->setVisible(false); } ui->label_errorString->hide(); @@ -95,10 +96,18 @@ void PageWalletRestoreSeed::onSeedLanguageChanged(const QString &language) { } int PageWalletRestoreSeed::nextId() const { - if (m_mode == &m_legacy || ui->check_overrideCreationDate->isChecked()) { + if (m_mode == &m_legacy || m_fields->showSetRestoreHeightPage) { return WalletWizard::Page_SetRestoreHeight; } + if (m_fields->showSetSeedPassphrasePage) { + return WalletWizard::Page_SetSeedPassphrase; + } + + if (m_fields->showSetSubaddressLookaheadPage) { + return WalletWizard::Page_SetSubaddressLookahead; + } + return WalletWizard::Page_WalletFile; } @@ -107,9 +116,6 @@ void PageWalletRestoreSeed::initializePage() { ui->seedEdit->setText(""); ui->seedEdit->setStyleSheet(""); ui->label_errorString->hide(); - ui->line_seedOffset->setText(""); - ui->check_overrideCreationDate->setVisible(false); - ui->check_overrideCreationDate->setChecked(false); ui->radio16->isChecked(); this->onSeedTypeToggled(); } @@ -161,8 +167,36 @@ bool PageWalletRestoreSeed::validatePage() { } m_fields->seed = _seed; - m_fields->seedOffsetPassphrase = ui->line_seedOffset->text(); - m_fields->seedCreationDateOverridden = ui->check_overrideCreationDate->isChecked(); return true; } + +void PageWalletRestoreSeed::onOptionsClicked() { + QDialog dialog(this); + dialog.setWindowTitle("Options"); + + QVBoxLayout layout; + QCheckBox check_overrideCreationDate("Override embedded wallet creation date"); + check_overrideCreationDate.setChecked(m_fields->showSetRestoreHeightPage); + + QCheckBox check_setSeedPasshprase("Extend this seed with a passphrase"); + check_setSeedPasshprase.setChecked(m_fields->showSetSeedPassphrasePage); + + QCheckBox check_subaddressLookahead("Set subaddress lookahead"); + check_subaddressLookahead.setChecked(m_fields->showSetSubaddressLookaheadPage); + + layout.addWidget(&check_overrideCreationDate); + layout.addWidget(&check_setSeedPasshprase); + layout.addWidget(&check_subaddressLookahead); + QDialogButtonBox buttons(QDialogButtonBox::Ok); + layout.addWidget(&buttons); + dialog.setLayout(&layout); + connect(&buttons, &QDialogButtonBox::accepted, [&dialog]{ + dialog.close(); + }); + dialog.exec(); + + m_fields->showSetRestoreHeightPage = check_overrideCreationDate.isChecked(); + m_fields->showSetSeedPassphrasePage = check_setSeedPasshprase.isChecked(); + m_fields->showSetSubaddressLookaheadPage = check_subaddressLookahead.isChecked(); +} \ No newline at end of file diff --git a/src/wizard/PageWalletRestoreSeed.h b/src/wizard/PageWalletRestoreSeed.h index fac22296..2aa4c00f 100644 --- a/src/wizard/PageWalletRestoreSeed.h +++ b/src/wizard/PageWalletRestoreSeed.h @@ -50,6 +50,7 @@ private: void onSeedTypeToggled(); void onSeedLanguageChanged(const QString &language); + void onOptionsClicked(); Ui::PageWalletRestoreSeed *ui; WizardFields *m_fields; diff --git a/src/wizard/PageWalletRestoreSeed.ui b/src/wizard/PageWalletRestoreSeed.ui index 3a82f7fc..0efe960f 100644 --- a/src/wizard/PageWalletRestoreSeed.ui +++ b/src/wizard/PageWalletRestoreSeed.ui @@ -94,30 +94,6 @@ - - - - Seed offset passphrase: - - - - - - - QLineEdit::Normal - - - Leave blank if in doubt - - - - - - - Override embedded wallet creation date - - - @@ -138,6 +114,30 @@ + + + + + + Options + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + diff --git a/src/wizard/PageWalletSeed.cpp b/src/wizard/PageWalletSeed.cpp index 0044ed03..18e7693a 100644 --- a/src/wizard/PageWalletSeed.cpp +++ b/src/wizard/PageWalletSeed.cpp @@ -94,9 +94,10 @@ void PageWalletSeed::displaySeed(const QString &seed){ void PageWalletSeed::onOptionsClicked() { QDialog dialog(this); + dialog.setWindowTitle("Options"); QVBoxLayout layout; QCheckBox checkbox("Extend this seed with a passphrase"); - checkbox.setChecked(m_fields->seedOffsetPassphraseEnabled); + checkbox.setChecked(m_fields->showSetSeedPassphrasePage); layout.addWidget(&checkbox); QDialogButtonBox buttons(QDialogButtonBox::Ok); layout.addWidget(&buttons); @@ -105,11 +106,11 @@ void PageWalletSeed::onOptionsClicked() { dialog.close(); }); dialog.exec(); - m_fields->seedOffsetPassphraseEnabled = checkbox.isChecked(); + m_fields->showSetSeedPassphrasePage = checkbox.isChecked(); } int PageWalletSeed::nextId() const { - if (m_fields->seedOffsetPassphraseEnabled) { + if (m_fields->showSetSeedPassphrasePage) { return WalletWizard::Page_SetSeedPassphrase; } return WalletWizard::Page_WalletFile; diff --git a/src/wizard/PageWalletSeed.ui b/src/wizard/PageWalletSeed.ui index 99e4512f..a0750b64 100644 --- a/src/wizard/PageWalletSeed.ui +++ b/src/wizard/PageWalletSeed.ui @@ -122,17 +122,7 @@ - <html><head/><body><p>Feather recently switched to a new seed scheme called <span style=" font-weight:600;">Polyseed</span>.</p></body></html> - - - true - - - - - - - For more information visit: docs.featherwallet.org/guides/seed-scheme + <html><head/><body><p>Feather uses <span style=" font-weight:600;">Polyseed</span>. For more information visit: docs.featherwallet.org/guides/seed-scheme</p></body></html> true @@ -935,7 +925,7 @@ Qt::NoFocus - Generate + Generate new diff --git a/src/wizard/WalletWizard.cpp b/src/wizard/WalletWizard.cpp index 250437c9..91e68935 100644 --- a/src/wizard/WalletWizard.cpp +++ b/src/wizard/WalletWizard.cpp @@ -14,6 +14,7 @@ #include "PageSetPassword.h" #include "PageSetRestoreHeight.h" #include "PageSetSeedPassphrase.h" +#include "PageSetSubaddressLookahead.h" #include "PageHardwareDevice.h" #include "PageNetworkTor.h" #include "PageNetworkWebsocket.h" @@ -41,6 +42,7 @@ WalletWizard::WalletWizard(QWidget *parent) auto createWalletSeed = new PageWalletSeed(&m_wizardFields, this); auto walletSetPasswordPage = new PageSetPassword(&m_wizardFields, this); auto walletSetSeedPassphrasePage = new PageSetSeedPassphrase(&m_wizardFields, this); + auto walletSetSubaddressLookaheadPage = new PageSetSubaddressLookahead(&m_wizardFields, this); setPage(Page_Menu, menuPage); setPage(Page_WalletFile, createWallet); setPage(Page_OpenWallet, openWalletPage); @@ -54,6 +56,7 @@ WalletWizard::WalletWizard(QWidget *parent) setPage(Page_SetRestoreHeight, new PageSetRestoreHeight(&m_wizardFields, this)); setPage(Page_HardwareDevice, new PageHardwareDevice(&m_wizardFields, this)); setPage(Page_SetSeedPassphrase, walletSetSeedPassphrasePage); + setPage(Page_SetSubaddressLookahead, walletSetSubaddressLookaheadPage); setStartId(Page_Menu); @@ -112,7 +115,7 @@ void WalletWizard::onCreateWallet() { deviceName = "Trezor"; } - emit createWalletFromDevice(walletPath, m_wizardFields.password, deviceName, restoreHeight); + emit createWalletFromDevice(walletPath, m_wizardFields.password, deviceName, restoreHeight, m_wizardFields.subaddressLookahead); return; } @@ -122,7 +125,8 @@ void WalletWizard::onCreateWallet() { m_wizardFields.address, m_wizardFields.secretViewKey, m_wizardFields.secretSpendKey, - m_wizardFields.restoreHeight); + m_wizardFields.restoreHeight, + m_wizardFields.subaddressLookahead); return; } @@ -132,9 +136,9 @@ void WalletWizard::onCreateWallet() { m_wizardFields.seed.restoreHeight = currentBlockHeight; } - if (m_wizardFields.mode == WizardMode::RestoreFromSeed && (m_wizardFields.seedType == Seed::Type::MONERO || m_wizardFields.seedCreationDateOverridden)) { + if (m_wizardFields.mode == WizardMode::RestoreFromSeed && (m_wizardFields.seedType == Seed::Type::MONERO || m_wizardFields.showSetRestoreHeightPage)) { m_wizardFields.seed.setRestoreHeight(m_wizardFields.restoreHeight); } - emit createWallet(m_wizardFields.seed, walletPath, m_wizardFields.password, m_wizardFields.seedLanguage, m_wizardFields.seedOffsetPassphrase); + emit createWallet(m_wizardFields.seed, walletPath, m_wizardFields.password, m_wizardFields.seedLanguage, m_wizardFields.seedOffsetPassphrase, m_wizardFields.subaddressLookahead); } \ No newline at end of file diff --git a/src/wizard/WalletWizard.h b/src/wizard/WalletWizard.h index 5a88f08a..04d31a6d 100644 --- a/src/wizard/WalletWizard.h +++ b/src/wizard/WalletWizard.h @@ -31,8 +31,9 @@ struct WizardFields { QString walletName; QString walletDir; Seed seed; - bool seedOffsetPassphraseEnabled = false; - bool seedCreationDateOverridden = false; + bool showSetSeedPassphrasePage = false; + bool showSetRestoreHeightPage = false; + bool showSetSubaddressLookaheadPage = false; QString seedOffsetPassphrase; QString seedLanguage = constants::seedLanguage; QString password; @@ -44,9 +45,23 @@ struct WizardFields { int restoreHeight = 0; Seed::Type seedType; DeviceType deviceType; + QString subaddressLookahead; + + void clearFields() { + showSetSeedPassphrasePage = false; + showSetRestoreHeightPage = false; + showSetSubaddressLookaheadPage = false; + seedOffsetPassphrase = ""; + password = ""; + address = ""; + secretViewKey = ""; + secretSpendKey = ""; + restoreHeight = 0; + subaddressLookahead = ""; + } WizardFields(): deviceType(DeviceType::LEDGER), mode(WizardMode::CreateWallet), - seedType(Seed::POLYSEED), seedOffsetPassphraseEnabled(false), restoreHeight(0) {} + seedType(Seed::POLYSEED), restoreHeight(0) {} }; class WalletWizard : public QWizard @@ -55,11 +70,12 @@ class WalletWizard : public QWizard public: enum Page { - Page_Menu, + Page_Menu = 0, Page_WalletFile, Page_CreateWalletSeed, Page_SetSeedPassphrase, Page_SetPasswordPage, + Page_SetSubaddressLookahead, Page_OpenWallet, Page_Network, Page_WalletRestoreSeed, @@ -79,9 +95,9 @@ signals: void openWallet(QString path, QString password); void defaultWalletDirChanged(QString walletDir); - void createWalletFromDevice(const QString &path, const QString &password, const QString &deviceName, int restoreHeight); - void createWalletFromKeys(const QString &path, const QString &password, const QString &address, const QString &viewkey, const QString &spendkey, quint64 restoreHeight, bool deterministic = false); - void createWallet(Seed seed, const QString &path, const QString &password, const QString &seedLanguage, const QString &seedOffset = ""); + void createWalletFromDevice(const QString &path, const QString &password, const QString &deviceName, int restoreHeight, const QString &subaddressLookahead); + void createWalletFromKeys(const QString &path, const QString &password, const QString &address, const QString &viewkey, const QString &spendkey, quint64 restoreHeight, const QString subaddressLookahead = ""); + void createWallet(Seed seed, const QString &path, const QString &password, const QString &seedLanguage, const QString &seedOffset = "", const QString &subaddressLookahead = ""); private slots: void onCreateWallet(); -- 2.52.0