From 22abca45785a0408c82560c100e63392fceec655 Mon Sep 17 00:00:00 2001 From: tobtoht Date: Fri, 29 Jan 2021 15:51:59 +0100 Subject: [PATCH] TxInfoDialog: improve UI --- src/dialog/transactioninfodialog.cpp | 30 +++++-- src/dialog/transactioninfodialog.h | 4 + src/dialog/transactioninfodialog.ui | 126 ++++++++++++++++++--------- src/dialog/txconfadvdialog.cpp | 20 +---- src/dialog/txconfadvdialog.h | 4 - src/dialog/txconfdialog.cpp | 4 +- src/libwalletqt/TransactionInfo.cpp | 4 + src/libwalletqt/TransactionInfo.h | 1 + src/libwalletqt/Transfer.h | 3 +- src/libwalletqt/Wallet.cpp | 6 +- src/libwalletqt/Wallet.h | 21 ++++- src/utils/utils.cpp | 17 ++++ src/utils/utils.h | 3 + 13 files changed, 165 insertions(+), 78 deletions(-) diff --git a/src/dialog/transactioninfodialog.cpp b/src/dialog/transactioninfodialog.cpp index 4d38b5d..f9f7a00 100644 --- a/src/dialog/transactioninfodialog.cpp +++ b/src/dialog/transactioninfodialog.cpp @@ -6,7 +6,9 @@ #include "libwalletqt/CoinsInfo.h" #include "libwalletqt/WalletManager.h" +#include "libwalletqt/Transfer.h" #include "utils.h" +#include "utils/ColorScheme.h" #include @@ -23,12 +25,16 @@ TransactionInfoDialog::TransactionInfoDialog(Wallet *wallet, TransactionInfo *tx ui->label_txid->setText(QString(txInfo->hash())); if (txInfo->direction() == TransactionInfo::Direction_In) { - ui->txKey->hide(); + ui->frameTxKey->hide(); } else { QString txKey = m_wallet->getTxKey(txInfo->hash()); - txKey = txKey.isEmpty() ? "unknown" : txKey; - ui->label_txKey->setText(txKey); + if (txKey.isEmpty()) { + ui->btn_CopyTxKey->setEnabled(false); + ui->btn_CopyTxKey->setToolTip("Transaction key unknown"); + } + m_txKey = txKey; } + connect(ui->btn_CopyTxKey, &QPushButton::pressed, this, &TransactionInfoDialog::copyTxKey); QString blockHeight = QString::number(txInfo->blockHeight()); if (blockHeight == "0") @@ -47,11 +53,17 @@ TransactionInfoDialog::TransactionInfoDialog(Wallet *wallet, TransactionInfo *tx qDebug() << m_wallet->coins()->coins_from_txid(txInfo->hash()); - QString destinations = txInfo->destinations_formatted(); - if (destinations.isEmpty()) { + 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(); + } + if (txInfo->transfers().size() == 0) { ui->frameDestinations->hide(); - } else { - ui->destinations->setText(destinations); } ui->txProofWidget->addWidget(m_txProofWidget); @@ -59,6 +71,10 @@ TransactionInfoDialog::TransactionInfoDialog(Wallet *wallet, TransactionInfo *tx this->adjustSize(); } +void TransactionInfoDialog::copyTxKey() { + Utils::copyToClipboard(m_txKey); +} + TransactionInfoDialog::~TransactionInfoDialog() { delete ui; } diff --git a/src/dialog/transactioninfodialog.h b/src/dialog/transactioninfodialog.h index 23b3d72..67ddad8 100644 --- a/src/dialog/transactioninfodialog.h +++ b/src/dialog/transactioninfodialog.h @@ -5,6 +5,7 @@ #define FEATHER_TRANSACTIONINFODIALOG_H #include +#include #include #include "libwalletqt/Coins.h" #include "libwalletqt/TransactionInfo.h" @@ -24,11 +25,14 @@ public: ~TransactionInfoDialog() override; private: + void copyTxKey(); + Ui::TransactionInfoDialog *ui; TransactionInfo *m_txInfo; Wallet *m_wallet; TxProofWidget *m_txProofWidget; + QString m_txKey; }; #endif //FEATHER_TRANSACTIONINFODIALOG_H diff --git a/src/dialog/transactioninfodialog.ui b/src/dialog/transactioninfodialog.ui index 00585c2..f7ae9fd 100644 --- a/src/dialog/transactioninfodialog.ui +++ b/src/dialog/transactioninfodialog.ui @@ -14,6 +14,9 @@ Transaction + + + @@ -33,25 +36,6 @@ - - - - Transaction key: - - - - - - txKey - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse - - - - - - @@ -131,6 +115,22 @@ + + + + Qt::Vertical + + + QSizePolicy::Maximum + + + + 0 + 15 + + + + @@ -152,13 +152,6 @@ 0 - - - - Qt::Horizontal - - - @@ -168,9 +161,15 @@ - + + + 0 + 0 + + + - 16777215 + 0 100 @@ -182,29 +181,76 @@ - - - - Qt::Horizontal - - - - - - Qt::Vertical + + QSizePolicy::Maximum + - 20 - 0 + 0 + 15 + + + + QFrame::NoFrame + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Copy + + + + + + + Transaction Key + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + diff --git a/src/dialog/txconfadvdialog.cpp b/src/dialog/txconfadvdialog.cpp index 507334e..cc67e4d 100644 --- a/src/dialog/txconfadvdialog.cpp +++ b/src/dialog/txconfadvdialog.cpp @@ -109,7 +109,8 @@ void TxConfAdvDialog::setupConstructionData(ConstructionInfo *ci) { for (const auto& o: outputs) { auto address = o->address(); auto amount = WalletManager::displayAmount(o->amount()); - cursor.insertText(address, textFormat(address)); + auto index = m_ctx->currentWallet->subaddressIndex(address); + cursor.insertText(address, Utils::addressTextFormat(index)); cursor.insertText(QString(" %1").arg(amount), QTextCharFormat()); cursor.insertBlock(); } @@ -183,23 +184,6 @@ void TxConfAdvDialog::closeDialog() { QDialog::reject(); } -QTextCharFormat TxConfAdvDialog::textFormat(const QString &address) { - auto index = m_ctx->currentWallet->subaddressIndex(address); - if (index.first == 0 && index.second == 0) { - QTextCharFormat rec; - rec.setBackground(QBrush(ColorScheme::YELLOW.asColor(true))); - rec.setToolTip("Wallet change/primary address"); - return rec; - } - if (index.first >= 0) { - QTextCharFormat rec; - rec.setBackground(QBrush(ColorScheme::GREEN.asColor(true))); - rec.setToolTip("Wallet receive address"); - return rec; - } - return QTextCharFormat(); -} - TxConfAdvDialog::~TxConfAdvDialog() { delete ui; } diff --git a/src/dialog/txconfadvdialog.h b/src/dialog/txconfadvdialog.h index 6d426e7..bd68797 100644 --- a/src/dialog/txconfadvdialog.h +++ b/src/dialog/txconfadvdialog.h @@ -42,8 +42,6 @@ private: void signedQrCode(); void signedSaveFile(); - QTextCharFormat textFormat(const QString &address); - Ui::TxConfAdvDialog *ui; AppContext *m_ctx; PendingTransaction *m_tx = nullptr; @@ -52,6 +50,4 @@ private: QMenu *m_exportSignedMenu; }; - - #endif //FEATHER_TXCONFADVDIALOG_H diff --git a/src/dialog/txconfdialog.cpp b/src/dialog/txconfdialog.cpp index 4922724..9c5e3e5 100644 --- a/src/dialog/txconfdialog.cpp +++ b/src/dialog/txconfdialog.cpp @@ -58,14 +58,14 @@ TxConfDialog::TxConfDialog(AppContext *ctx, PendingTransaction *tx, const QStrin ui->label_address->setFont(ModelUtils::getMonospaceFont()); ui->label_address->setToolTip(address); - if (subaddressIndex.first >= 0) { + if (subaddressIndex.isValid()) { ui->label_note->setText("Note: this is a churn transaction."); ui->label_note->show(); ui->label_address->setStyleSheet(ColorScheme::GREEN.asStylesheet(true)); ui->label_address->setToolTip("Wallet receive address"); } - if (subaddressIndex.first == 0 && subaddressIndex.second == 0) { + if (subaddressIndex.isPrimary()) { ui->label_address->setStyleSheet(ColorScheme::YELLOW.asStylesheet(true)); ui->label_address->setToolTip("Wallet change/primary address"); } diff --git a/src/libwalletqt/TransactionInfo.cpp b/src/libwalletqt/TransactionInfo.cpp index d7dae29..f7ad540 100644 --- a/src/libwalletqt/TransactionInfo.cpp +++ b/src/libwalletqt/TransactionInfo.cpp @@ -144,6 +144,10 @@ QList TransactionInfo::destinations() const return dests; } +QList TransactionInfo::transfers() const { + return m_transfers; +} + QString TransactionInfo::rings_formatted() const { QString rings; diff --git a/src/libwalletqt/TransactionInfo.h b/src/libwalletqt/TransactionInfo.h index acdbf81..11d767c 100644 --- a/src/libwalletqt/TransactionInfo.h +++ b/src/libwalletqt/TransactionInfo.h @@ -76,6 +76,7 @@ public: //! used in tx details popup QList destinations() const; QString destinations_formatted() const; + QList transfers() const; QString rings_formatted() const; private: diff --git a/src/libwalletqt/Transfer.h b/src/libwalletqt/Transfer.h index baca79d..8349d41 100644 --- a/src/libwalletqt/Transfer.h +++ b/src/libwalletqt/Transfer.h @@ -14,7 +14,8 @@ class Transfer : public QObject Q_PROPERTY(quint64 amount READ amount) Q_PROPERTY(QString address READ address) private: - explicit Transfer(uint64_t _amount, QString _address, QObject *parent = 0): QObject(parent), m_amount(_amount), m_address(std::move(_address)) {}; + explicit Transfer(uint64_t _amount, QString _address, QObject *parent = 0) + : QObject(parent), m_amount(_amount), m_address(std::move(_address)) {}; private: friend class TransactionInfo; friend class ConstructionInfo; diff --git a/src/libwalletqt/Wallet.cpp b/src/libwalletqt/Wallet.cpp index c1100ae..178e546 100644 --- a/src/libwalletqt/Wallet.cpp +++ b/src/libwalletqt/Wallet.cpp @@ -150,13 +150,13 @@ QString Wallet::address(quint32 accountIndex, quint32 addressIndex) const return QString::fromStdString(m_walletImpl->address(accountIndex, addressIndex)); } -QPair Wallet::subaddressIndex(const QString &address) const +SubaddressIndex Wallet::subaddressIndex(const QString &address) const { std::pair i; if (!m_walletImpl->subaddressIndex(address.toStdString(), i)) { - return QPair(-1, -1); + return SubaddressIndex(-1, -1); } - return QPair(i.first, i.second); + return SubaddressIndex(i.first, i.second); } QString Wallet::path() const diff --git a/src/libwalletqt/Wallet.h b/src/libwalletqt/Wallet.h index e8f1e19..5c5c9a1 100644 --- a/src/libwalletqt/Wallet.h +++ b/src/libwalletqt/Wallet.h @@ -30,6 +30,22 @@ struct TxProof { QString error; }; +struct SubaddressIndex { + SubaddressIndex(int major, int minor) + : major(major), minor(minor) {} + + bool isValid() const { + return major >= 0 && minor >= 0; + } + + bool isPrimary() const { + return major == 0 && minor == 0; + } + + int major; + int minor; +}; + class TransactionHistory; class TransactionHistoryModel; class TransactionHistoryProxyModel; @@ -139,9 +155,8 @@ public: //! returns wallet's public address Q_INVOKABLE QString address(quint32 accountIndex, quint32 addressIndex) const; - //! returns the subaddress index (major, minor) of the address - // (-1, -1) if address does not belong to wallet - Q_INVOKABLE QPair subaddressIndex(const QString &address) const; + //! returns the subaddress index of the address + Q_INVOKABLE SubaddressIndex subaddressIndex(const QString &address) const; //! returns wallet file's path QString path() const; diff --git a/src/utils/utils.cpp b/src/utils/utils.cpp index 9abca2c..7888103 100644 --- a/src/utils/utils.cpp +++ b/src/utils/utils.cpp @@ -14,6 +14,7 @@ #include "utils/config.h" #include "utils/tails.h" #include "utils/whonix.h" +#include "utils/ColorScheme.h" #include "globals.h" // Application log for current session @@ -550,4 +551,20 @@ QString Utils::balanceFormat(quint64 balance) { str.remove(QRegExp("\\.$")); return str; +} + +QTextCharFormat Utils::addressTextFormat(const SubaddressIndex &index) { + if (index.isPrimary()) { + QTextCharFormat rec; + rec.setBackground(QBrush(ColorScheme::YELLOW.asColor(true))); + rec.setToolTip("Wallet change/primary address"); + return rec; + } + if (index.isValid()) { + QTextCharFormat rec; + rec.setBackground(QBrush(ColorScheme::GREEN.asColor(true))); + rec.setToolTip("Wallet receive address"); + return rec; + } + return QTextCharFormat(); } \ No newline at end of file diff --git a/src/utils/utils.h b/src/utils/utils.h index 93e308b..b7fd856 100644 --- a/src/utils/utils.h +++ b/src/utils/utils.h @@ -11,11 +11,13 @@ #include #include #include +#include #include #include #include "networktype.h" +#include "libwalletqt/Wallet.h" struct logMessage { @@ -99,6 +101,7 @@ public: static int maxLength(const QVector &array); static QMap localeCache; static QString balanceFormat(quint64 balance); + static QTextCharFormat addressTextFormat(const SubaddressIndex &index); template static QString QtEnumToString (const QEnum value)