2020-10-12 22:01:06 +00:00
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
2024-01-01 17:07:58 +00:00
|
|
|
// SPDX-FileCopyrightText: 2020-2024 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 <QMessageBox>
|
|
|
|
|
2023-03-01 02:05:56 +00:00
|
|
|
#include "utils/Utils.h"
|
2023-12-07 11:09:23 +00:00
|
|
|
#include "WalletManager.h"
|
2023-12-11 22:52:44 +00:00
|
|
|
#include "qrcode/QrCode.h"
|
2023-12-30 14:45:54 +00:00
|
|
|
#include "dialog/PasswordSetDialog.h"
|
2023-12-11 22:52:44 +00:00
|
|
|
#include "dialog/QrCodeDialog.h"
|
2023-03-01 02:05:56 +00:00
|
|
|
|
|
|
|
ViewOnlyDialog::ViewOnlyDialog(Wallet *wallet, QWidget *parent)
|
2021-10-22 17:19:56 +00:00
|
|
|
: WindowModalDialog(parent)
|
2021-05-18 15:59:18 +00:00
|
|
|
, ui(new Ui::ViewOnlyDialog)
|
2023-03-01 02:05:56 +00:00
|
|
|
, m_wallet(wallet)
|
2020-10-12 22:01:06 +00:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
2023-03-01 02:05:56 +00:00
|
|
|
ui->label_restoreHeight->setText(QString::number(m_wallet->getWalletCreationHeight()));
|
|
|
|
ui->label_primaryAddress->setText(m_wallet->address(0, 0));
|
|
|
|
ui->label_secretViewKey->setText(m_wallet->getSecretViewKey());
|
2020-10-12 22:01:06 +00:00
|
|
|
|
2023-01-09 02:17:25 +00:00
|
|
|
connect(ui->btn_Copy, &QPushButton::clicked, this, &ViewOnlyDialog::copyToClipboard);
|
2020-10-12 22:01:06 +00:00
|
|
|
connect(ui->btn_Save, &QPushButton::clicked, this, &ViewOnlyDialog::onWriteViewOnlyWallet);
|
2023-12-05 21:06:48 +00:00
|
|
|
connect(ui->btn_transmitOverUR, &QPushButton::clicked, [this] {
|
2023-12-11 22:52:44 +00:00
|
|
|
QrCode qr(this->toJsonString(), QrCode::Version::AUTO, QrCode::ErrorCorrectionLevel::HIGH);
|
|
|
|
QrCodeDialog dialog{this, &qr, "View-Only details"};
|
2023-12-05 21:06:48 +00:00
|
|
|
dialog.exec();
|
|
|
|
});
|
2020-10-12 22:01:06 +00:00
|
|
|
|
2023-03-01 02:05:56 +00:00
|
|
|
if (m_wallet->viewOnly()) {
|
2021-08-14 15:02:03 +00:00
|
|
|
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(){
|
2023-12-30 14:49:51 +00:00
|
|
|
QDir walletDir = QDir(Utils::defaultWalletDir());
|
|
|
|
QString fn = QFileDialog::getSaveFileName(this, "Save .keys wallet file", walletDir.filePath(QString("%1_view_only").arg(m_wallet->walletName())), "Monero wallet (*.keys)");
|
2023-12-30 14:45:54 +00:00
|
|
|
if (fn.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!fn.endsWith(".keys")) {
|
|
|
|
fn += ".keys";
|
|
|
|
}
|
|
|
|
|
|
|
|
PasswordSetDialog dialog("Set a password for the view-only wallet", this);
|
|
|
|
dialog.exec();
|
|
|
|
QString password = dialog.password();
|
|
|
|
|
|
|
|
m_wallet->createViewOnly(fn, password);
|
2020-10-12 22:01:06 +00:00
|
|
|
|
|
|
|
QMessageBox::information(this, "Information", "View-only wallet successfully written to disk.");
|
|
|
|
}
|
|
|
|
|
2023-12-05 21:06:48 +00:00
|
|
|
QString ViewOnlyDialog::toString() {
|
|
|
|
QString text;
|
2020-10-12 22:01:06 +00:00
|
|
|
text += QString("Secret view key: %1\n").arg(ui->label_secretViewKey->text());
|
2023-12-05 21:06:48 +00:00
|
|
|
text += QString("Address: %1\n").arg(ui->label_primaryAddress->text());
|
2020-10-12 22:01:06 +00:00
|
|
|
text += QString("Restore height: %1\n").arg(ui->label_restoreHeight->text());
|
2023-12-05 21:06:48 +00:00
|
|
|
text += QString("Wallet name: %1\n").arg(m_wallet->walletName());
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
2023-12-11 22:52:44 +00:00
|
|
|
QString ViewOnlyDialog::toJsonString() {
|
|
|
|
QVariantMap data;
|
|
|
|
data["version"] = 0,
|
|
|
|
data["primaryAddress"] = m_wallet->address(0, 0);
|
|
|
|
data["privateViewKey"] = m_wallet->getSecretViewKey();
|
|
|
|
data["restoreHeight"] = m_wallet->getWalletCreationHeight();
|
|
|
|
data["walletName"] = m_wallet->walletName();
|
|
|
|
|
|
|
|
auto obj = QJsonDocument::fromVariant(data);
|
|
|
|
return obj.toJson(QJsonDocument::Compact);
|
|
|
|
}
|
|
|
|
|
2023-12-05 21:06:48 +00:00
|
|
|
void ViewOnlyDialog::copyToClipboard() {
|
|
|
|
Utils::copyToClipboard(this->toString());
|
2020-10-12 22:01:06 +00:00
|
|
|
}
|
|
|
|
|
2021-06-27 12:13:05 +00:00
|
|
|
ViewOnlyDialog::~ViewOnlyDialog() = default;
|