SeedDialog: add 25 word seed toggle

This commit is contained in:
tobtoht 2020-11-11 23:09:35 +01:00
parent b66aceccc8
commit 0f3c005b60
4 changed files with 41 additions and 20 deletions

View file

@ -4,12 +4,30 @@
#include "ui_seeddialog.h" #include "ui_seeddialog.h"
#include "seeddialog.h" #include "seeddialog.h"
SeedDialog::SeedDialog(const QString &seed, QWidget *parent) SeedDialog::SeedDialog(Wallet *wallet, QWidget *parent)
: QDialog(parent) : QDialog(parent)
, ui(new Ui::SeedDialog) , ui(new Ui::SeedDialog)
{ {
ui->setupUi(this); ui->setupUi(this);
ui->label_seedIcon->setPixmap(QPixmap(":/assets/images/seed.png").scaledToWidth(64, Qt::SmoothTransformation)); ui->label_seedIcon->setPixmap(QPixmap(":/assets/images/seed.png").scaledToWidth(64, Qt::SmoothTransformation));
QString seed_14_words = wallet->getCacheAttribute("feather.seed");
QString seed_25_words = wallet->getSeed();
if (seed_14_words.isEmpty()) {
ui->check_toggleSeedType->hide();
this->setSeed(seed_25_words);
} else {
this->setSeed(seed_14_words);
connect(ui->check_toggleSeedType, &QCheckBox::toggled, [this, seed_25_words, seed_14_words](bool toggled){
this->setSeed(toggled ? seed_25_words : seed_14_words);
});
}
this->adjustSize();
}
void SeedDialog::setSeed(const QString &seed) {
ui->seed->setPlainText(seed); ui->seed->setPlainText(seed);
int words = seed.split(" ").size(); int words = seed.split(" ").size();
@ -23,8 +41,6 @@ SeedDialog::SeedDialog(const QString &seed, QWidget *parent)
"<li>Never type it on a website</li>" "<li>Never type it on a website</li>"
"<li>Do not store it electronically</li>" "<li>Do not store it electronically</li>"
"</ul>").arg(words)); "</ul>").arg(words));
this->adjustSize();
} }
SeedDialog::~SeedDialog() SeedDialog::~SeedDialog()

View file

@ -5,6 +5,7 @@
#define FEATHER_SEEDDIALOG_H #define FEATHER_SEEDDIALOG_H
#include <QDialog> #include <QDialog>
#include "libwalletqt/Wallet.h"
namespace Ui { namespace Ui {
class SeedDialog; class SeedDialog;
@ -15,10 +16,12 @@ class SeedDialog : public QDialog
Q_OBJECT Q_OBJECT
public: public:
explicit SeedDialog(const QString& seed, QWidget *parent = nullptr); explicit SeedDialog(Wallet *wallet, QWidget *parent = nullptr);
~SeedDialog() override; ~SeedDialog() override;
private: private:
void setSeed(const QString &seed);
Ui::SeedDialog *ui; Ui::SeedDialog *ui;
}; };

View file

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>542</width> <width>542</width>
<height>244</height> <height>259</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -57,6 +57,13 @@
</item> </item>
</layout> </layout>
</item> </item>
<item>
<widget class="QCheckBox" name="check_toggleSeedType">
<property name="text">
<string>Show 25 word seed</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QLabel" name="label_warning"> <widget class="QLabel" name="label_warning">
<property name="text"> <property name="text">

View file

@ -851,12 +851,7 @@ void MainWindow::showWalletInfoDialog() {
} }
void MainWindow::showSeedDialog() { void MainWindow::showSeedDialog() {
QString seed = m_ctx->currentWallet->getCacheAttribute("feather.seed"); auto *dialog = new SeedDialog(m_ctx->currentWallet, this);
if (seed.isEmpty()) {
seed = m_ctx->currentWallet->getSeed();
}
auto *dialog = new SeedDialog(seed, this);
dialog->exec(); dialog->exec();
dialog->deleteLater(); dialog->deleteLater();
} }