1
mirror of https://github.com/monero-project/monero-gui synced 2024-12-26 01:23:44 +01:00

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 transaction;
property alias password : passwordDialog.password
property bool walletOpeningWithPassword: false
function altKeyReleased() { ctrlPressed = false; }
@ -140,18 +138,27 @@ ApplicationWindow {
basicPanel.paymentClicked.connect(handlePayment);
// wallet already opened with wizard, we just need to initialize it
if (typeof wizard.settings['wallet'] !== 'undefined') {
wallet = wizard.settings['wallet'];
connectWallet(wizard.settings['wallet'])
} else {
var wallet_path = walletPath();
console.log("opening wallet at: ", wallet_path);
console.log("opening wallet at: ", wallet_path, "with password: ", appWindow.password);
walletManager.openWalletAsync(wallet_path, appWindow.password,
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() {
var wallet_path = persistentSettings.wallet_path + "/" + persistentSettings.account_name + "/"
+ persistentSettings.account_name;
@ -162,39 +169,32 @@ ApplicationWindow {
console.log(">>> wallet opened: " + wallet)
if (wallet.status !== Wallet.Status_Ok) {
if (!appWindow.walletOpeningWithPassword) {
if (appWindow.password === '') {
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)
// 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
console.log("closing wallet async : " + wallet.address)
walletManager.closeWalletAsync(wallet);
informationPopup.open()
informationPopup.onCloseCallback = appWindow.initialize
walletManager.closeWallet(wallet);
informationPopup.onCloseCallback = function() {
passwordDialog.open()
}
}
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);
connectWallet(wallet)
}
@ -205,14 +205,14 @@ ApplicationWindow {
function onWalletUpdate() {
console.log(">>> wallet updated")
basicPanel.unlockedBalanceText = leftPanel.unlockedBalanceText = walletManager.displayAmount(wallet.unlockedBalance);
basicPanel.balanceText = leftPanel.balanceText = walletManager.displayAmount(wallet.balance);
basicPanel.unlockedBalanceText = leftPanel.unlockedBalanceText =
walletManager.displayAmount(currentWallet.unlockedBalance);
basicPanel.balanceText = leftPanel.balanceText = walletManager.displayAmount(currentWallet.balance);
}
function onWalletRefresh() {
console.log(">>> wallet refreshed")
leftPanel.networkStatus.connected = wallet.connected
leftPanel.networkStatus.connected = currentWallet.connected
onWalletUpdate();
}
@ -369,12 +369,12 @@ ApplicationWindow {
id: passwordDialog
standardButtons: StandardButton.Ok + StandardButton.Cancel
onAccepted: {
appWindow.currentWallet = null
appWindow.initialize();
var wallet_path = walletPath();
console.log("opening wallet with password: ", wallet_path);
walletManager.openWalletAsync(wallet_path, password, persistentSettings.testnet);
// var wallet_path = walletPath();
// console.log("opening wallet with password: ", wallet_path);
// walletManager.openWalletAsync(wallet_path, password, persistentSettings.testnet);
}
onRejected: {
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);
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;
}
@ -84,7 +91,7 @@ void WalletManager::closeWalletAsync(Wallet *wallet)
this, [this, watcher]() {
QFuture<QString> future = watcher->future();
watcher->deleteLater();
emit future.result();
emit walletClosed(future.result());
});
}

View File

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

View File

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

View File

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