From b3669c5a950598dcff80e76e6b192584cc4bd82f Mon Sep 17 00:00:00 2001 From: tobtoht Date: Tue, 6 Jul 2021 15:31:08 +0200 Subject: [PATCH] TxInfoDialog: show inputs on outgoing transactions --- src/dialog/TxInfoDialog.cpp | 63 +++++++++++++++++++++++++------------ src/dialog/TxInfoDialog.h | 2 ++ src/dialog/TxInfoDialog.ui | 50 +++++++++++++++++++++++++++-- 3 files changed, 92 insertions(+), 23 deletions(-) diff --git a/src/dialog/TxInfoDialog.cpp b/src/dialog/TxInfoDialog.cpp index 8abcea4f..dc549893 100644 --- a/src/dialog/TxInfoDialog.cpp +++ b/src/dialog/TxInfoDialog.cpp @@ -9,6 +9,8 @@ #include "appcontext.h" #include "config.h" +#include "libwalletqt/Coins.h" +#include "libwalletqt/CoinsInfo.h" #include "libwalletqt/TransactionHistory.h" #include "libwalletqt/Transfer.h" #include "libwalletqt/WalletManager.h" @@ -42,33 +44,54 @@ TxInfoDialog::TxInfoDialog(QSharedPointer ctx, TransactionInfo *txIn ui->btn_rebroadcastTx->hide(); } - QTextCursor cursor = ui->destinations->textCursor(); - for (const auto& transfer : txInfo->transfers()) { - auto address = transfer->address(); - auto amount = WalletManager::displayAmount(transfer->amount()); - auto index = m_ctx->wallet->subaddressIndex(address); - cursor.insertText(address, Utils::addressTextFormat(index, transfer->amount())); - cursor.insertText(QString(" %1").arg(amount), QTextCharFormat()); - cursor.insertBlock(); + if (txInfo->direction() == TransactionInfo::Direction_Out) { + // TODO: this will not properly represent coinjoin-like transactions. + QVector coins = m_ctx->wallet->coins()->coins_from_txid(m_txid); + QTextCursor c_i = ui->inputs->textCursor(); + QString inputs_str; + for (const auto &coin : coins) { + inputs_str += QString("%1 %2\n").arg(coin->pubKey(), coin->displayAmount()); + } + ui->inputs->setText(inputs_str); + ui->label_inputs->setText(QString("Inputs (%1)").arg(QString::number(coins.size()))); + this->adjustHeight(ui->inputs, coins.size()); + } else { + ui->frameInputs->hide(); } - if (txInfo->transfers().size() == 0) { - ui->frameDestinations->hide(); + QTextCursor cursor = ui->outputs->textCursor(); + + auto transfers = txInfo->transfers(); + if (!transfers.isEmpty()) { + for (const auto& transfer : transfers) { + auto address = transfer->address(); + auto amount = WalletManager::displayAmount(transfer->amount()); + auto index = m_ctx->wallet->subaddressIndex(address); + cursor.insertText(address, Utils::addressTextFormat(index, transfer->amount())); + cursor.insertText(QString(" %1").arg(amount), QTextCharFormat()); + cursor.insertBlock(); + } + ui->label_outputs->setText(QString("Destinations (%2)").arg(QString::number(transfers.size()))); + this->adjustHeight(ui->outputs, transfers.size()); + } else { + ui->frameOutputs->hide(); } - 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(); } +void TxInfoDialog::adjustHeight(QTextEdit *textEdit, qreal docHeight) { + QCoreApplication::processEvents(); + + qreal lineHeight = QFontMetrics(ui->outputs->document()->defaultFont()).height(); + + int h = int(docHeight * (lineHeight + 2) + 11); + h = qMin(qMax(h, 100), 600); + textEdit->setMinimumHeight(h); + textEdit->setMaximumHeight(h); + textEdit->verticalScrollBar()->hide(); +} + void TxInfoDialog::setData(TransactionInfo *tx) { QString blockHeight = QString::number(tx->blockHeight()); diff --git a/src/dialog/TxInfoDialog.h b/src/dialog/TxInfoDialog.h index a1ad1b92..0041471a 100644 --- a/src/dialog/TxInfoDialog.h +++ b/src/dialog/TxInfoDialog.h @@ -6,6 +6,7 @@ #include #include +#include #include #include "appcontext.h" @@ -31,6 +32,7 @@ private: void createTxProof(); void setData(TransactionInfo *tx); void updateData(); + void adjustHeight(QTextEdit *textEdit, qreal docHeight); QScopedPointer ui; QSharedPointer m_ctx; diff --git a/src/dialog/TxInfoDialog.ui b/src/dialog/TxInfoDialog.ui index 66e9c0cc..02b18c82 100644 --- a/src/dialog/TxInfoDialog.ui +++ b/src/dialog/TxInfoDialog.ui @@ -94,7 +94,51 @@ - + + + QFrame::NoFrame + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Inputs: + + + + + + + + 0 + 0 + + + + true + + + + + + + + QFrame::NoFrame @@ -115,7 +159,7 @@ 0 - + 0 @@ -128,7 +172,7 @@ - + 0