diff --git a/src/libwalletqt/TransactionInfo.cpp b/src/libwalletqt/TransactionInfo.cpp index 9200ec11..9c5094bb 100644 --- a/src/libwalletqt/TransactionInfo.cpp +++ b/src/libwalletqt/TransactionInfo.cpp @@ -34,85 +34,81 @@ TransactionInfo::Direction TransactionInfo::direction() const { - return static_cast(m_pimpl->direction()); + return m_direction; } bool TransactionInfo::isPending() const { - return m_pimpl->isPending(); + return m_pending; } bool TransactionInfo::isFailed() const { - return m_pimpl->isFailed(); + return m_failed; } double TransactionInfo::amount() const { // there's no unsigned uint64 for JS, so better use double - return WalletManager::instance()->displayAmount(m_pimpl->amount()).toDouble(); + return displayAmount().toDouble(); } quint64 TransactionInfo::atomicAmount() const { - return m_pimpl->amount(); + return m_amount; } QString TransactionInfo::displayAmount() const { - return WalletManager::instance()->displayAmount(m_pimpl->amount()); + return WalletManager::instance()->displayAmount(m_amount); } QString TransactionInfo::fee() const { - if(m_pimpl->fee() == 0) + if(m_fee == 0) return ""; - return WalletManager::instance()->displayAmount(m_pimpl->fee()); + return WalletManager::instance()->displayAmount(m_fee); } quint64 TransactionInfo::blockHeight() const { - return m_pimpl->blockHeight(); + return m_blockHeight; } QSet TransactionInfo::subaddrIndex() const { - QSet result; - for (uint32_t i : m_pimpl->subaddrIndex()) - result.insert(i); - return result; + return m_subaddrIndex; } quint32 TransactionInfo::subaddrAccount() const { - return m_pimpl->subaddrAccount(); + return m_subaddrAccount; } QString TransactionInfo::label() const { - return QString::fromStdString(m_pimpl->label()); + return m_label; } quint64 TransactionInfo::confirmations() const { - return m_pimpl->confirmations(); + return m_confirmations; } quint64 TransactionInfo::unlockTime() const { - return m_pimpl->unlockTime(); + return m_unlockTime; } QString TransactionInfo::hash() const { - return QString::fromStdString(m_pimpl->hash()); + return m_hash; } QDateTime TransactionInfo::timestamp() const { - QDateTime result = QDateTime::fromTime_t(m_pimpl->timestamp()); - return result; + return m_timestamp; } QString TransactionInfo::date() const @@ -127,13 +123,13 @@ QString TransactionInfo::time() const QString TransactionInfo::paymentId() const { - return QString::fromStdString(m_pimpl->paymentId()); + return m_paymentId; } QString TransactionInfo::destinations_formatted() const { QString destinations; - for (auto const& t: transfers()) { + for (auto const& t: m_transfers) { if (!destinations.isEmpty()) destinations += "
"; destinations += WalletManager::instance()->displayAmount(t->amount()) + ": " + t->address(); @@ -141,22 +137,29 @@ QString TransactionInfo::destinations_formatted() const return destinations; } -QList TransactionInfo::transfers() const +TransactionInfo::TransactionInfo(const Monero::TransactionInfo *pimpl, QObject *parent) + : QObject(parent) + , m_amount(pimpl->amount()) + , m_blockHeight(pimpl->blockHeight()) + , m_confirmations(pimpl->confirmations()) + , m_direction(static_cast(pimpl->direction())) + , m_failed(pimpl->isFailed()) + , m_fee(pimpl->fee()) + , m_hash(QString::fromStdString(pimpl->hash())) + , m_label(QString::fromStdString(pimpl->label())) + , m_paymentId(QString::fromStdString(pimpl->paymentId())) + , m_pending(pimpl->isPending()) + , m_subaddrAccount(pimpl->subaddrAccount()) + , m_timestamp(QDateTime::fromTime_t(pimpl->timestamp())) + , m_unlockTime(pimpl->unlockTime()) { - 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); + for (auto const &t: pimpl->transfers()) + { + Transfer *transfer = new Transfer(t.amount, QString::fromStdString(t.address), this); m_transfers.append(transfer); } - return m_transfers; -} - -TransactionInfo::TransactionInfo(Monero::TransactionInfo *pimpl, QObject *parent) - : QObject(parent), m_pimpl(pimpl) -{ - + for (uint32_t i : pimpl->subaddrIndex()) + { + m_subaddrIndex.insert(i); + } } diff --git a/src/libwalletqt/TransactionInfo.h b/src/libwalletqt/TransactionInfo.h index e18fe849..1f5041e6 100644 --- a/src/libwalletqt/TransactionInfo.h +++ b/src/libwalletqt/TransactionInfo.h @@ -90,14 +90,25 @@ public: //! only applicable for output transactions //! 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(Monero::TransactionInfo * pimpl, QObject *parent = 0); + explicit TransactionInfo(const Monero::TransactionInfo *pimpl, QObject *parent = 0); private: friend class TransactionHistory; - Monero::TransactionInfo * m_pimpl; mutable QList m_transfers; + quint64 m_amount; + quint64 m_blockHeight; + quint64 m_confirmations; + Direction m_direction; + bool m_failed; + quint64 m_fee; + QString m_hash; + QString m_label; + QString m_paymentId; + bool m_pending; + quint32 m_subaddrAccount; + QSet m_subaddrIndex; + QDateTime m_timestamp; + quint64 m_unlockTime; }; // in order to wrap it to QVariant