feather/src/wizard/PageWalletSeed.cpp

104 lines
3.3 KiB
C++
Raw Normal View History

// SPDX-License-Identifier: BSD-3-Clause
2020-12-26 19:56:06 +00:00
// Copyright (c) 2020-2021, The Monero Project.
2021-03-12 18:26:48 +00:00
#include "WalletWizard.h"
#include "PageWalletSeed.h"
#include "ui_PageWalletSeed.h"
2021-05-18 15:59:18 +00:00
#include "constants.h"
2021-01-20 22:10:12 +00:00
#include <QMessageBox>
2021-05-18 15:59:18 +00:00
PageWalletSeed::PageWalletSeed(WizardFields *fields, QWidget *parent)
2021-03-12 18:26:48 +00:00
: QWizardPage(parent)
, ui(new Ui::PageWalletSeed)
, m_fields(fields)
{
ui->setupUi(this);
2021-03-12 18:26:48 +00:00
QPixmap pixmap = QPixmap(":/assets/images/seed.png");
ui->seedIcon->setPixmap(pixmap.scaledToWidth(32, Qt::SmoothTransformation));
2021-01-20 22:10:12 +00:00
ui->seedWord2->setHelpText("In addition to the private spend key, Tevador's 14 word seed scheme also encodes the "
"restore date, cryptocurrency type, and reserves a few bits for future use. "
"The second word is static because the reserved bits remain the same for each seed generation.");
connect(ui->btnRoulette, &QPushButton::clicked, [=]{
this->seedRoulette(0);
});
2021-01-24 14:13:46 +00:00
connect(ui->btnCopy, &QPushButton::clicked, [this]{
Utils::copyToClipboard(m_mnemonic);
});
}
2021-03-12 18:26:48 +00:00
void PageWalletSeed::initializePage() {
2021-01-24 14:13:46 +00:00
this->generateSeed();
2021-03-12 18:26:48 +00:00
this->setTitle(m_fields->modeText);
}
2021-03-12 18:26:48 +00:00
void PageWalletSeed::seedRoulette(int count) {
count += 1;
2021-01-24 14:13:46 +00:00
if (count > m_rouletteSpin)
return;
this->generateSeed();
QTimer::singleShot(10, [=] {
this->seedRoulette(count);
});
}
2021-03-12 18:26:48 +00:00
void PageWalletSeed::generateSeed() {
do {
2021-05-18 15:59:18 +00:00
FeatherSeed seed = FeatherSeed(constants::networkType, QString::fromStdString(constants::coinName), constants::seedLanguage);
2021-03-12 18:26:48 +00:00
m_mnemonic = seed.mnemonic.join(" ");
m_restoreHeight = seed.restoreHeight;
} while (m_mnemonic.split(" ").length() != 14); // https://github.com/tevador/monero-seed/issues/2
2021-01-24 14:13:46 +00:00
this->displaySeed(m_mnemonic);
}
2021-03-12 18:26:48 +00:00
void PageWalletSeed::displaySeed(const QString &seed){
2021-01-20 22:10:12 +00:00
QStringList seedSplit = seed.split(" ");
ui->seedWord1->setText(seedSplit[0]);
ui->seedWord2->setText(seedSplit[1]);
ui->seedWord3->setText(seedSplit[2]);
ui->seedWord4->setText(seedSplit[3]);
ui->seedWord5->setText(seedSplit[4]);
ui->seedWord6->setText(seedSplit[5]);
ui->seedWord7->setText(seedSplit[6]);
ui->seedWord8->setText(seedSplit[7]);
ui->seedWord9->setText(seedSplit[8]);
ui->seedWord10->setText(seedSplit[9]);
ui->seedWord11->setText(seedSplit[10]);
ui->seedWord12->setText(seedSplit[11]);
ui->seedWord13->setText(seedSplit[12]);
ui->seedWord14->setText(seedSplit[13]);
}
2021-03-12 18:26:48 +00:00
int PageWalletSeed::nextId() const {
return WalletWizard::Page_WalletFile;
}
2021-03-12 18:26:48 +00:00
bool PageWalletSeed::validatePage() {
if (m_mnemonic.isEmpty()) return false;
if (!m_restoreHeight) return false;
2021-01-20 22:10:12 +00:00
QMessageBox seedWarning(this);
seedWarning.setWindowTitle("Warning!");
seedWarning.setText("• Never disclose your seed\n"
"• Never type it on a website\n"
"• Store it safely (offline)\n"
"• Do not lose your seed!");
2021-03-12 18:26:48 +00:00
seedWarning.addButton("Go back", QMessageBox::RejectRole);
2021-01-20 22:10:12 +00:00
seedWarning.addButton("I understand", QMessageBox::AcceptRole);
2021-03-12 18:26:48 +00:00
int res = seedWarning.exec();
if (res == QMessageBox::Rejected) {
return false;
}
m_fields->seed = m_mnemonic;
2021-01-20 22:10:12 +00:00
return true;
}