Transaction history is not crashing and refreshing properly

This commit is contained in:
Ilya Kitaev 2016-10-07 00:47:28 +03:00
parent defc2a414a
commit 0498c3ba64
8 changed files with 74 additions and 45 deletions

View File

@ -80,6 +80,7 @@ ListView {
}
// -- description aka recepient name from address book (TODO)
/*
Text {
id: descriptionText
width: text.length ? (descriptionArea.containsMouse ? parent.width - x - 12 : 120) : 0
@ -97,12 +98,14 @@ ListView {
hoverEnabled: true
}
}
*/
/*
Item { //separator
width: descriptionText.width ? 12 : 0
height: 14
visible: !descriptionArea.containsMouse
}
*/
// -- address (in case outgoing transaction) - N/A in case of incoming
Text {
id: addressText
@ -113,7 +116,7 @@ ListView {
font.pixelSize: 14
color: "#545454"
text: hash
visible: !descriptionArea.containsMouse
// visible: !descriptionArea.containsMouse
}
}
// -- "PaymentID" title

View File

@ -40,6 +40,7 @@
#include "PendingTransaction.h"
#include "TranslationManager.h"
#include "TransactionInfo.h"
#include "TransactionHistory.h"
#include "model/TransactionHistoryModel.h"
@ -57,6 +58,7 @@ int main(int argc, char *argv[])
filter *eventFilter = new filter;
app.installEventFilter(eventFilter);
// registering types for QML
qmlRegisterType<clipboardAdapter>("moneroComponents.Clipboard", 1, 0, "Clipboard");
qmlRegisterUncreatableType<Wallet>("moneroComponents.Wallet", 1, 0, "Wallet", "Wallet can't be instantiated directly");
@ -77,7 +79,9 @@ int main(int argc, char *argv[])
qmlRegisterUncreatableType<TransactionHistoryModel>("moneroComponents", 1, 0, "TransactionHistoryModel",
"TranslationManager can't be instantiated directly");
"TransactionHistoryModel can't be instantiated directly");
qmlRegisterUncreatableType<TransactionHistory>("moneroComponents", 1, 0, "TransactionHistory",
"TransactionHistory can't be instantiated directly");
QQmlApplicationEngine engine;

View File

@ -55,6 +55,8 @@ ApplicationWindow {
property alias password : passwordDialog.password
property int splashCounter: 0
property bool isNewWallet: false
// true if wallet ever synchronized
property bool walletInitialized : false
function altKeyReleased() { ctrlPressed = false; }
@ -168,11 +170,10 @@ ApplicationWindow {
currentWallet.refreshed.connect(onWalletRefresh)
currentWallet.updated.connect(onWalletUpdate)
currentWallet.newBlock.connect(onWalletNewBlock)
currentWallet.moneySpent.connect(onWalletMoneySent)
currentWallet.moneyReceived.connect(onWalletMoneyReceived)
console.log("initializing with daemon address: ", persistentSettings.daemon_address)
currentWallet.initAsync(persistentSettings.daemon_address, 0);
}
function walletPath() {
@ -241,6 +242,13 @@ ApplicationWindow {
console.log("wallet stored after first successfull refresh")
}
// initialize transaction history once wallet is initializef first time;
if (!walletInitialized) {
currentWallet.history.refresh()
walletInitialized = true
}
leftPanel.networkStatus.connected = currentWallet.connected
onWalletUpdate();
@ -258,6 +266,18 @@ ApplicationWindow {
}
}
function onWalletMoneyReceived(txId, amount) {
// refresh transaction history here
currentWallet.refresh()
currentWallet.history.refresh() // this will refresh model
}
function onWalletMoneySent(txId, amount) {
// refresh transaction history here
currentWallet.refresh()
currentWallet.history.refresh() // this will refresh model
}
function walletsFound() {

View File

@ -33,7 +33,7 @@ import moneroComponents.WalletManager 1.0
Rectangle {
id: root
property var model: testModel
property var model
color: "#F0EEEE"
@ -340,7 +340,7 @@ Rectangle {
offset: 20
onSortRequest: console.log("column: " + column + " desc: " + desc)
}
/*
ListModel {
id: testModel
ListElement { paymentId: "faef56b9acf67a7dba75ec01f403497049d7cff111628edfe7b57278554dc798"; address: "faef56b9acf67a7dba75ec01f403497049d7cff111628edfe7b57278554dc798"; date: "Jan 12, 2014"; time: "12:23 <font size='2'>AM</font>"; amount: "0.<font size='2'>000709159241</font>"; balance: "19301.<font size='2'>870709159241</font>"; description: "Client from Australia"; out: false }
@ -354,6 +354,7 @@ Rectangle {
ListElement { paymentId: "faef56b9acf67a7dba75ec01f403497049d7cff111628edfe7b57278554dc798"; address: "faef56b9acf67a7dba75ec01f403497049d7cff111628edfe7b57278554dc798"; date: "Jan 12, 2014"; time: "12:23 <font size='2'>AM</font>"; amount: "0.<font size='2'>000709159241</font>"; balance: "19301.<font size='2'>870709159241</font>"; description: "Client from Australia"; out: false }
ListElement { paymentId: "faef56b9acf67a7dba75ec01f403497049d7cff111628edfe7b57278554dc798"; address: "faef56b9acf67a7dba75ec01f403497049d7cff111628edfe7b57278554dc798"; date: "Jan 12, 2014"; time: "12:23 <font size='2'>AM</font>"; amount: "0.<font size='2'>000709159241</font>"; balance: "19301.<font size='2'>870709159241</font>"; description: ""; out: false }
}
*/
Scroll {
id: flickableScroll

View File

@ -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();
}

View File

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

View File

@ -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());
}

View File

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