2020-10-07 10:36:04 +00:00
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
// Copyright (c) 2020, The Monero Project.
|
|
|
|
|
|
|
|
#include "utils/utils.h"
|
|
|
|
#include "wizard/walletwizard.h"
|
|
|
|
#include "wizard/menu.h"
|
|
|
|
#include "wizard/openwallet.h"
|
|
|
|
#include "wizard/createwallet.h"
|
|
|
|
#include "wizard/network.h"
|
|
|
|
#include "wizard/createwalletseed.h"
|
|
|
|
#include "wizard/restorewallet.h"
|
2020-10-12 22:01:06 +00:00
|
|
|
#include "wizard/viewonlywallet.h"
|
2020-10-07 10:36:04 +00:00
|
|
|
|
|
|
|
#include <QStyle>
|
|
|
|
#include <QLabel>
|
2020-10-12 22:01:06 +00:00
|
|
|
#include <QLineEdit>
|
2020-10-07 10:36:04 +00:00
|
|
|
#include <QVBoxLayout>
|
|
|
|
#include <QScreen>
|
|
|
|
#include <QApplication>
|
|
|
|
|
|
|
|
WalletWizard::WalletWizard(AppContext *ctx, WalletWizard::Page startPage, QWidget *parent) : QWizard(parent),
|
|
|
|
m_ctx(ctx) {
|
|
|
|
this->setWindowTitle("Welcome to feather");
|
|
|
|
this->setWindowIcon(QIcon(":/assets/images/appicons/64x64.png"));
|
2020-10-11 16:17:11 +00:00
|
|
|
auto openWalletPage = new OpenWalletPage(m_ctx, this);
|
|
|
|
auto createWallet = new CreateWalletPage(m_ctx, this);
|
|
|
|
auto createWalletSeed = new CreateWalletSeedPage(m_ctx, this);
|
|
|
|
setPage(Page_Menu, new MenuPage(m_ctx, this));
|
2020-10-07 10:36:04 +00:00
|
|
|
setPage(Page_CreateWallet, createWallet);
|
|
|
|
setPage(Page_OpenWallet, openWalletPage);
|
|
|
|
setPage(Page_CreateWalletSeed, createWalletSeed);
|
2020-10-11 16:17:11 +00:00
|
|
|
setPage(Page_Network, new NetworkPage(m_ctx, this));
|
|
|
|
setPage(Page_Restore, new RestorePage(m_ctx, this));
|
2020-10-12 22:01:06 +00:00
|
|
|
setPage(Page_ViewOnly, new ViewOnlyPage(m_ctx, this));
|
2020-10-07 10:36:04 +00:00
|
|
|
|
|
|
|
if(config()->get(Config::firstRun).toUInt())
|
|
|
|
setStartId(Page_Network);
|
|
|
|
else
|
|
|
|
setStartId(Page_Menu);
|
|
|
|
|
|
|
|
setPixmap(QWizard::WatermarkPixmap, QPixmap(":/assets/images/photos/1.png"));
|
|
|
|
setWizardStyle(WizardStyle::ModernStyle);
|
|
|
|
setOption(QWizard::NoBackButtonOnStartPage);
|
|
|
|
|
|
|
|
connect(this, &QWizard::rejected, [=]{
|
|
|
|
return QApplication::exit(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
connect(createWalletSeed, &CreateWalletSeedPage::createWallet, this, &WalletWizard::createWallet);
|
|
|
|
connect(createWallet, &CreateWalletPage::createWallet, this, &WalletWizard::createWallet);
|
|
|
|
|
|
|
|
connect(openWalletPage, &OpenWalletPage::openWallet, [=](const QString &path){
|
|
|
|
const auto walletPasswd = this->field("walletPasswd").toString();
|
|
|
|
emit openWallet(path, walletPasswd);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void WalletWizard::createWallet() {
|
2020-10-11 15:08:34 +00:00
|
|
|
auto mnemonicRestoredSeed = this->field("mnemonicRestoredSeed").toString();
|
|
|
|
auto mnemonicSeed = mnemonicRestoredSeed.isEmpty() ? this->field("mnemonicSeed").toString() : mnemonicRestoredSeed;
|
2020-10-07 10:36:04 +00:00
|
|
|
const auto walletPath = this->field("walletPath").toString();
|
|
|
|
const auto walletPasswd = this->field("walletPasswd").toString();
|
|
|
|
auto restoreHeight = this->field("restoreHeight").toUInt();
|
2020-10-12 22:01:06 +00:00
|
|
|
auto viewKey = this->field("viewOnlyViewKey").toString();
|
|
|
|
auto spendKey = this->field("viewOnlySpendKey").toString();
|
|
|
|
auto viewAddress = this->field("viewOnlyAddress").toString();
|
2020-10-07 10:36:04 +00:00
|
|
|
|
2020-10-12 22:01:06 +00:00
|
|
|
if(!viewKey.isEmpty() && !viewAddress.isEmpty()) {
|
|
|
|
auto viewHeight = this->field("viewOnlyHeight").toUInt();
|
|
|
|
m_ctx->createWalletViewOnly(walletPath,
|
|
|
|
walletPasswd,
|
|
|
|
viewAddress,
|
|
|
|
viewKey, spendKey, viewHeight);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto seed = FeatherSeed::fromSeed(m_ctx->restoreHeights[m_ctx->networkType], m_ctx->coinName.toStdString(), m_ctx->seedLanguage, mnemonicSeed.toStdString());
|
2020-10-07 10:36:04 +00:00
|
|
|
if(restoreHeight > 0)
|
|
|
|
seed.setRestoreHeight(restoreHeight);
|
|
|
|
m_ctx->createWallet(seed, walletPath, walletPasswd);
|
2020-10-12 22:01:06 +00:00
|
|
|
}
|