From c82fed8aa0eb2378251b5fc6f8c05142a28403d7 Mon Sep 17 00:00:00 2001 From: "James C. Owens" Date: Sun, 29 Oct 2023 13:51:37 -0400 Subject: [PATCH] Add TypeToString in TransactionRecord and use for loop to include in TransactionView --- src/qt/transactionrecord.cpp | 49 ++++++++++++++++++++++++++++++++++++ src/qt/transactionrecord.h | 15 +++++++++++ src/qt/transactionview.cpp | 15 +++++------ 3 files changed, 72 insertions(+), 7 deletions(-) diff --git a/src/qt/transactionrecord.cpp b/src/qt/transactionrecord.cpp index 8747cc6664..1fc5af5a19 100755 --- a/src/qt/transactionrecord.cpp +++ b/src/qt/transactionrecord.cpp @@ -1,6 +1,7 @@ #include "transactionrecord.h" #include "wallet/wallet.h" #include "base58.h" +#include /* Return positive answer if transaction should be shown in list. */ bool TransactionRecord::showTransaction(const CWalletTx &wtx, bool datetime_limit_flag, const int64_t &datetime_limit) @@ -361,6 +362,54 @@ QList TransactionRecord::decomposeTransaction(const CWallet * return parts; } +QString TransactionRecord::TypeToString() const +{ + return TypeToString(type); +} + +QString TransactionRecord::TypeToString(const Type& type, const bool& translated) +{ + if (translated) { + switch(type) { + case Other: return QObject::tr("Other"); + case Generated: return QObject::tr("Mined"); + case SendToAddress: return QObject::tr("Sent to Address"); + case SendToOther: return QObject::tr("Sent to Other"); + case RecvWithAddress: return QObject::tr("Received with Address"); + case RecvFromOther: return QObject::tr("Received from Other"); + case SendToSelf: return QObject::tr("Self"); + case BeaconAdvertisement: return QObject::tr("Beacon Advertisements"); + case Poll: return QObject::tr("Polls"); + case Vote: return QObject::tr("Votes"); + case Message: return QObject::tr("Messages"); + case MRC: return QObject::tr("MRCs"); + } + + assert(false); // Suppress warning + } else { + switch(type) { + case Other: return "Other"; + case Generated: return "Mined"; + case SendToAddress: return "Sent to Address"; + case SendToOther: return "Sent to Other"; + case RecvWithAddress: return "Received with Address"; + case RecvFromOther: return "Received from Other"; + case SendToSelf: return "Self"; + case BeaconAdvertisement: return "Beacon Advertisements"; + case Poll: return "Polls"; + case Vote: return "Votes"; + case Message: return "Messages"; + case MRC: return "MRCs"; + } + + assert(false); // Suppress warning + } + + // This will never be reached. Put it in anyway to prevent control reaches end of non-void function warning + // from some compiler versions. + return QString{}; +} + void TransactionRecord::updateStatus(const CWalletTx &wtx) EXCLUSIVE_LOCKS_REQUIRED(cs_main) { AssertLockHeld(cs_main); diff --git a/src/qt/transactionrecord.h b/src/qt/transactionrecord.h index 9ce027b73c..4bd8c075d7 100644 --- a/src/qt/transactionrecord.h +++ b/src/qt/transactionrecord.h @@ -87,6 +87,18 @@ class TransactionRecord MRC }; + static constexpr std::initializer_list TYPES {Other, + Generated, + SendToAddress, + RecvWithAddress, + RecvFromOther, + SendToSelf, + BeaconAdvertisement, + Poll, + Vote, + Message, + MRC}; + /** Number of confirmation recommended for accepting a transaction */ static const int RecommendedNumConfirmations = 10; @@ -114,6 +126,9 @@ class TransactionRecord static bool showTransaction(const CWalletTx &wtx, bool datetime_limit_flag = false, const int64_t &datetime_limit = 0); static QList decomposeTransaction(const CWallet *wallet, const CWalletTx &wtx); + QString TypeToString() const; + static QString TypeToString(const Type& type, const bool& translated = true); + /** @name Immutable transaction attributes @{*/ uint256 hash; diff --git a/src/qt/transactionview.cpp b/src/qt/transactionview.cpp index b080d75696..7457374500 100644 --- a/src/qt/transactionview.cpp +++ b/src/qt/transactionview.cpp @@ -81,14 +81,15 @@ TransactionView::TransactionView(QWidget *parent) filterFrameLayout->addWidget(dateWidget); typeWidget = new QComboBox(this); + + // Add catch-all typeWidget->addItem(tr("All Types"), TransactionFilterProxy::ALL_TYPES); - typeWidget->addItem(tr("Received with"), TransactionFilterProxy::TYPE(TransactionRecord::RecvWithAddress) | - TransactionFilterProxy::TYPE(TransactionRecord::RecvFromOther)); - typeWidget->addItem(tr("Sent to"), TransactionFilterProxy::TYPE(TransactionRecord::SendToAddress) | - TransactionFilterProxy::TYPE(TransactionRecord::SendToOther)); - typeWidget->addItem(tr("To yourself"), TransactionFilterProxy::TYPE(TransactionRecord::SendToSelf)); - typeWidget->addItem(tr("Mined"), TransactionFilterProxy::TYPE(TransactionRecord::Generated)); - typeWidget->addItem(tr("Other"), TransactionFilterProxy::TYPE(TransactionRecord::Other)); + + // Add types from TransactionRecord Type enum. + for (const auto& iter : TransactionRecord::TYPES) { + typeWidget->addItem(TransactionRecord::TypeToString(iter), TransactionFilterProxy::TYPE(iter)); + } + filterFrameLayout->addWidget(typeWidget); filterFrameLayout->addStretch();