1
mirror of https://github.com/monero-project/monero-gui synced 2025-01-16 14:27:26 +01:00

Merge pull request #235

e1255bd history: remove unused dependencies (Jaquee)
9341d75 history: print destination address in tx details popup (Jaquee)
7aea3d3 TransactionInfo: add transfers() and destinations_formatted() (Jaquee)
a4c3de9 history: add Transfer class (Jaquee)
This commit is contained in:
Riccardo Spagni 2016-12-09 00:06:44 +02:00
commit bb506a2e92
No known key found for this signature in database
GPG Key ID: 55432DF31CCD4FCD
8 changed files with 71 additions and 19 deletions

View File

@ -37,7 +37,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 = '<tr><td width="85" style="padding-top:5px"><b>',
trMiddle = '</b></td><td style="padding-left:10px;padding-top:5px;">',
trEnd = "</td></tr>";
@ -47,6 +47,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 : "")
+ "</table>"
+ translationManager.emptyString;
}
@ -72,6 +73,7 @@ ListView {
width:600
cancelVisible: false
okVisible: true
width:850
}
@ -97,12 +99,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();
}

View File

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

View File

@ -41,7 +41,6 @@ private:
private:
friend class Wallet;
Bitmonero::TransactionHistory * m_pimpl;
mutable QList<TransactionInfo*> m_tinfo;
mutable QDateTime m_firstDateTime;

View File

@ -1,7 +1,8 @@
#include "TransactionInfo.h"
#include "WalletManager.h"
#include "Transfer.h"
#include <QDateTime>
#include <QDebug>
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 += "<br> ";
destinations += WalletManager::instance()->displayAmount(t->amount()) + ": " + t->address();
}
return destinations;
}
QList<Transfer*> TransactionInfo::transfers() const
{
if (!m_transfers.isEmpty()) {
return m_transfers;
}
for(auto const& t: m_pimpl->transfers()) {
TransactionInfo * parent = const_cast<TransactionInfo*>(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)
{

View File

@ -5,6 +5,8 @@
#include <QObject>
#include <QDateTime>
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<Transfer> & transfers() const = 0;
//! used in tx details popup
QString destinations_formatted() const;
//! Could be useful later when addressbook is implemented
Q_INVOKABLE QList<Transfer*> transfers() const;
private:
explicit TransactionInfo(Bitmonero::TransactionInfo * pimpl, QObject *parent = 0);
private:
friend class TransactionHistory;
Bitmonero::TransactionInfo * m_pimpl;
mutable QList<Transfer*> m_transfers;
};
// in order to wrap it to QVariant

View File

@ -0,0 +1,24 @@
#ifndef TRANSFER_H
#define TRANSFER_H
#include <wallet/wallet2_api.h>
#include <QObject>
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): QObject(parent), m_amount(_amount), m_address(_address) {};
private:
friend class TransactionInfo;
quint64 m_amount;
QString m_address;
public:
quint64 amount() const { return m_amount; }
QString address() const { return m_address; }
};
#endif // TRANSACTIONINFO_H

View File

@ -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<int, QByteArray> TransactionHistoryModel::roleNames() const
roleNames.insert(TransactionIsOutRole, "isOut");
roleNames.insert(TransactionDateRole, "date");
roleNames.insert(TransactionTimeRole, "time");
roleNames.insert(TransactionDestinationsRole, "destinations");
return roleNames;
}

View File

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