TxInfoDialog: show inputs on outgoing transactions

This commit is contained in:
tobtoht 2021-07-06 15:31:08 +02:00
parent 71736e7e87
commit b3669c5a95
No known key found for this signature in database
GPG key ID: 1CADD27F41F45C3C
3 changed files with 92 additions and 23 deletions

View file

@ -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<AppContext> 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<CoinsInfo*> 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());

View file

@ -6,6 +6,7 @@
#include <QDialog>
#include <QTextCharFormat>
#include <QTextEdit>
#include <QtSvg/QSvgWidget>
#include "appcontext.h"
@ -31,6 +32,7 @@ private:
void createTxProof();
void setData(TransactionInfo *tx);
void updateData();
void adjustHeight(QTextEdit *textEdit, qreal docHeight);
QScopedPointer<Ui::TxInfoDialog> ui;
QSharedPointer<AppContext> m_ctx;

View file

@ -94,7 +94,51 @@
</spacer>
</item>
<item>
<widget class="QFrame" name="frameDestinations">
<widget class="QFrame" name="frameInputs">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_inputs">
<property name="text">
<string>Inputs:</string>
</property>
</widget>
</item>
<item>
<widget class="QTextEdit" name="inputs">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QFrame" name="frameOutputs">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
@ -115,7 +159,7 @@
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_destinations">
<widget class="QLabel" name="label_outputs">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
@ -128,7 +172,7 @@
</widget>
</item>
<item>
<widget class="QTextEdit" name="destinations">
<widget class="QTextEdit" name="outputs">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>