forked from Public/monero-gui
Transaction history is not crashing and refreshing properly
This commit is contained in:
@@ -7,54 +7,53 @@
|
||||
|
||||
TransactionInfo *TransactionHistory::transaction(int index)
|
||||
{
|
||||
// box up Bitmonero::TransactionInfo
|
||||
Bitmonero::TransactionInfo * impl = m_pimpl->transaction(index);
|
||||
if (!impl) {
|
||||
|
||||
if (index < 0 || index >= m_tinfo.size()) {
|
||||
qCritical("%s: no transaction info for index %d", __FUNCTION__, index);
|
||||
qCritical("%s: there's %d transactions in backend", __FUNCTION__, m_pimpl->count());
|
||||
return nullptr;
|
||||
}
|
||||
TransactionInfo * result = new TransactionInfo(impl, this);
|
||||
return result;
|
||||
return m_tinfo.at(index);
|
||||
}
|
||||
|
||||
TransactionInfo *TransactionHistory::transaction(const QString &id)
|
||||
{
|
||||
// box up Bitmonero::TransactionInfo
|
||||
Bitmonero::TransactionInfo * impl = m_pimpl->transaction(id.toStdString());
|
||||
TransactionInfo * result = new TransactionInfo(impl, this);
|
||||
return result;
|
||||
}
|
||||
//// XXX: not sure if this method really needed;
|
||||
//TransactionInfo *TransactionHistory::transaction(const QString &id)
|
||||
//{
|
||||
// return nullptr;
|
||||
//}
|
||||
|
||||
QList<TransactionInfo *> TransactionHistory::getAll() const
|
||||
{
|
||||
// XXX this invalidates previously saved history that might be used by model
|
||||
emit refreshStarted();
|
||||
qDeleteAll(m_tinfo);
|
||||
m_tinfo.clear();
|
||||
TransactionHistory * parent = const_cast<TransactionHistory*>(this);
|
||||
for (const auto i : m_pimpl->getAll()) {
|
||||
TransactionInfo * ti = new TransactionInfo(i, parent);
|
||||
qDebug() << ti->hash();
|
||||
m_tinfo.append(ti);
|
||||
}
|
||||
emit refreshFinished();
|
||||
return m_tinfo;
|
||||
}
|
||||
|
||||
void TransactionHistory::refresh()
|
||||
{
|
||||
// XXX this invalidates previously saved history that might be used by clients
|
||||
|
||||
emit refreshStarted();
|
||||
// rebuilding transaction list in wallet_api;
|
||||
m_pimpl->refresh();
|
||||
emit refreshFinished();
|
||||
// copying list here and keep track on every item to avoid memleaks
|
||||
getAll();
|
||||
}
|
||||
|
||||
quint64 TransactionHistory::count() const
|
||||
{
|
||||
return m_pimpl->count();
|
||||
return m_tinfo.count();
|
||||
}
|
||||
|
||||
|
||||
TransactionHistory::TransactionHistory(Bitmonero::TransactionHistory *pimpl, QObject *parent)
|
||||
: QObject(parent), m_pimpl(pimpl)
|
||||
{
|
||||
|
||||
// this->refresh();
|
||||
}
|
||||
|
||||
@@ -17,14 +17,14 @@ class TransactionHistory : public QObject
|
||||
|
||||
public:
|
||||
Q_INVOKABLE TransactionInfo *transaction(int index);
|
||||
Q_INVOKABLE TransactionInfo * transaction(const QString &id);
|
||||
// Q_INVOKABLE TransactionInfo * transaction(const QString &id);
|
||||
Q_INVOKABLE QList<TransactionInfo*> getAll() const;
|
||||
Q_INVOKABLE void refresh();
|
||||
quint64 count() const;
|
||||
|
||||
signals:
|
||||
void refreshStarted();
|
||||
void refreshFinished();
|
||||
void refreshStarted() const;
|
||||
void refreshFinished() const;
|
||||
|
||||
public slots:
|
||||
|
||||
|
||||
@@ -32,7 +32,6 @@ public:
|
||||
|
||||
virtual void moneyReceived(const std::string &txId, uint64_t amount)
|
||||
{
|
||||
|
||||
qDebug() << __FUNCTION__;
|
||||
emit m_wallet->moneyReceived(QString::fromStdString(txId), amount);
|
||||
}
|
||||
@@ -40,14 +39,12 @@ public:
|
||||
virtual void newBlock(uint64_t height)
|
||||
{
|
||||
// qDebug() << __FUNCTION__;
|
||||
m_wallet->m_history->refresh();
|
||||
emit m_wallet->newBlock(height);
|
||||
}
|
||||
|
||||
virtual void updated()
|
||||
{
|
||||
qDebug() << __FUNCTION__;
|
||||
m_wallet->m_history->refresh();
|
||||
emit m_wallet->updated();
|
||||
}
|
||||
|
||||
@@ -55,7 +52,6 @@ public:
|
||||
virtual void refreshed()
|
||||
{
|
||||
qDebug() << __FUNCTION__;
|
||||
|
||||
emit m_wallet->refreshed();
|
||||
}
|
||||
|
||||
@@ -93,6 +89,11 @@ bool Wallet::connected() const
|
||||
return m_walletImpl->connected();
|
||||
}
|
||||
|
||||
bool Wallet::synchronized() const
|
||||
{
|
||||
return m_walletImpl->synchronized();
|
||||
}
|
||||
|
||||
QString Wallet::errorString() const
|
||||
{
|
||||
return QString::fromStdString(m_walletImpl->errorString());
|
||||
@@ -207,19 +208,16 @@ void Wallet::disposeTransaction(PendingTransaction *t)
|
||||
delete t;
|
||||
}
|
||||
|
||||
TransactionHistory *Wallet::history()
|
||||
TransactionHistory *Wallet::history() const
|
||||
{
|
||||
// if (m_history->count() == 0) {
|
||||
// m_history->refresh();
|
||||
// }
|
||||
|
||||
return m_history;
|
||||
}
|
||||
|
||||
TransactionHistoryModel *Wallet::historyModel()
|
||||
TransactionHistoryModel *Wallet::historyModel() const
|
||||
{
|
||||
if (!m_historyModel) {
|
||||
m_historyModel = new TransactionHistoryModel(this);
|
||||
Wallet * w = const_cast<Wallet*>(this);
|
||||
m_historyModel = new TransactionHistoryModel(w);
|
||||
m_historyModel->setTransactionHistory(this->history());
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ class Wallet : public QObject
|
||||
Q_PROPERTY(QString seedLanguage READ getSeedLanguage)
|
||||
Q_PROPERTY(Status status READ status)
|
||||
Q_PROPERTY(bool connected READ connected)
|
||||
Q_PROPERTY(bool synchronized READ synchronized)
|
||||
Q_PROPERTY(QString errorString READ errorString)
|
||||
Q_PROPERTY(QString address READ address)
|
||||
Q_PROPERTY(quint64 balance READ balance)
|
||||
@@ -52,9 +53,13 @@ public:
|
||||
//! returns last operation's status
|
||||
Status status() const;
|
||||
|
||||
//! returns of wallet connected
|
||||
//! returns true if wallet connected
|
||||
bool connected() const;
|
||||
|
||||
//! returns true if wallet was ever synchronized
|
||||
bool synchronized() const;
|
||||
|
||||
|
||||
//! returns last operation's error message
|
||||
QString errorString() const;
|
||||
|
||||
@@ -98,7 +103,6 @@ public:
|
||||
//! refreshes the wallet
|
||||
Q_INVOKABLE bool refresh();
|
||||
|
||||
|
||||
//! refreshes the wallet asynchronously
|
||||
Q_INVOKABLE void refreshAsync();
|
||||
|
||||
@@ -116,10 +120,10 @@ public:
|
||||
Q_INVOKABLE void disposeTransaction(PendingTransaction * t);
|
||||
|
||||
//! returns transaction history
|
||||
TransactionHistory * history();
|
||||
TransactionHistory * history() const;
|
||||
|
||||
//! returns transaction history model
|
||||
TransactionHistoryModel * historyModel();
|
||||
TransactionHistoryModel * historyModel() const;
|
||||
|
||||
//! generate payment id
|
||||
Q_INVOKABLE QString generatePaymentId() const;
|
||||
@@ -160,7 +164,7 @@ private:
|
||||
// history lifetime managed by wallet;
|
||||
TransactionHistory * m_history;
|
||||
// Used for UI history view
|
||||
TransactionHistoryModel * m_historyModel;
|
||||
mutable TransactionHistoryModel * m_historyModel;
|
||||
QString m_paymentId;
|
||||
mutable QTime m_daemonBlockChainHeightTime;
|
||||
mutable quint64 m_daemonBlockChainHeight;
|
||||
|
||||
Reference in New Issue
Block a user