mirror of
https://github.com/monero-project/monero-gui.git
synced 2025-01-07 10:22:07 +02:00
WalletManager::openWalletAsync in progress
This commit is contained in:
parent
c1269301f7
commit
d3234bb915
81
main.qml
81
main.qml
@ -49,9 +49,10 @@ ApplicationWindow {
|
|||||||
property bool rightPanelExpanded: false
|
property bool rightPanelExpanded: false
|
||||||
property bool osx: false
|
property bool osx: false
|
||||||
property alias persistentSettings : persistentSettings
|
property alias persistentSettings : persistentSettings
|
||||||
property var wallet;
|
property var currentWallet;
|
||||||
property var transaction;
|
property var transaction;
|
||||||
property alias password : passwordDialog.password
|
property alias password : passwordDialog.password
|
||||||
|
property bool walletOpeningWithPassword: false
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -145,27 +146,10 @@ ApplicationWindow {
|
|||||||
var wallet_path = walletPath();
|
var wallet_path = walletPath();
|
||||||
|
|
||||||
console.log("opening wallet at: ", wallet_path);
|
console.log("opening wallet at: ", wallet_path);
|
||||||
wallet = walletManager.openWallet(wallet_path, appWindow.password,
|
walletManager.openWalletAsync(wallet_path, appWindow.password,
|
||||||
persistentSettings.testnet);
|
persistentSettings.testnet);
|
||||||
if (wallet.status !== Wallet.Status_Ok) {
|
|
||||||
console.error("Error opening wallet with empty password: ", wallet.errorString);
|
|
||||||
console.log("closing wallet...")
|
|
||||||
walletManager.closeWallet(wallet)
|
|
||||||
console.log("wallet closed")
|
|
||||||
// try to open wallet with password;
|
|
||||||
passwordDialog.open();
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("Wallet opened successfully: ", wallet.errorString);
|
|
||||||
}
|
|
||||||
// subscribing for wallet updates
|
|
||||||
wallet.updated.connect(onWalletUpdate);
|
|
||||||
wallet.refreshed.connect(onWalletRefresh);
|
|
||||||
|
|
||||||
console.log("initializing with daemon address..")
|
|
||||||
wallet.initAsync(persistentSettings.daemon_address, 0);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function walletPath() {
|
function walletPath() {
|
||||||
@ -174,6 +158,50 @@ ApplicationWindow {
|
|||||||
return wallet_path;
|
return wallet_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onWalletOpened(wallet) {
|
||||||
|
console.log(">>> wallet opened: " + wallet)
|
||||||
|
|
||||||
|
if (wallet.status !== Wallet.Status_Ok) {
|
||||||
|
if (!appWindow.walletOpeningWithPassword) {
|
||||||
|
console.error("Error opening wallet with empty password: ", wallet.errorString);
|
||||||
|
console.log("closing wallet async...")
|
||||||
|
walletManager.closeWalletAsync(wallet)
|
||||||
|
// try to open wallet with password;
|
||||||
|
appWindow.walletOpeningWithPassword = true
|
||||||
|
passwordDialog.open();
|
||||||
|
} else {
|
||||||
|
// opening with password but password doesn't match
|
||||||
|
console.error("Error opening wallet with password: ", wallet.errorString);
|
||||||
|
informationPopup.title = qsTr("Error") + translationManager.emptyString;
|
||||||
|
informationPopup.text = qsTr("Couldn't open wallet: ") + wallet.errorString;
|
||||||
|
informationPopup.icon = StandardIcon.Critical
|
||||||
|
informationPopup.open()
|
||||||
|
informationPopup.onCloseCallback = appWindow.initialize
|
||||||
|
walletManager.closeWallet(wallet);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// wallet opened successfully, subscribing for wallet updates
|
||||||
|
currentWallet = wallet
|
||||||
|
// wallet.updated.connect(appWindow.onWalletUpdate)
|
||||||
|
// wallet.refreshed.connect(appWindow.onWalletRefresh)
|
||||||
|
// currentWallet.refreshed.connect(onWalletRefresh)
|
||||||
|
var connectResult = currentWallet.refreshed.connect(function() {
|
||||||
|
console.log("QML: refreshed")
|
||||||
|
})
|
||||||
|
|
||||||
|
console.log("connected to refreshed: " + connectResult);
|
||||||
|
currentWallet.updated.connect(onWalletUpdate)
|
||||||
|
console.log("initializing with daemon address: ", persistentSettings.daemon_address)
|
||||||
|
currentWallet.initAsync(persistentSettings.daemon_address, 0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function onWalletClosed(walletAddress) {
|
||||||
|
console.log(">>> wallet closed: " + walletAddress)
|
||||||
|
}
|
||||||
|
|
||||||
function onWalletUpdate() {
|
function onWalletUpdate() {
|
||||||
console.log(">>> wallet updated")
|
console.log(">>> wallet updated")
|
||||||
@ -283,6 +311,9 @@ ApplicationWindow {
|
|||||||
x = (Screen.width - width) / 2
|
x = (Screen.width - width) / 2
|
||||||
y = (Screen.height - height) / 2
|
y = (Screen.height - height) / 2
|
||||||
//
|
//
|
||||||
|
walletManager.walletOpened.connect(onWalletOpened);
|
||||||
|
walletManager.walletClosed.connect(onWalletClosed);
|
||||||
|
|
||||||
rootItem.state = walletsFound() ? "normal" : "wizard";
|
rootItem.state = walletsFound() ? "normal" : "wizard";
|
||||||
if (rootItem.state === "normal") {
|
if (rootItem.state === "normal") {
|
||||||
initialize(persistentSettings)
|
initialize(persistentSettings)
|
||||||
@ -342,16 +373,8 @@ ApplicationWindow {
|
|||||||
var wallet_path = walletPath();
|
var wallet_path = walletPath();
|
||||||
console.log("opening wallet with password: ", wallet_path);
|
console.log("opening wallet with password: ", wallet_path);
|
||||||
|
|
||||||
wallet = walletManager.openWallet(wallet_path, password, persistentSettings.testnet);
|
walletManager.openWalletAsync(wallet_path, password, persistentSettings.testnet);
|
||||||
if (wallet.status !== Wallet.Status_Ok) {
|
|
||||||
console.error("Error opening wallet with password: ", wallet.errorString);
|
|
||||||
informationPopup.title = qsTr("Error") + translationManager.emptyString;
|
|
||||||
informationPopup.text = qsTr("Couldn't open wallet: ") + wallet.errorString;
|
|
||||||
informationPopup.icon = StandardIcon.Critical
|
|
||||||
informationPopup.open()
|
|
||||||
informationPopup.onCloseCallback = appWindow.initialize
|
|
||||||
walletManager.closeWallet(wallet);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
onRejected: {
|
onRejected: {
|
||||||
appWindow.enableUI(false)
|
appWindow.enableUI(false)
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
#include <QtConcurrent/QtConcurrent>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -42,6 +43,20 @@ Wallet *WalletManager::openWallet(const QString &path, const QString &password,
|
|||||||
return wallet;
|
return wallet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WalletManager::openWalletAsync(const QString &path, const QString &password, bool testnet)
|
||||||
|
{
|
||||||
|
QFuture<Wallet*> future = QtConcurrent::run(this, &WalletManager::openWallet,
|
||||||
|
path, password, testnet);
|
||||||
|
QFutureWatcher<Wallet*> * watcher = new QFutureWatcher<Wallet*>();
|
||||||
|
watcher->setFuture(future);
|
||||||
|
connect(watcher, &QFutureWatcher<Wallet*>::finished,
|
||||||
|
this, [this, watcher]() {
|
||||||
|
QFuture<Wallet*> future = watcher->future();
|
||||||
|
watcher->deleteLater();
|
||||||
|
emit walletOpened(future.result());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Wallet *WalletManager::recoveryWallet(const QString &path, const QString &memo, bool testnet)
|
Wallet *WalletManager::recoveryWallet(const QString &path, const QString &memo, bool testnet)
|
||||||
{
|
{
|
||||||
@ -51,9 +66,26 @@ Wallet *WalletManager::recoveryWallet(const QString &path, const QString &memo,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void WalletManager::closeWallet(Wallet *wallet)
|
QString WalletManager::closeWallet(Wallet *wallet)
|
||||||
{
|
{
|
||||||
|
QString result = wallet->address();
|
||||||
delete wallet;
|
delete wallet;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WalletManager::closeWalletAsync(Wallet *wallet)
|
||||||
|
{
|
||||||
|
QFuture<QString> future = QtConcurrent::run(this, &WalletManager::closeWallet,
|
||||||
|
wallet);
|
||||||
|
QFutureWatcher<QString> * watcher = new QFutureWatcher<QString>();
|
||||||
|
watcher->setFuture(future);
|
||||||
|
|
||||||
|
connect(watcher, &QFutureWatcher<QString>::finished,
|
||||||
|
this, [this, watcher]() {
|
||||||
|
QFuture<QString> future = watcher->future();
|
||||||
|
watcher->deleteLater();
|
||||||
|
emit future.result();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WalletManager::walletExists(const QString &path) const
|
bool WalletManager::walletExists(const QString &path) const
|
||||||
|
@ -16,15 +16,38 @@ public:
|
|||||||
// wizard: createWallet path;
|
// wizard: createWallet path;
|
||||||
Q_INVOKABLE Wallet * createWallet(const QString &path, const QString &password,
|
Q_INVOKABLE Wallet * createWallet(const QString &path, const QString &password,
|
||||||
const QString &language, bool testnet = false);
|
const QString &language, bool testnet = false);
|
||||||
// just for future use
|
|
||||||
|
/*!
|
||||||
|
* \brief openWallet - opens wallet by given path
|
||||||
|
* \param path - wallet filename
|
||||||
|
* \param password - wallet password. Empty string in wallet isn't password protected
|
||||||
|
* \param testnet - determines if we running testnet
|
||||||
|
* \return wallet object pointer
|
||||||
|
*/
|
||||||
Q_INVOKABLE Wallet * openWallet(const QString &path, const QString &password, bool testnet = false);
|
Q_INVOKABLE Wallet * openWallet(const QString &path, const QString &password, bool testnet = false);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief openWalletAsync - asynchronous version of "openWallet". Returns immediately. "walletOpened" signal
|
||||||
|
* emitted when wallet opened;
|
||||||
|
*/
|
||||||
|
Q_INVOKABLE void openWalletAsync(const QString &path, const QString &password, bool testnet = false);
|
||||||
|
|
||||||
// wizard: recoveryWallet path; hint: internally it recorvers wallet and set password = ""
|
// wizard: recoveryWallet path; hint: internally it recorvers wallet and set password = ""
|
||||||
Q_INVOKABLE Wallet * recoveryWallet(const QString &path, const QString &memo,
|
Q_INVOKABLE Wallet * recoveryWallet(const QString &path, const QString &memo,
|
||||||
bool testnet = false);
|
bool testnet = false);
|
||||||
|
|
||||||
//! utils: close wallet to free memory
|
/*!
|
||||||
Q_INVOKABLE void closeWallet(Wallet * wallet);
|
* \brief closeWallet - closes wallet and frees memory
|
||||||
|
* \param wallet
|
||||||
|
* \return wallet address
|
||||||
|
*/
|
||||||
|
Q_INVOKABLE QString closeWallet(Wallet * wallet);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief closeWalletAsync - asynchronous version of "closeWallet"
|
||||||
|
* \param wallet - wallet pointer;
|
||||||
|
*/
|
||||||
|
Q_INVOKABLE void closeWalletAsync(Wallet * wallet);
|
||||||
|
|
||||||
//! checks is given filename is a wallet;
|
//! checks is given filename is a wallet;
|
||||||
Q_INVOKABLE bool walletExists(const QString &path) const;
|
Q_INVOKABLE bool walletExists(const QString &path) const;
|
||||||
@ -50,8 +73,10 @@ public:
|
|||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
public slots:
|
void walletOpened(Wallet * wallet);
|
||||||
|
void walletClosed(const QString &walletAddress);
|
||||||
|
|
||||||
|
public slots:
|
||||||
private:
|
private:
|
||||||
|
|
||||||
explicit WalletManager(QObject *parent = 0);
|
explicit WalletManager(QObject *parent = 0);
|
||||||
|
Loading…
Reference in New Issue
Block a user