From c247962c21cf33c73f86cc07160c46bc98274b0b Mon Sep 17 00:00:00 2001 From: tobtoht Date: Thu, 4 Jan 2024 22:23:16 +0100 Subject: [PATCH] History: set default description to Coinbase for mining outputs --- src/libwalletqt/TransactionHistory.cpp | 29 +++++++++++++++++--------- src/libwalletqt/TransactionHistory.h | 1 + 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/libwalletqt/TransactionHistory.cpp b/src/libwalletqt/TransactionHistory.cpp index 7218aa3..aaa543a 100644 --- a/src/libwalletqt/TransactionHistory.cpp +++ b/src/libwalletqt/TransactionHistory.cpp @@ -103,11 +103,7 @@ void TransactionHistory::refresh() t->m_timestamp = QDateTime::fromSecsSinceEpoch(pd.m_timestamp); t->m_confirmations = (wallet_height > pd.m_block_height) ? wallet_height - pd.m_block_height : 0; t->m_unlockTime = pd.m_unlock_time; - - t->m_description = QString::fromStdString(m_wallet2->get_tx_note(pd.m_tx_hash)); - if (t->m_description.isEmpty()) { - t->m_description = QString::fromStdString(m_wallet2->get_subaddress_label(pd.m_subaddr_index)); - } + t->m_description = description(pd); m_rows.append(t); } @@ -254,11 +250,7 @@ void TransactionHistory::refresh() t->m_label = QString::fromStdString(m_wallet2->get_subaddress_label(pd.m_subaddr_index)); t->m_timestamp = QDateTime::fromSecsSinceEpoch(pd.m_timestamp); t->m_confirmations = 0; - - t->m_description = QString::fromStdString(m_wallet2->get_tx_note(pd.m_tx_hash)); - if (t->m_description.isEmpty()) { - t->m_description = QString::fromStdString(m_wallet2->get_subaddress_label(pd.m_subaddr_index)); - } + t->m_description = description(pd); m_rows.append(t); @@ -393,3 +385,20 @@ bool TransactionHistory::writeCSV(const QString &path) { data = QString("blockHeight,timestamp,date,accountIndex,direction,balanceDelta,amount,fee,txid,description,paymentId,fiatAmount,fiatCurrency%1").arg(data); return Utils::fileWrite(path, data); } + +QString TransactionHistory::description(const tools::wallet2::payment_details &pd) +{ + QString description = QString::fromStdString(m_wallet2->get_tx_note(pd.m_tx_hash)); + if (description.isEmpty()) { + if (pd.m_coinbase) { + description = "Coinbase"; + } + else if (pd.m_subaddr_index.major == 0 && pd.m_subaddr_index.minor == 0) { + description = "Primary address"; + } + else { + description = QString::fromStdString(m_wallet2->get_subaddress_label(pd.m_subaddr_index)); + } + } + return description; +} \ No newline at end of file diff --git a/src/libwalletqt/TransactionHistory.h b/src/libwalletqt/TransactionHistory.h index ce10b8e..24e60c6 100644 --- a/src/libwalletqt/TransactionHistory.h +++ b/src/libwalletqt/TransactionHistory.h @@ -51,6 +51,7 @@ signals: private: explicit TransactionHistory(Wallet *wallet, tools::wallet2 *wallet2, QObject *parent = nullptr); + QString description(const tools::wallet2::payment_details &pd); private: friend class Wallet;