2020-10-07 10:36:04 +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-07 10:36:04 +00:00
|
|
|
|
2021-06-27 11:46:32 +00:00
|
|
|
#include "TxConfDialog.h"
|
|
|
|
#include "ui_TxConfDialog.h"
|
|
|
|
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
2021-06-27 14:33:18 +00:00
|
|
|
#include "constants.h"
|
2021-06-27 11:46:32 +00:00
|
|
|
#include "TxConfAdvDialog.h"
|
2021-05-02 18:22:38 +00:00
|
|
|
#include "utils/AppData.h"
|
2021-01-28 22:48:14 +00:00
|
|
|
#include "utils/ColorScheme.h"
|
2023-03-01 02:05:56 +00:00
|
|
|
#include "utils/config.h"
|
2023-03-28 20:42:12 +00:00
|
|
|
#include "utils/Utils.h"
|
2020-10-07 10:36:04 +00:00
|
|
|
|
2023-03-01 02:05:56 +00:00
|
|
|
TxConfDialog::TxConfDialog(Wallet *wallet, PendingTransaction *tx, const QString &address, const QString &description, QWidget *parent)
|
2021-10-22 17:19:56 +00:00
|
|
|
: WindowModalDialog(parent)
|
2020-10-07 10:36:04 +00:00
|
|
|
, ui(new Ui::TxConfDialog)
|
2023-03-01 02:05:56 +00:00
|
|
|
, m_wallet(wallet)
|
2020-10-07 10:36:04 +00:00
|
|
|
, m_tx(tx)
|
|
|
|
, m_address(address)
|
|
|
|
, m_description(description)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
|
|
ui->label_warning->setText("You are about to send a transaction.\nVerify the information below.");
|
2021-01-21 03:10:46 +00:00
|
|
|
ui->label_note->hide();
|
2020-10-07 10:36:04 +00:00
|
|
|
|
|
|
|
QString preferredCur = config()->get(Config::preferredFiatCurrency).toString();
|
|
|
|
|
|
|
|
auto convert = [preferredCur](double amount){
|
2021-05-02 18:22:38 +00:00
|
|
|
return QString::number(appData()->prices.convert("XMR", preferredCur, amount), 'f', 2);
|
2020-10-07 10:36:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
QString amount = WalletManager::displayAmount(tx->amount());
|
|
|
|
QString fee = WalletManager::displayAmount(tx->fee());
|
|
|
|
QString total = WalletManager::displayAmount(tx->amount() + tx->fee());
|
2020-12-16 16:31:25 +00:00
|
|
|
QVector<QString> amounts = {amount, fee, total};
|
|
|
|
int maxLength = Utils::maxLength(amounts);
|
|
|
|
std::for_each(amounts.begin(), amounts.end(), [maxLength](QString& amount){amount = amount.rightJustified(maxLength, ' ');});
|
|
|
|
|
2021-05-18 15:59:18 +00:00
|
|
|
QString amount_fiat = convert(tx->amount() / constants::cdiv);
|
|
|
|
QString fee_fiat = convert(tx->fee() / constants::cdiv);
|
|
|
|
QString total_fiat = convert((tx->amount() + tx->fee()) / constants::cdiv);
|
2020-12-16 16:31:25 +00:00
|
|
|
QVector<QString> amounts_fiat = {amount_fiat, fee_fiat, total_fiat};
|
|
|
|
int maxLengthFiat = Utils::maxLength(amounts_fiat);
|
|
|
|
std::for_each(amounts_fiat.begin(), amounts_fiat.end(), [maxLengthFiat](QString& amount){amount = amount.rightJustified(maxLengthFiat, ' ');});
|
|
|
|
|
2023-03-28 20:42:12 +00:00
|
|
|
ui->label_amount->setFont(Utils::getMonospaceFont());
|
|
|
|
ui->label_fee->setFont(Utils::getMonospaceFont());
|
|
|
|
ui->label_total->setFont(Utils::getMonospaceFont());
|
2021-01-28 22:48:14 +00:00
|
|
|
|
2020-12-16 16:31:25 +00:00
|
|
|
ui->label_amount->setText(QString("%1 (%2 %3)").arg(amounts[0], amounts_fiat[0], preferredCur));
|
|
|
|
ui->label_fee->setText(QString("%1 (%2 %3)").arg(amounts[1], amounts_fiat[1], preferredCur));
|
|
|
|
ui->label_total->setText(QString("%1 (%2 %3)").arg(amounts[2], amounts_fiat[2], preferredCur));
|
2020-10-07 10:36:04 +00:00
|
|
|
|
2023-03-01 02:05:56 +00:00
|
|
|
auto subaddressIndex = m_wallet->subaddressIndex(address);
|
2021-01-21 03:10:46 +00:00
|
|
|
QString addressExtra;
|
2021-01-28 22:48:14 +00:00
|
|
|
|
2023-03-28 20:42:12 +00:00
|
|
|
ui->label_address->setText(Utils::displayAddress(address, 2));
|
|
|
|
ui->label_address->setFont(Utils::getMonospaceFont());
|
2021-01-28 22:48:14 +00:00
|
|
|
ui->label_address->setToolTip(address);
|
|
|
|
|
2021-01-29 14:51:59 +00:00
|
|
|
if (subaddressIndex.isValid()) {
|
2021-01-21 03:10:46 +00:00
|
|
|
ui->label_note->setText("Note: this is a churn transaction.");
|
|
|
|
ui->label_note->show();
|
2021-01-28 22:48:14 +00:00
|
|
|
ui->label_address->setStyleSheet(ColorScheme::GREEN.asStylesheet(true));
|
|
|
|
ui->label_address->setToolTip("Wallet receive address");
|
2021-01-21 03:10:46 +00:00
|
|
|
}
|
|
|
|
|
2021-01-29 14:51:59 +00:00
|
|
|
if (subaddressIndex.isPrimary()) {
|
2021-01-28 22:48:14 +00:00
|
|
|
ui->label_address->setStyleSheet(ColorScheme::YELLOW.asStylesheet(true));
|
|
|
|
ui->label_address->setToolTip("Wallet change/primary address");
|
|
|
|
}
|
2020-10-07 10:36:04 +00:00
|
|
|
|
2022-06-23 15:14:06 +00:00
|
|
|
if (tx->fee() > WalletManager::amountFromDouble(0.01)) {
|
|
|
|
ui->label_fee->setStyleSheet(ColorScheme::RED.asStylesheet(true));
|
|
|
|
ui->label_fee->setToolTip("Unrealistic fee. You may be connected to a malicious node.");
|
|
|
|
}
|
|
|
|
|
2020-10-16 03:05:05 +00:00
|
|
|
ui->buttonBox->button(QDialogButtonBox::Ok)->setText("Send");
|
|
|
|
|
|
|
|
connect(ui->btn_Advanced, &QPushButton::clicked, this, &TxConfDialog::setShowAdvanced);
|
2020-10-07 10:36:04 +00:00
|
|
|
|
|
|
|
this->adjustSize();
|
|
|
|
}
|
|
|
|
|
2020-10-16 03:05:05 +00:00
|
|
|
void TxConfDialog::setShowAdvanced() {
|
|
|
|
this->showAdvanced = true;
|
|
|
|
QDialog::reject();
|
2020-10-07 10:36:04 +00:00
|
|
|
}
|
|
|
|
|
2021-06-27 12:13:05 +00:00
|
|
|
TxConfDialog::~TxConfDialog() = default;
|