"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); app.installEventFilter(eventFilter);
qmlRegisterType<clipboardAdapter>("moneroComponents", 1, 0, "Clipboard"); qmlRegisterType<clipboardAdapter>("moneroComponents", 1, 0, "Clipboard");
qmlRegisterInterface<Wallet>("Wallet"); qmlRegisterUncreatableType<Wallet>("Bitmonero.Wallet", 1, 0, "Wallet", "Wallet can't be instantiated directly");
QQmlApplicationEngine engine; QQmlApplicationEngine engine;

View file

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

View file

@ -43,22 +43,9 @@ Item {
settingsObject['auto_donations_amount'] = autoDonationAmountText.text; settingsObject['auto_donations_amount'] = autoDonationAmountText.text;
settingsObject['allow_background_mining'] = allowBackgroundMiningCheckBox.checked; 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; return true;
settingsObject['wallet_filename'] = new_wallet_filename;
} }
Row { Row {

View file

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

View file

@ -49,8 +49,12 @@ Rectangle {
function switchPage(next) { function switchPage(next) {
// save settings for current page; // save settings for current page;
if (typeof pages[currentPage].onPageClosed !== 'undefined') { if (next && typeof pages[currentPage].onPageClosed !== 'undefined') {
pages[currentPage].onPageClosed(settings); if (pages[currentPage].onPageClosed(settings) !== true) {
print ("Can't go to the next page");
return;
};
} }
print ("switchpage: start: currentPage: ", currentPage); print ("switchpage: start: currentPage: ", currentPage);
@ -59,6 +63,10 @@ Rectangle {
var step_value = next ? 1 : -1 var step_value = next ? 1 : -1
currentPage += step_value currentPage += step_value
pages[currentPage].opacity = 1; pages[currentPage].opacity = 1;
if (next && typeof pages[currentPage].onPageOpened !== 'undefined') {
pages[currentPage].onPageOpened(settings)
}
handlePageChanged(); handlePageChanged();
} }
} }
@ -84,7 +92,7 @@ Rectangle {
break; break;
case recoveryWalletPage: case recoveryWalletPage:
// TODO: disable "next button" until 25 words private key entered // TODO: disable "next button" until 25 words private key entered
// nextButton.enabled = false; nextButton.enabled = false
break break
default: default:
nextButton.enabled = true nextButton.enabled = true
@ -115,6 +123,27 @@ Rectangle {
handlePageChanged() 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" releasedColor: "#FF6C3C"
pressedColor: "#FF4304" pressedColor: "#FF4304"
visible: parent.paths[currentPath][currentPage] === finishPage visible: parent.paths[currentPath][currentPage] === finishPage
onClicked: wizard.useMoneroClicked() onClicked: {
wizard.applySettings();
wizard.useMoneroClicked()
}
} }
} }

View file

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

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 Bitmonero.Wallet 1.0
Item { Item {
opacity: 0 opacity: 0
@ -42,12 +43,25 @@ Item {
function onPageClosed(settingsObject) { function onPageClosed(settingsObject) {
settingsObject['account_name'] = uiItem.accountNameText settingsObject['account_name'] = uiItem.accountNameText
settingsObject['words'] = uiItem.wordsTexttext settingsObject['words'] = cleanWordsInput(uiItem.wordsTextItem.memoText)
settingsObject['wallet_path'] = uiItem.walletPath 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 { WizardManageWalletUI {
@ -60,8 +74,8 @@ Item {
wordsTextItem.memoTextReadOnly: false wordsTextItem.memoTextReadOnly: false
wordsTextItem.memoText: "" wordsTextItem.memoText: ""
wordsTextItem.onMemoTextChanged: { wordsTextItem.onMemoTextChanged: {
var wordsArray = wordsTextItem.memoText.trim().split(" ") var wordsArray = cleanWordsInput(wordsTextItem.memoText).split(" ");
//wizard.nextButton.enabled = wordsArray.length === 25 wizard.nextButton.enabled = wordsArray.length === 25
} }
} }
} }

View file

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