From a4c3de9e2e3ad364ceb979499221a2fc86a09548 Mon Sep 17 00:00:00 2001 From: Jaquee Date: Sat, 3 Dec 2016 12:06:57 +0100 Subject: [PATCH 1/4] history: add Transfer class --- monero-core.pro | 1 + src/libwalletqt/Transfer.h | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 src/libwalletqt/Transfer.h diff --git a/monero-core.pro b/monero-core.pro index 5e47d732..0113aa63 100644 --- a/monero-core.pro +++ b/monero-core.pro @@ -24,6 +24,7 @@ HEADERS += \ src/libwalletqt/TransactionHistory.h \ src/libwalletqt/TransactionInfo.h \ src/libwalletqt/QRCodeImageProvider.h \ + src/libwalletqt/Transfer.h \ oshelper.h \ TranslationManager.h \ src/model/TransactionHistoryModel.h \ diff --git a/src/libwalletqt/Transfer.h b/src/libwalletqt/Transfer.h new file mode 100644 index 00000000..2f68f7c1 --- /dev/null +++ b/src/libwalletqt/Transfer.h @@ -0,0 +1,28 @@ +#ifndef TRANSFER_H +#define TRANSFER_H + +#include +#include + +class Transfer : public QObject +{ + Q_OBJECT + Q_PROPERTY(quint64 amount READ amount) + Q_PROPERTY(QString address READ address) +private: + explicit Transfer(uint64_t _amount, const QString &_address, QObject *parent = 0): m_amount(_amount), m_address(_address), QObject(parent) {}; +private: + friend class TransactionInfo; + qint64 m_amount; + QString m_address; + +public: + qint64 amount(){ return m_amount; } + QString address(){ return m_address; }; + +}; +// in order to wrap it to QVariant +Q_DECLARE_METATYPE(Transfer*) + + +#endif // TRANSACTIONINFO_H From 7aea3d38d6cea3264436bf90c0633ed1b62738d1 Mon Sep 17 00:00:00 2001 From: Jaquee Date: Sat, 3 Dec 2016 12:07:47 +0100 Subject: [PATCH 2/4] TransactionInfo: add transfers() and destinations_formatted() --- src/libwalletqt/TransactionHistory.h | 1 - src/libwalletqt/TransactionInfo.cpp | 28 ++++++++++++++++++++++++++- src/libwalletqt/TransactionInfo.h | 20 ++++++++----------- src/libwalletqt/Transfer.h | 12 ++++-------- src/model/TransactionHistoryModel.cpp | 4 ++++ src/model/TransactionHistoryModel.h | 4 +++- 6 files changed, 46 insertions(+), 23 deletions(-) diff --git a/src/libwalletqt/TransactionHistory.h b/src/libwalletqt/TransactionHistory.h index ee05787a..41ee6338 100644 --- a/src/libwalletqt/TransactionHistory.h +++ b/src/libwalletqt/TransactionHistory.h @@ -41,7 +41,6 @@ private: private: friend class Wallet; - Bitmonero::TransactionHistory * m_pimpl; mutable QList m_tinfo; mutable QDateTime m_firstDateTime; diff --git a/src/libwalletqt/TransactionInfo.cpp b/src/libwalletqt/TransactionInfo.cpp index fb096a14..ba81b6a8 100644 --- a/src/libwalletqt/TransactionInfo.cpp +++ b/src/libwalletqt/TransactionInfo.cpp @@ -1,7 +1,8 @@ #include "TransactionInfo.h" #include "WalletManager.h" - +#include "Transfer.h" #include +#include TransactionInfo::Direction TransactionInfo::direction() const { @@ -71,6 +72,31 @@ QString TransactionInfo::paymentId() const return QString::fromStdString(m_pimpl->paymentId()); } +QString TransactionInfo::destinations_formatted() const +{ + QString destinations; + for (auto const& t: transfers()) { + if (!destinations.isEmpty()) + destinations += "
"; + destinations += WalletManager::instance()->displayAmount(t->amount()) + ": " + t->address(); + } + return destinations; +} + +QList TransactionInfo::transfers() const +{ + if (!m_transfers.isEmpty()) { + return m_transfers; + } + + for(auto const& t: m_pimpl->transfers()) { + TransactionInfo * parent = const_cast(this); + Transfer * transfer = new Transfer(t.amount, QString::fromStdString(t.address), parent); + m_transfers.append(transfer); + } + return m_transfers; +} + TransactionInfo::TransactionInfo(Bitmonero::TransactionInfo *pimpl, QObject *parent) : QObject(parent), m_pimpl(pimpl) { diff --git a/src/libwalletqt/TransactionInfo.h b/src/libwalletqt/TransactionInfo.h index 7e9396a1..cd4ce3d0 100644 --- a/src/libwalletqt/TransactionInfo.h +++ b/src/libwalletqt/TransactionInfo.h @@ -5,6 +5,8 @@ #include #include +class Transfer; + class TransactionInfo : public QObject { Q_OBJECT @@ -21,6 +23,7 @@ class TransactionInfo : public QObject Q_PROPERTY(QString date READ date) Q_PROPERTY(QString time READ time) Q_PROPERTY(QString paymentId READ paymentId) + Q_PROPERTY(QString destinations_formatted READ destinations_formatted) public: enum Direction { @@ -31,14 +34,6 @@ public: Q_ENUM(Direction) -// TODO: implement as separate class; - -// struct Transfer { -// Transfer(uint64_t _amount, const std::string &address); -// const uint64_t amount; -// const std::string address; -// }; - Direction direction() const; bool isPending() const; bool isFailed() const; @@ -53,16 +48,17 @@ public: QString date() const; QString time() const; QString paymentId() const; - - - // TODO: implement it //! only applicable for output transactions - // virtual const std::vector & transfers() const = 0; + //! used in tx details popup + QString destinations_formatted() const; + //! Could be useful later when addressbook is implemented + Q_INVOKABLE QList transfers() const; private: explicit TransactionInfo(Bitmonero::TransactionInfo * pimpl, QObject *parent = 0); private: friend class TransactionHistory; Bitmonero::TransactionInfo * m_pimpl; + mutable QList m_transfers; }; // in order to wrap it to QVariant diff --git a/src/libwalletqt/Transfer.h b/src/libwalletqt/Transfer.h index 2f68f7c1..a31ad84e 100644 --- a/src/libwalletqt/Transfer.h +++ b/src/libwalletqt/Transfer.h @@ -10,19 +10,15 @@ class Transfer : public QObject Q_PROPERTY(quint64 amount READ amount) Q_PROPERTY(QString address READ address) private: - explicit Transfer(uint64_t _amount, const QString &_address, QObject *parent = 0): m_amount(_amount), m_address(_address), QObject(parent) {}; + explicit Transfer(uint64_t _amount, const QString &_address, QObject *parent = 0): QObject(parent), m_amount(_amount), m_address(_address) {}; private: friend class TransactionInfo; - qint64 m_amount; + quint64 m_amount; QString m_address; - public: - qint64 amount(){ return m_amount; } - QString address(){ return m_address; }; + quint64 amount() const { return m_amount; } + QString address() const { return m_address; } }; -// in order to wrap it to QVariant -Q_DECLARE_METATYPE(Transfer*) - #endif // TRANSACTIONINFO_H diff --git a/src/model/TransactionHistoryModel.cpp b/src/model/TransactionHistoryModel.cpp index cf280e99..333893aa 100644 --- a/src/model/TransactionHistoryModel.cpp +++ b/src/model/TransactionHistoryModel.cpp @@ -95,6 +95,9 @@ QVariant TransactionHistoryModel::data(const QModelIndex &index, int role) const case TransactionTimeRole: result = tInfo->time(); break; + case TransactionDestinationsRole: + result = tInfo->destinations_formatted(); + break; } return result; @@ -124,6 +127,7 @@ QHash TransactionHistoryModel::roleNames() const roleNames.insert(TransactionIsOutRole, "isOut"); roleNames.insert(TransactionDateRole, "date"); roleNames.insert(TransactionTimeRole, "time"); + roleNames.insert(TransactionDestinationsRole, "destinations"); return roleNames; } diff --git a/src/model/TransactionHistoryModel.h b/src/model/TransactionHistoryModel.h index 8b18f887..1b349914 100644 --- a/src/model/TransactionHistoryModel.h +++ b/src/model/TransactionHistoryModel.h @@ -33,7 +33,9 @@ public: // extra roles for date and time (as UI wants date and time separately) TransactionDateRole, TransactionTimeRole, - TransactionAtomicAmountRole + TransactionAtomicAmountRole, + // only for outgoing + TransactionDestinationsRole }; Q_ENUM(TransactionInfoRole) From 9341d752361a780090feea54da1845073b3d9b91 Mon Sep 17 00:00:00 2001 From: Jaquee Date: Sat, 3 Dec 2016 12:08:39 +0100 Subject: [PATCH 3/4] history: print destination address in tx details popup --- components/HistoryTable.qml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/components/HistoryTable.qml b/components/HistoryTable.qml index 5f4584c7..9a4e31f2 100644 --- a/components/HistoryTable.qml +++ b/components/HistoryTable.qml @@ -28,6 +28,8 @@ import QtQuick 2.0 import moneroComponents.Clipboard 1.0 +import moneroComponents.TransactionHistory 1.0 +import moneroComponents.TransactionInfo 1.0 ListView { @@ -37,7 +39,7 @@ ListView { property var previousItem property int rowSpacing: 12 - function buildTxDetailsString(tx_id, paymentId, tx_key,tx_note) { + function buildTxDetailsString(tx_id, paymentId, tx_key,tx_note, destinations) { var trStart = '', trMiddle = '', trEnd = ""; @@ -47,6 +49,7 @@ ListView { + (paymentId ? trStart + qsTr("Payment ID:") + trMiddle + paymentId + trEnd : "") + (tx_key ? trStart + qsTr("Tx key:") + trMiddle + tx_key + trEnd : "") + (tx_note ? trStart + qsTr("Tx note:") + trMiddle + tx_note + trEnd : "") + + (destinations ? trStart + qsTr("Destinations:") + trMiddle + destinations + trEnd : "") + "" + translationManager.emptyString; } @@ -71,6 +74,7 @@ ListView { id: detailsPopup cancelVisible: false okVisible: true + width:850 } @@ -96,12 +100,10 @@ ListView { pressedColor: "#FF4304" text: qsTr("Details") onClicked: { - console.log(hash) var tx_key = currentWallet.getTxKey(hash) var tx_note = currentWallet.getUserNote(hash) - console.log("key",tx_key); detailsPopup.title = "Transaction details"; - detailsPopup.content = buildTxDetailsString(hash,paymentId,tx_key,tx_note); + detailsPopup.content = buildTxDetailsString(hash,paymentId,tx_key,tx_note,destinations); detailsPopup.open(); } From e1255bd91f6b237fe85acb18cc19164fb82408ca Mon Sep 17 00:00:00 2001 From: Jaquee Date: Sat, 3 Dec 2016 12:11:14 +0100 Subject: [PATCH 4/4] history: remove unused dependencies --- components/HistoryTable.qml | 2 -- 1 file changed, 2 deletions(-) diff --git a/components/HistoryTable.qml b/components/HistoryTable.qml index 9a4e31f2..5bf2a3c8 100644 --- a/components/HistoryTable.qml +++ b/components/HistoryTable.qml @@ -28,8 +28,6 @@ import QtQuick 2.0 import moneroComponents.Clipboard 1.0 -import moneroComponents.TransactionHistory 1.0 -import moneroComponents.TransactionInfo 1.0 ListView {