From 71da777375d41f0b57003d0d28edd83611136d42 Mon Sep 17 00:00:00 2001 From: Ilya Kitaev Date: Thu, 14 Jul 2016 13:09:39 +0300 Subject: [PATCH] Init wallet asynchronously --- main.qml | 20 ++++---------------- src/libwalletqt/Wallet.cpp | 16 +++++++++++++++- src/libwalletqt/Wallet.h | 9 +++++++++ 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/main.qml b/main.qml index b96b5dea..168591df 100644 --- a/main.qml +++ b/main.qml @@ -145,23 +145,12 @@ ApplicationWindow { } console.log("Wallet opened successfully: ", wallet.errorString); } - // display splash screen... - - console.log("initializing with daemon address..") - if (!wallet.init(persistentSettings.daemon_address, 0)) { - console.log("Error initialize wallet: ", wallet.errorString); - return - } - console.log("Wallet initialized successfully") - // TODO: update network indicator - // subscribing for wallet updates wallet.updated.connect(onWalletUpdate); wallet.refreshed.connect(onWalletRefresh); - console.log("refreshing wallet async") - // TODO: refresh asynchronously without blocking UI, implement signal(s) - wallet.refreshAsync(); - console.log("wallet balance: ", wallet.balance) + + console.log("initializing with daemon address..") + wallet.initAsync(persistentSettings.daemon_address, 0); } @@ -173,8 +162,7 @@ ApplicationWindow { function onWalletRefresh() { console.log(">>> wallet refreshed") - leftPanel.unlockedBalanceText = walletManager.displayAmount(wallet.unlockedBalance); - leftPanel.balanceText = walletManager.displayAmount(wallet.balance); + onWalletUpdate(); } diff --git a/src/libwalletqt/Wallet.cpp b/src/libwalletqt/Wallet.cpp index 3697984e..4c6995cb 100644 --- a/src/libwalletqt/Wallet.cpp +++ b/src/libwalletqt/Wallet.cpp @@ -28,6 +28,7 @@ public: // TODO Q_UNUSED(txId) Q_UNUSED(amount) + qDebug() << __FUNCTION__; } virtual void moneyReceived(const std::string &txId, uint64_t amount) @@ -35,16 +36,19 @@ public: // TODO Q_UNUSED(txId) Q_UNUSED(amount) + qDebug() << __FUNCTION__; } virtual void updated() { + qDebug() << __FUNCTION__; emit m_wallet->updated(); } // called when wallet refreshed by background thread or explicitly virtual void refreshed() { + qDebug() << __FUNCTION__; emit m_wallet->refreshed(); } @@ -74,6 +78,11 @@ Wallet::Status Wallet::status() const return static_cast(m_walletImpl->status()); } +bool Wallet::connected() const +{ + return m_walletImpl->connected(); +} + QString Wallet::errorString() const { return QString::fromStdString(m_walletImpl->errorString()); @@ -99,6 +108,11 @@ bool Wallet::init(const QString &daemonAddress, quint64 upperTransactionLimit) return m_walletImpl->init(daemonAddress.toStdString(), upperTransactionLimit); } +void Wallet::initAsync(const QString &daemonAddress, quint64 upperTransactionLimit) +{ + m_walletImpl->initAsync(daemonAddress.toStdString(), upperTransactionLimit); +} + bool Wallet::connectToDaemon() { return m_walletImpl->connectToDaemon(); @@ -183,7 +197,7 @@ void Wallet::setPaymentId(const QString &paymentId) Wallet::Wallet(Bitmonero::Wallet *w, QObject *parent) : QObject(parent), m_walletImpl(w), m_history(nullptr) { - + m_walletImpl->setListener(new WalletListenerImpl(this)); } Wallet::~Wallet() diff --git a/src/libwalletqt/Wallet.h b/src/libwalletqt/Wallet.h index 4d6a1ea0..feba75e0 100644 --- a/src/libwalletqt/Wallet.h +++ b/src/libwalletqt/Wallet.h @@ -20,6 +20,7 @@ class Wallet : public QObject Q_PROPERTY(QString seed READ getSeed) Q_PROPERTY(QString seedLanguage READ getSeedLanguage) Q_PROPERTY(Status status READ status) + Q_PROPERTY(bool connected READ connected) Q_PROPERTY(QString errorString READ errorString) Q_PROPERTY(QString address READ address) Q_PROPERTY(quint64 balance READ balance) @@ -27,6 +28,7 @@ class Wallet : public QObject Q_PROPERTY(TransactionHistory * history READ history) Q_PROPERTY(QString paymentId READ paymentId WRITE setPaymentId) + public: enum Status { Status_Ok = Bitmonero::Wallet::Status_Ok, @@ -47,6 +49,9 @@ public: //! returns last operation's status Status status() const; + //! returns of wallet connected + bool connected() const; + //! returns last operation's error message QString errorString() const; @@ -62,6 +67,9 @@ public: //! initializes wallet Q_INVOKABLE bool init(const QString &daemonAddress, quint64 upperTransactionLimit); + //! initializes wallet asynchronously + Q_INVOKABLE void initAsync(const QString &daemonAddress, quint64 upperTransactionLimit); + //! connects to daemon Q_INVOKABLE bool connectToDaemon(); @@ -124,6 +132,7 @@ private: // history lifetime managed by wallet; TransactionHistory * m_history; QString m_paymentId; + }; #endif // WALLET_H