2020-10-07 10:36:04 +00:00
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
2020-12-26 19:56:06 +00:00
|
|
|
// Copyright (c) 2020-2021, The Monero Project.
|
2020-10-07 10:36:04 +00:00
|
|
|
|
|
|
|
#include "wizard/createwalletseed.h"
|
|
|
|
#include "wizard/walletwizard.h"
|
|
|
|
#include "ui_createwalletseed.h"
|
|
|
|
|
|
|
|
#include <QFileDialog>
|
2021-01-20 22:10:12 +00:00
|
|
|
#include <QMessageBox>
|
2020-10-07 10:36:04 +00:00
|
|
|
|
|
|
|
CreateWalletSeedPage::CreateWalletSeedPage(AppContext *ctx, QWidget *parent) :
|
|
|
|
QWizardPage(parent),
|
|
|
|
m_ctx(ctx),
|
|
|
|
ui(new Ui::CreateWalletSeedPage) {
|
|
|
|
ui->setupUi(this);
|
|
|
|
this->setFinalPage(true);
|
|
|
|
this->setTitle("Wallet seed");
|
|
|
|
|
|
|
|
// hide ui element, we only need it for registerField
|
|
|
|
this->registerField("mnemonicSeed", ui->hiddenMnemonicSeed);
|
|
|
|
ui->hiddenMnemonicSeed->hide();
|
|
|
|
|
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.");
|
2020-10-07 10:36:04 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
2020-10-07 10:36:04 +00:00
|
|
|
|
|
|
|
this->setButtonText(QWizard::FinishButton, "Create/Open wallet");
|
2021-01-24 14:13:46 +00:00
|
|
|
}
|
2020-10-07 10:36:04 +00:00
|
|
|
|
2021-01-24 14:13:46 +00:00
|
|
|
void CreateWalletSeedPage::initializePage() {
|
|
|
|
this->generateSeed();
|
2020-10-07 10:36:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CreateWalletSeedPage::seedRoulette(int count) {
|
|
|
|
count += 1;
|
2021-01-24 14:13:46 +00:00
|
|
|
if (count > m_rouletteSpin)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this->generateSeed();
|
2020-10-07 10:36:04 +00:00
|
|
|
|
|
|
|
QTimer::singleShot(10, [=] {
|
|
|
|
this->seedRoulette(count);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-01-24 14:13:46 +00:00
|
|
|
void CreateWalletSeedPage::generateSeed() {
|
|
|
|
FeatherSeed seed = FeatherSeed(m_ctx->restoreHeights[m_ctx->networkType], m_ctx->coinName, m_ctx->seedLanguage);
|
|
|
|
m_mnemonic = seed.mnemonic.join(" ");
|
|
|
|
m_restoreHeight = seed.restoreHeight;
|
|
|
|
this->displaySeed(m_mnemonic);
|
|
|
|
}
|
|
|
|
|
2020-10-07 10:36:04 +00:00
|
|
|
void CreateWalletSeedPage::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]);
|
2020-10-07 10:36:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int CreateWalletSeedPage::nextId() const {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CreateWalletSeedPage::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!");
|
|
|
|
seedWarning.addButton("I understand", QMessageBox::AcceptRole);
|
|
|
|
seedWarning.exec();
|
|
|
|
|
2020-10-07 10:36:04 +00:00
|
|
|
this->setField("mnemonicSeed", m_mnemonic);
|
|
|
|
this->setField("restoreHeight", m_restoreHeight);
|
|
|
|
emit createWallet();
|
|
|
|
return true;
|
|
|
|
}
|