aboutsummaryrefslogtreecommitdiff
path: root/src/libwalletqt
diff options
context:
space:
mode:
authorIlya Kitaev <mbg033@gmail.com>2016-10-07 00:47:28 +0300
committerIlya Kitaev <mbg033@gmail.com>2016-10-10 00:19:13 +0300
commit0498c3ba64ace2bd8898a5d0ba3107a2f024c692 (patch)
treebeb2d8e596eb5632ebcd1efcabcfdf75a299774b /src/libwalletqt
parentdefc2a414abe6df837682d1472db0272f0b55eca (diff)
downloadmonzero-gui-0498c3ba64ace2bd8898a5d0ba3107a2f024c692.tar.gz
monzero-gui-0498c3ba64ace2bd8898a5d0ba3107a2f024c692.tar.xz
monzero-gui-0498c3ba64ace2bd8898a5d0ba3107a2f024c692.zip
Transaction history is not crashing and refreshing properly
Diffstat (limited to 'src/libwalletqt')
-rw-r--r--src/libwalletqt/TransactionHistory.cpp35
-rw-r--r--src/libwalletqt/TransactionHistory.h6
-rw-r--r--src/libwalletqt/Wallet.cpp20
-rw-r--r--src/libwalletqt/Wallet.h14
4 files changed, 38 insertions, 37 deletions
diff --git a/src/libwalletqt/TransactionHistory.cpp b/src/libwalletqt/TransactionHistory.cpp
index 8f52f07e..e94816f2 100644
--- a/src/libwalletqt/TransactionHistory.cpp
+++ b/src/libwalletqt/TransactionHistory.cpp
@@ -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();
}
diff --git a/src/libwalletqt/TransactionHistory.h b/src/libwalletqt/TransactionHistory.h
index 560b8df8..d7a7278e 100644
--- a/src/libwalletqt/TransactionHistory.h
+++ b/src/libwalletqt/TransactionHistory.h
@@ -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:
diff --git a/src/libwalletqt/Wallet.cpp b/src/libwalletqt/Wallet.cpp
index 39d40a17..14e0a868 100644
--- a/src/libwalletqt/Wallet.cpp
+++ b/src/libwalletqt/Wallet.cpp
@@ -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());
}
diff --git a/src/libwalletqt/Wallet.h b/src/libwalletqt/Wallet.h
index d3ca4085..159a08b0 100644
--- a/src/libwalletqt/Wallet.h
+++ b/src/libwalletqt/Wallet.h
@@ -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;