WalletManager::openWalletAsync integrating with UI

This commit is contained in:
Ilya Kitaev 2016-08-19 14:44:44 +03:00
parent d3234bb915
commit 8d93f01db4
5 changed files with 50 additions and 38 deletions

View file

@ -52,8 +52,6 @@ ApplicationWindow {
property var currentWallet; property var currentWallet;
property var transaction; property var transaction;
property alias password : passwordDialog.password property alias password : passwordDialog.password
property bool walletOpeningWithPassword: false
function altKeyReleased() { ctrlPressed = false; } function altKeyReleased() { ctrlPressed = false; }
@ -140,18 +138,27 @@ ApplicationWindow {
basicPanel.paymentClicked.connect(handlePayment); basicPanel.paymentClicked.connect(handlePayment);
// wallet already opened with wizard, we just need to initialize it
if (typeof wizard.settings['wallet'] !== 'undefined') { if (typeof wizard.settings['wallet'] !== 'undefined') {
wallet = wizard.settings['wallet']; connectWallet(wizard.settings['wallet'])
} else { } else {
var wallet_path = walletPath(); var wallet_path = walletPath();
console.log("opening wallet at: ", wallet_path, "with password: ", appWindow.password);
console.log("opening wallet at: ", wallet_path);
walletManager.openWalletAsync(wallet_path, appWindow.password, walletManager.openWalletAsync(wallet_path, appWindow.password,
persistentSettings.testnet); persistentSettings.testnet);
} }
} }
function connectWallet(wallet) {
currentWallet = wallet
currentWallet.refreshed.connect(onWalletRefresh)
currentWallet.updated.connect(onWalletUpdate)
console.log("initializing with daemon address: ", persistentSettings.daemon_address)
currentWallet.initAsync(persistentSettings.daemon_address, 0);
}
function walletPath() { function walletPath() {
var wallet_path = persistentSettings.wallet_path + "/" + persistentSettings.account_name + "/" var wallet_path = persistentSettings.wallet_path + "/" + persistentSettings.account_name + "/"
+ persistentSettings.account_name; + persistentSettings.account_name;
@ -162,39 +169,32 @@ ApplicationWindow {
console.log(">>> wallet opened: " + wallet) console.log(">>> wallet opened: " + wallet)
if (wallet.status !== Wallet.Status_Ok) { if (wallet.status !== Wallet.Status_Ok) {
if (!appWindow.walletOpeningWithPassword) { if (appWindow.password === '') {
console.error("Error opening wallet with empty password: ", wallet.errorString); console.error("Error opening wallet with empty password: ", wallet.errorString);
console.log("closing wallet async...") console.log("closing wallet async : " + wallet.address)
walletManager.closeWalletAsync(wallet) walletManager.closeWalletAsync(wallet)
// try to open wallet with password; // try to open wallet with password;
appWindow.walletOpeningWithPassword = true
passwordDialog.open(); passwordDialog.open();
} else { } else {
// opening with password but password doesn't match // opening with password but password doesn't match
console.error("Error opening wallet with password: ", wallet.errorString); console.error("Error opening wallet with password: ", wallet.errorString);
informationPopup.title = qsTr("Error") + translationManager.emptyString; informationPopup.title = qsTr("Error") + translationManager.emptyString;
informationPopup.text = qsTr("Couldn't open wallet: ") + wallet.errorString; informationPopup.text = qsTr("Couldn't open wallet: ") + wallet.errorString;
informationPopup.icon = StandardIcon.Critical informationPopup.icon = StandardIcon.Critical
console.log("closing wallet async : " + wallet.address)
walletManager.closeWalletAsync(wallet);
informationPopup.open() informationPopup.open()
informationPopup.onCloseCallback = appWindow.initialize informationPopup.onCloseCallback = function() {
walletManager.closeWallet(wallet); passwordDialog.open()
}
} }
return; return;
} }
// wallet opened successfully, subscribing for wallet updates // wallet opened successfully, subscribing for wallet updates
currentWallet = wallet connectWallet(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);
} }
@ -205,14 +205,14 @@ ApplicationWindow {
function onWalletUpdate() { function onWalletUpdate() {
console.log(">>> wallet updated") console.log(">>> wallet updated")
basicPanel.unlockedBalanceText = leftPanel.unlockedBalanceText = walletManager.displayAmount(wallet.unlockedBalance); basicPanel.unlockedBalanceText = leftPanel.unlockedBalanceText =
basicPanel.balanceText = leftPanel.balanceText = walletManager.displayAmount(wallet.balance); walletManager.displayAmount(currentWallet.unlockedBalance);
basicPanel.balanceText = leftPanel.balanceText = walletManager.displayAmount(currentWallet.balance);
} }
function onWalletRefresh() { function onWalletRefresh() {
console.log(">>> wallet refreshed") console.log(">>> wallet refreshed")
leftPanel.networkStatus.connected = wallet.connected leftPanel.networkStatus.connected = currentWallet.connected
onWalletUpdate(); onWalletUpdate();
} }
@ -369,12 +369,12 @@ ApplicationWindow {
id: passwordDialog id: passwordDialog
standardButtons: StandardButton.Ok + StandardButton.Cancel standardButtons: StandardButton.Ok + StandardButton.Cancel
onAccepted: { onAccepted: {
appWindow.currentWallet = null
appWindow.initialize();
var wallet_path = walletPath(); // var wallet_path = walletPath();
console.log("opening wallet with password: ", wallet_path); // console.log("opening wallet with password: ", wallet_path);
// walletManager.openWalletAsync(wallet_path, password, persistentSettings.testnet);
walletManager.openWalletAsync(wallet_path, password, persistentSettings.testnet);
} }
onRejected: { onRejected: {
appWindow.enableUI(false) appWindow.enableUI(false)

View file

@ -40,6 +40,13 @@ Wallet *WalletManager::openWallet(const QString &path, const QString &password,
Bitmonero::Wallet * w = m_pimpl->openWallet(path.toStdString(), password.toStdString(), testnet); Bitmonero::Wallet * w = m_pimpl->openWallet(path.toStdString(), password.toStdString(), testnet);
Wallet * wallet = new Wallet(w); Wallet * wallet = new Wallet(w);
// move wallet to the GUI thread. Otherwise it wont be emitting signals
if (wallet->thread() != qApp->thread()) {
wallet->moveToThread(qApp->thread());
}
return wallet; return wallet;
} }
@ -84,7 +91,7 @@ void WalletManager::closeWalletAsync(Wallet *wallet)
this, [this, watcher]() { this, [this, watcher]() {
QFuture<QString> future = watcher->future(); QFuture<QString> future = watcher->future();
watcher->deleteLater(); watcher->deleteLater();
emit future.result(); emit walletClosed(future.result());
}); });
} }

