feather/src/dialog/transactioninfodialog.cpp

132 lines
4.6 KiB
C++
Raw Normal View History

// SPDX-License-Identifier: BSD-3-Clause
2020-12-26 19:56:06 +00:00
// Copyright (c) 2020-2021, The Monero Project.
#include "transactioninfodialog.h"
#include "ui_transactioninfodialog.h"
#include "libwalletqt/CoinsInfo.h"
#include "libwalletqt/WalletManager.h"
2021-01-29 14:51:59 +00:00
#include "libwalletqt/Transfer.h"
2021-03-14 21:12:02 +00:00
#include "libwalletqt/TransactionHistory.h"
#include "utils.h"
2021-01-29 14:51:59 +00:00
#include "utils/ColorScheme.h"
2021-03-14 21:12:02 +00:00
#include "model/ModelUtils.h"
#include "config.h"
#include "appcontext.h"
#include <QMessageBox>
2021-03-14 21:12:02 +00:00
#include <QScrollBar>
2020-10-19 23:05:42 +00:00
TransactionInfoDialog::TransactionInfoDialog(Wallet *wallet, TransactionInfo *txInfo, QWidget *parent)
: QDialog(parent)
, ui(new Ui::TransactionInfoDialog)
2020-10-19 23:05:42 +00:00
, m_wallet(wallet)
, m_txInfo(txInfo)
{
ui->setupUi(this);
2021-03-08 20:03:20 +00:00
m_txid = txInfo->hash();
ui->label_txid->setText(m_txid);
2021-03-14 21:12:02 +00:00
m_txKey = m_wallet->getTxKey(txInfo->hash());
if (m_txKey.isEmpty()) {
2021-03-08 20:03:20 +00:00
ui->btn_CopyTxKey->setEnabled(false);
ui->btn_CopyTxKey->setToolTip("Transaction key unknown");
2020-10-19 23:05:42 +00:00
}
2021-03-08 20:03:20 +00:00
2021-01-29 14:51:59 +00:00
connect(ui->btn_CopyTxKey, &QPushButton::pressed, this, &TransactionInfoDialog::copyTxKey);
2021-03-08 20:03:20 +00:00
connect(ui->btn_createTxProof, &QPushButton::pressed, this, &TransactionInfoDialog::createTxProof);
2021-03-14 21:12:02 +00:00
connect(m_wallet, &Wallet::newBlock, this, &TransactionInfoDialog::updateData);
2021-03-14 21:12:02 +00:00
this->setData(txInfo);
2021-03-14 21:12:02 +00:00
if (AppContext::txCache.contains(txInfo->hash()) && (txInfo->isFailed() || txInfo->isPending()) && txInfo->direction() != TransactionInfo::Direction_In) {
connect(ui->btn_rebroadcastTx, &QPushButton::pressed, [this]{
emit resendTranscation(m_txid);
});
} else {
ui->btn_rebroadcastTx->hide();
}
2021-01-29 14:51:59 +00:00
QTextCursor cursor = ui->destinations->textCursor();
for (const auto& transfer : txInfo->transfers()) {
auto address = transfer->address();
auto amount = WalletManager::displayAmount(transfer->amount());
auto index = m_wallet->subaddressIndex(address);
cursor.insertText(address, Utils::addressTextFormat(index));
cursor.insertText(QString(" %1").arg(amount), QTextCharFormat());
cursor.insertBlock();
}
2021-03-14 21:12:02 +00:00
2021-01-29 14:51:59 +00:00
if (txInfo->transfers().size() == 0) {
ui->frameDestinations->hide();
}
2021-03-08 20:03:20 +00:00
m_txProofDialog = new TxProofDialog(this, m_wallet, txInfo);
2021-03-14 21:12:02 +00:00
QCoreApplication::processEvents();
qreal lineHeight = QFontMetrics(ui->destinations->document()->defaultFont()).height();
qreal docHeight = txInfo->transfers().size();
int h = int(docHeight * (lineHeight + 2) + 11);
h = qMin(qMax(h, 100), 600);
ui->destinations->setMinimumHeight(h);
ui->destinations->setMaximumHeight(h);
ui->destinations->verticalScrollBar()->hide();
this->adjustSize();
}
2021-03-14 21:12:02 +00:00
void TransactionInfoDialog::setData(TransactionInfo* tx) {
QString blockHeight = QString::number(tx->blockHeight());
if (tx->isFailed()) {
ui->label_status->setText("Status: Failed (node was unable to relay transaction)");
}
if (blockHeight == "0") {
ui->label_status->setText("Status: Unconfirmed (in mempool)");
}
else {
QString dateTimeFormat = QString("%1 %2").arg(config()->get(Config::dateFormat).toString(), config()->get(Config::timeFormat).toString());
QString date = tx->timestamp().toString(dateTimeFormat);
QString statusText = QString("Status: Included in block %1 (%2 confirmations) on %3").arg(blockHeight, QString::number(tx->confirmations()), date);
ui->label_status->setText(statusText);
}
if (tx->confirmationsRequired() > tx->confirmations()) {
bool mandatoryLock = tx->confirmationsRequired() == 10;
QString confsRequired = QString::number(tx->confirmationsRequired() - tx->confirmations());
ui->label_lock->setText(QString("Lock: Outputs become spendable in %1 blocks (%2)").arg(confsRequired, mandatoryLock ? "consensus rule" : "specified by sender"));
} else {
ui->label_lock->setText("Lock: Outputs are spendable");
}
QString direction = tx->direction() == TransactionInfo::Direction_In ? "received" : "sent";
ui->label_amount->setText(QString("Amount %1: %2").arg(direction, tx->displayAmount()));
QString fee = tx->fee().isEmpty() ? "n/a" : tx->fee();
ui->label_fee->setText(QString("Fee: %1 XMR").arg(tx->isCoinbase() ? WalletManager::displayAmount(0) : fee));
}
void TransactionInfoDialog::updateData() {
if (!m_wallet) return;
TransactionInfo* tx = m_wallet->history()->transaction(m_txid);
if (!tx) return;
this->setData(tx);
}
2021-01-29 14:51:59 +00:00
void TransactionInfoDialog::copyTxKey() {
Utils::copyToClipboard(m_txKey);
}
2021-03-08 20:03:20 +00:00
void TransactionInfoDialog::createTxProof() {
m_txProofDialog->show();
}
TransactionInfoDialog::~TransactionInfoDialog() {
delete ui;
}