"new wallet" and "recovery wallet" flows are implemented using libwallet

api
This commit is contained in:
Ilya Kitaev 2016-06-14 16:09:14 +03:00
parent b7787dc670
commit 1eac46ae73
8 changed files with 61 additions and 27 deletions

View file

@ -47,7 +47,7 @@ int main(int argc, char *argv[])
app.installEventFilter(eventFilter);
qmlRegisterType<clipboardAdapter>("moneroComponents", 1, 0, "Clipboard");
qmlRegisterInterface<Wallet>("Wallet");
qmlRegisterUncreatableType<Wallet>("Bitmonero.Wallet", 1, 0, "Wallet", "Wallet can't be instantiated directly");
QQmlApplicationEngine engine;

View file

@ -46,10 +46,7 @@ Item {
settingsObject['account_name'] = uiItem.accountNameText
settingsObject['words'] = uiItem.wordsTexttext
settingsObject['wallet_path'] = uiItem.walletPath
// put wallet files to the subdirectory with the same name as
// wallet name
return true;
}
//! function called each time we hide this page

View file

@ -43,22 +43,9 @@ Item {
settingsObject['auto_donations_amount'] = autoDonationAmountText.text;
settingsObject['allow_background_mining'] = allowBackgroundMiningCheckBox.checked;
// here we need to actually move wallet to the new location
// put wallet files to the subdirectory with the same name as
// wallet name
var new_wallet_filename = settingsObject.wallet_path + "/"
+ settingsObject.account_name + "/"
+ settingsObject.account_name;
// moving wallet files to the new destination, if user changed it
if (new_wallet_filename !== settingsObject.wallet_filename) {
// using previously saved wallet;
settingsObject.wallet.store(new_wallet_filename);
//walletManager.moveWallet(settingsObject.wallet_filename, new_wallet_filename);
}
// saving wallet_filename;
settingsObject['wallet_filename'] = new_wallet_filename;
return true;
}
Row {

View file

@ -53,6 +53,8 @@ Item {
+ buildSettingsString();
}
Row {
id: dotsRow
anchors.top: parent.top

View file

@ -49,8 +49,12 @@ Rectangle {
function switchPage(next) {
// save settings for current page;
if (typeof pages[currentPage].onPageClosed !== 'undefined') {
pages[currentPage].onPageClosed(settings);
if (next && typeof pages[currentPage].onPageClosed !== 'undefined') {
if (pages[currentPage].onPageClosed(settings) !== true) {
print ("Can't go to the next page");
return;
};
}
print ("switchpage: start: currentPage: ", currentPage);
@ -59,6 +63,10 @@ Rectangle {
var step_value = next ? 1 : -1
currentPage += step_value
pages[currentPage].opacity = 1;
if (next && typeof pages[currentPage].onPageOpened !== 'undefined') {
pages[currentPage].onPageOpened(settings)
}
handlePageChanged();
}
}
@ -84,7 +92,7 @@ Rectangle {
break;
case recoveryWalletPage:
// TODO: disable "next button" until 25 words private key entered
// nextButton.enabled = false;
nextButton.enabled = false
break
default:
nextButton.enabled = true
@ -115,6 +123,27 @@ Rectangle {
handlePageChanged()
}
//! actually writes the wallet
function applySettings() {
print ("Here we apply the settings");
// here we need to actually move wallet to the new location
// put wallet files to the subdirectory with the same name as
// wallet name
var new_wallet_filename = settings.wallet_path + "/"
+ settings.account_name + "/"
+ settings.account_name;
// moving wallet files to the new destination, if user changed it
if (new_wallet_filename !== settings.wallet_filename) {
// using previously saved wallet;
settings.wallet.store(new_wallet_filename);
//walletManager.moveWallet(settingsObject.wallet_filename, new_wallet_filename);
}
// saving wallet_filename;
settings['wallet_filename'] = new_wallet_filename;
}
@ -255,6 +284,9 @@ Rectangle {
releasedColor: "#FF6C3C"
pressedColor: "#FF4304"
visible: parent.paths[currentPath][currentPage] === finishPage
onClicked: wizard.useMoneroClicked()
onClicked: {
wizard.applySettings();
wizard.useMoneroClicked()
}
}
}

View file

@ -45,6 +45,7 @@ Item {
function onPageClosed(settingsObject) {
settingsObject.wallet.setPassword(passwordItem.password)
return true
}
function handlePassword() {

View file

@ -29,6 +29,7 @@
import QtQuick 2.2
import moneroComponents 1.0
import QtQuick.Dialogs 1.2
import Bitmonero.Wallet 1.0
Item {
opacity: 0
@ -42,12 +43,25 @@ Item {
function onPageClosed(settingsObject) {
settingsObject['account_name'] = uiItem.accountNameText
settingsObject['words'] = uiItem.wordsTexttext
settingsObject['words'] = cleanWordsInput(uiItem.wordsTextItem.memoText)
settingsObject['wallet_path'] = uiItem.walletPath
return recoveryWallet(settingsObject)
}
function recoveryWallet() {
function recoveryWallet(settingsObject) {
var testnet = true;
var wallet = walletManager.recoveryWallet(oshelper.temporaryFilename(), settingsObject.words, testnet);
var success = wallet.status === Wallet.Status_Ok;
if (success) {
settingsObject['wallet'] = wallet;
} else {
walletManager.closeWallet(wallet);
}
return success;
}
function cleanWordsInput(text) {
return text.trim().replace(/(\r\n|\n|\r)/gm, " ");
}
WizardManageWalletUI {
@ -60,8 +74,8 @@ Item {
wordsTextItem.memoTextReadOnly: false
wordsTextItem.memoText: ""
wordsTextItem.onMemoTextChanged: {
var wordsArray = wordsTextItem.memoText.trim().split(" ")
//wizard.nextButton.enabled = wordsArray.length === 25
var wordsArray = cleanWordsInput(wordsTextItem.memoText).split(" ");
wizard.nextButton.enabled = wordsArray.length === 25
}
}
}

View file

@ -41,6 +41,7 @@ Item {
settingsObject['language'] = lang.display_name;
settingsObject['wallet_language'] = lang.wallet_name;
settingsObject['locale'] = lang.locale;
return true
}
Column {