View file

@ -29,6 +29,7 @@
import QtQuick 2.2 import QtQuick 2.2
import moneroComponents 1.0 import moneroComponents 1.0
import QtQuick.Dialogs 1.2 import QtQuick.Dialogs 1.2
import 'utils.js' as Utils
Item { Item {
opacity: 0 opacity: 0
@ -54,7 +55,7 @@ Item {
} }
function checkNextButton() { function checkNextButton() {
var wordsArray = cleanWordsInput(uiItem.wordsTextItem.memoText).split(" "); var wordsArray = Utils.lineBreaksToSpaces(uiItem.wordsTextItem.memoText).split(" ");
wizard.nextButton.enabled = wordsArray.length === 25; wizard.nextButton.enabled = wordsArray.length === 25;
} }

View file

@ -30,6 +30,7 @@ import QtQuick 2.2
import moneroComponents 1.0 import moneroComponents 1.0
import QtQuick.Dialogs 1.2 import QtQuick.Dialogs 1.2
import Bitmonero.Wallet 1.0 import Bitmonero.Wallet 1.0
import 'utils.js' as Utils
Item { Item {
opacity: 0 opacity: 0
@ -46,13 +47,13 @@ Item {
} }
function checkNextButton() { function checkNextButton() {
var wordsArray = cleanWordsInput(uiItem.wordsTextItem.memoText).split(" "); var wordsArray = Utils.lineBreaksToSpaces(uiItem.wordsTextItem.memoText).split(" ");
wizard.nextButton.enabled = wordsArray.length === 25; wizard.nextButton.enabled = wordsArray.length === 25;
} }
function onPageClosed(settingsObject) { function onPageClosed(settingsObject) {
settingsObject['account_name'] = uiItem.accountNameText settingsObject['account_name'] = uiItem.accountNameText
settingsObject['words'] = cleanWordsInput(uiItem.wordsTextItem.memoText) settingsObject['words'] = Utils.lineBreaksToSpaces(uiItem.wordsTextItem.memoText)
settingsObject['wallet_path'] = uiItem.walletPath settingsObject['wallet_path'] = uiItem.walletPath
return recoveryWallet(settingsObject) return recoveryWallet(settingsObject)
} }
@ -69,9 +70,7 @@ Item {
return success; return success;
} }
function cleanWordsInput(text) {
return text.trim().replace(/(\r\n|\n|\r)/gm, " ");
}
WizardManageWalletUI { WizardManageWalletUI {
id: uiItem id: uiItem

View file

@ -42,3 +42,8 @@ function mapScope (inputScopeFrom, inputScopeTo, outputScopeFrom, outputScopeTo,
function tr(text) { function tr(text) {
return qsTr(text) + translationManager.emptyString return qsTr(text) + translationManager.emptyString
} }
function lineBreaksToSpaces(text) {
return text.trim().replace(/(\r\n|\n|\r)/gm, " ");
}