TxInfoDialog: improve UI

This commit is contained in:
tobtoht 2021-01-29 15:51:59 +01:00
parent 3e534fd536
commit 22abca4578
No known key found for this signature in database
GPG key ID: 1CADD27F41F45C3C
13 changed files with 165 additions and 78 deletions

View file

@ -6,7 +6,9 @@
#include "libwalletqt/CoinsInfo.h"
#include "libwalletqt/WalletManager.h"
#include "libwalletqt/Transfer.h"
#include "utils.h"
#include "utils/ColorScheme.h"
#include <QMessageBox>
@ -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;
}

View file

@ -5,6 +5,7 @@
#define FEATHER_TRANSACTIONINFODIALOG_H
#include <QDialog>
#include <QTextCharFormat>
#include <QtSvg/QSvgWidget>
#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

View file

@ -14,6 +14,9 @@
<string>Transaction</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2"/>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
@ -33,25 +36,6 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="txKey">
<property name="title">
<string>Transaction key:</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QLabel" name="label_txKey">
<property name="text">
<string>txKey</string>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
@ -131,6 +115,22 @@
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Maximum</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>15</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QFrame" name="frameDestinations">
<property name="frameShape">
@ -152,13 +152,6 @@
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_destinations">
<property name="text">
@ -168,9 +161,15 @@
</item>
<item>
<widget class="QTextEdit" name="destinations">
<property name="maximumSize">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>16777215</width>
<width>0</width>
<height>100</height>
</size>
</property>
@ -182,29 +181,76 @@
</layout>
</widget>
</item>
<item>
<widget class="Line" name="line_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="txProofWidget"/>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Maximum</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>0</height>
<width>0</width>
<height>15</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QFrame" name="frameTxKey">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<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="QPushButton" name="btn_CopyTxKey">
<property name="text">
<string>Copy</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Transaction Key</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="txProofWidget"/>
</item>
</layout>
</widget>
<resources/>

View file

@ -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;
}

View file

@ -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

View file

@ -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");
}

View file

@ -144,6 +144,10 @@ QList<QString> TransactionInfo::destinations() const
return dests;
}
QList<Transfer*> TransactionInfo::transfers() const {
return m_transfers;
}
QString TransactionInfo::rings_formatted() const
{
QString rings;

View file

@ -76,6 +76,7 @@ public:
//! used in tx details popup
QList<QString> destinations() const;
QString destinations_formatted() const;
QList<Transfer*> transfers() const;
QString rings_formatted() const;
private:

View file

@ -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;

View file

@ -150,13 +150,13 @@ QString Wallet::address(quint32 accountIndex, quint32 addressIndex) const
return QString::fromStdString(m_walletImpl->address(accountIndex, addressIndex));
}
QPair<int, int> Wallet::subaddressIndex(const QString &address) const
SubaddressIndex Wallet::subaddressIndex(const QString &address) const
{
std::pair<uint32_t, uint32_t> i;
if (!m_walletImpl->subaddressIndex(address.toStdString(), i)) {
return QPair<int, int>(-1, -1);
return SubaddressIndex(-1, -1);
}
return QPair<int, int>(i.first, i.second);
return SubaddressIndex(i.first, i.second);
}
QString Wallet::path() const

View file

@ -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<int, int> 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;

View file

@ -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();
}

View file

@ -11,11 +11,13 @@
#include <QtNetwork>
#include <QApplication>
#include <QMainWindow>
#include <QTextCharFormat>
#include <sstream>
#include <monero_seed/monero_seed.hpp>
#include "networktype.h"
#include "libwalletqt/Wallet.h"
struct logMessage
{
@ -99,6 +101,7 @@ public:
static int maxLength(const QVector<QString> &array);
static QMap<QString, QLocale> localeCache;
static QString balanceFormat(quint64 balance);
static QTextCharFormat addressTextFormat(const SubaddressIndex &index);
template<typename QEnum>
static QString QtEnumToString (const QEnum value)