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>
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
2020-10-11 16:17:11 +00:00
|
|
|
ui->seed->setFont(Utils::relativeFont(1));
|
2020-10-07 10:36:04 +00:00
|
|
|
|
|
|
|
connect(ui->btnRoulette, &QPushButton::clicked, [=]{
|
|
|
|
this->seedRoulette(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
this->setButtonText(QWizard::FinishButton, "Create/Open wallet");
|
|
|
|
|
|
|
|
// generate new seed
|
|
|
|
this->seedRoulette(m_rouletteSpin - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CreateWalletSeedPage::seedRoulette(int count) {
|
|
|
|
count += 1;
|
|
|
|
if(count > m_rouletteSpin) return;
|
2021-01-20 21:13:51 +00:00
|
|
|
FeatherSeed seed = FeatherSeed(m_ctx->restoreHeights[m_ctx->networkType], m_ctx->coinName, m_ctx->seedLanguage);
|
|
|
|
m_mnemonic = seed.mnemonic.join(" ");
|
2020-10-07 10:36:04 +00:00
|
|
|
m_restoreHeight = seed.restoreHeight;
|
|
|
|
|
|
|
|
this->displaySeed(m_mnemonic);
|
|
|
|
QTimer::singleShot(10, [=] {
|
|
|
|
this->seedRoulette(count);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void CreateWalletSeedPage::displaySeed(const QString &seed){
|
2020-10-11 16:17:11 +00:00
|
|
|
ui->seed->setPlainText(seed);
|
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;
|
|
|
|
this->setField("mnemonicSeed", m_mnemonic);
|
|
|
|
this->setField("restoreHeight", m_restoreHeight);
|
|
|
|
emit createWallet();
|
|
|
|
return true;
|
|
|
|
}
|