2020-10-12 22:01:06 +00:00
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
2023-01-02 19:30:11 +00:00
|
|
|
// SPDX-FileCopyrightText: 2020-2023 The Monero Project
|
2020-10-12 22:01:06 +00:00
|
|
|
|
2021-06-27 14:33:18 +00:00
|
|
|
#include "ViewOnlyDialog.h"
|
|
|
|
#include "ui_ViewOnlyDialog.h"
|
|
|
|
|
2020-10-12 22:01:06 +00:00
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QInputDialog>
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
2021-05-18 15:59:18 +00:00
|
|
|
ViewOnlyDialog::ViewOnlyDialog(QSharedPointer<AppContext> ctx, QWidget *parent)
|
2021-10-22 17:19:56 +00:00
|
|
|
: WindowModalDialog(parent)
|
2021-05-18 15:59:18 +00:00
|
|
|
, ui(new Ui::ViewOnlyDialog)
|
|
|
|
, m_ctx(std::move(ctx))
|
2020-10-12 22:01:06 +00:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
2021-05-18 15:59:18 +00:00
|
|
|
ui->label_restoreHeight->setText(QString::number(m_ctx->wallet->getWalletCreationHeight()));
|
|
|
|
ui->label_primaryAddress->setText(m_ctx->wallet->address(0, 0));
|
|
|
|
ui->label_secretViewKey->setText(m_ctx->wallet->getSecretViewKey());
|
2020-10-12 22:01:06 +00:00
|
|
|
|
|
|
|
connect(ui->btn_Copy, &QPushButton::clicked, this, &ViewOnlyDialog::copyToClipboad);
|
|
|
|
connect(ui->btn_Save, &QPushButton::clicked, this, &ViewOnlyDialog::onWriteViewOnlyWallet);
|
|
|
|
|
2021-08-14 15:02:03 +00:00
|
|
|
if (m_ctx->wallet->viewOnly()) {
|
|
|
|
ui->btn_Save->setEnabled(false);
|
|
|
|
ui->btn_Save->setToolTip("Wallet is already view-only");
|
|
|
|
}
|
|
|
|
|
2020-10-12 22:01:06 +00:00
|
|
|
this->adjustSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ViewOnlyDialog::onWriteViewOnlyWallet(){
|
2021-03-14 21:12:02 +00:00
|
|
|
QString fn = QFileDialog::getSaveFileName(this, "Save .keys wallet file", Utils::defaultWalletDir(), "Monero wallet (*.keys)");
|
2020-10-12 22:01:06 +00:00
|
|
|
if(fn.isEmpty()) return;
|
|
|
|
if(!fn.endsWith(".keys")) fn += ".keys";
|
|
|
|
|
|
|
|
QString passwd;
|
|
|
|
QInputDialog passwordDialog(this);
|
|
|
|
passwordDialog.setInputMode(QInputDialog::TextInput);
|
|
|
|
passwordDialog.setTextEchoMode(QLineEdit::Password);
|
|
|
|
passwordDialog.setWindowTitle("View-Only wallet password");
|
|
|
|
passwordDialog.setLabelText("Protect this view-only wallet with a password?");
|
|
|
|
passwordDialog.resize(300, 100);
|
|
|
|
if((bool)passwordDialog.exec())
|
|
|
|
passwd = passwordDialog.textValue();
|
|
|
|
|
2021-05-18 15:59:18 +00:00
|
|
|
m_ctx->wallet->createViewOnly(fn, passwd);
|
2020-10-12 22:01:06 +00:00
|
|
|
|
|
|
|
QMessageBox::information(this, "Information", "View-only wallet successfully written to disk.");
|
|
|
|
}
|
|
|
|
|
|
|
|
void ViewOnlyDialog::copyToClipboad() {
|
|
|
|
QString text = "";
|
|
|
|
text += QString("Address: %1\n").arg(ui->label_primaryAddress->text());
|
|
|
|
text += QString("Secret view key: %1\n").arg(ui->label_secretViewKey->text());
|
|
|
|
text += QString("Restore height: %1\n").arg(ui->label_restoreHeight->text());
|
|
|
|
Utils::copyToClipboard(text);
|
|
|
|
}
|
|
|
|
|
2021-06-27 12:13:05 +00:00
|
|
|
ViewOnlyDialog::~ViewOnlyDialog() = default;
|