wizard: fix restore from key and seed functionality

This commit is contained in:
mmbyday 2019-02-22 18:26:51 -08:00
parent c2889c2b81
commit 08ec5e99ac
5 changed files with 65 additions and 16 deletions

View file

@ -3,18 +3,18 @@
function updateFromQrCode(address, payment_id, amount, tx_description, recipient_name, extra_parameters) {
// Switch to recover from keys
recoverFromSeedMode = false
spendkey.text = ""
spendKeyLine.text = ""
viewKeyLine.text = ""
restoreHeightItem.text = ""
restoreHeight.text = ""
if(typeof extra_parameters.secret_view_key != "undefined") {
viewKeyLine.text = extra_parameters.secret_view_key
}
if(typeof extra_parameters.secret_spend_key != "undefined") {
spendkey.text = extra_parameters.secret_spend_key
spendKeyLine.text = extra_parameters.secret_spend_key
}
if(typeof extra_parameters.restore_height != "undefined") {
restoreHeightItem.text = extra_parameters.restore_height
restoreHeight.text = extra_parameters.restore_height
}
addressLine.text = address
@ -170,12 +170,14 @@ function checkSeed(seed) {
}
function restoreWalletCheckViewSpendAddress(walletmanager, nettype, viewkey, spendkey, addressline){
var addressOK = (viewkey.length > 0 || spendkey.length > 0) ? walletmanager.addressValid(addressline, nettype) : false
var viewKeyOK = (viewkey.length > 0) ? walletmanager.keyValid(viewkey, addressline, true, nettype) : true
// Spendkey is optional
var spendKeyOK = (spendkey.length > 0) ? walletmanager.keyValid(spendkey, addressline, false, nettype) : true
return addressOK && viewKeyOK && spendKeyOK
var results = [];
// addressOK
results[0] = walletmanager.addressValid(addressline, nettype);
// viewKeyOK
results[1] = walletmanager.keyValid(viewkey, addressline, true, nettype);
// spendKeyOK, Spendkey is optional
results[2] = walletmanager.keyValid(spendkey, addressline, false, nettype);
return results;
}
//usage: getApproximateBlockchainHeight("March 18 2016") or getApproximateBlockchainHeight("2016-11-11")

View file

@ -76,6 +76,9 @@ Rectangle {
property string walletOptionsLocation: ''
property string walletOptionsPassword: ''
property string walletOptionsSeed: ''
property string walletOptionsRecoverAddress: ''
property string walletOptionsRecoverViewkey: ''
property string walletOptionsRecoverSpendkey: ''
property string walletOptionsBackup: ''
property int walletOptionsRestoreHeight: 0
property string walletOptionsBootstrapAddress: persistentSettings.bootstrapNodeAddress
@ -307,7 +310,7 @@ Rectangle {
oshelper.removeTemporaryWallet(wizardController.tmpWalletFilename)
// protecting wallet with password
m_wallet.setPassword(walletOptionsPassword);
wizardController.m_wallet.setPassword(walletOptionsPassword);
// Store password in session to be able to use password protected functions (e.g show seed)
appWindow.walletPassword = walletOptionsPassword
@ -325,6 +328,40 @@ Rectangle {
persistentSettings.is_recovering_from_device = (wizardController.walletOptionsIsRecoveringFromDevice === undefined) ? false : wizardController.walletOptionsIsRecoveringFromDevice
}
function recoveryWallet() {
var nettype = persistentSettings.nettype;
var kdfRounds = persistentSettings.kdfRounds;
var restoreHeight = wizardController.walletOptionsRestoreHeight;
var tmp_wallet_filename = oshelper.temporaryFilename()
console.log("Creating temporary wallet", tmp_wallet_filename)
// delete the temporary wallet object before creating new
if (typeof wizardController.m_wallet !== 'undefined') {
walletManager.closeWallet()
console.log("deleting temporary wallet")
}
var wallet = ''
// From seed or keys
if(wizardController.walletRestoreMode === 'seed')
wallet = walletManager.recoveryWallet(tmp_wallet_filename, wizardController.walletOptionsSeed, nettype, restoreHeight, kdfRounds)
else
wallet = walletManager.createWalletFromKeys(tmp_wallet_filename, wizardController.language_wallet, nettype,
wizardController.walletOptionsRecoverAddress, wizardController.walletOptionsRecoverViewkey,
wizardController.walletOptionsRecoverSpendkey, restoreHeight, kdfRounds)
var success = wallet.status === Wallet.Status_Ok;
if (success) {
wizardController.m_wallet = wallet;
wizardController.walletOptionsIsRecovering = true;
wizardController.tmpWalletFilename = tmp_wallet_filename
} else {
console.log(wallet.errorString)
appWindow.showStatusMessage(qsTr(wallet.errorString), 5);
walletManager.closeWallet();
}
return success;
}
function createWalletFromDevice() {
// TODO: create wallet in temporary filename and a) move it to the path specified by user after the final
// page submitted or b) delete it when program closed before reaching final page

View file

@ -128,7 +128,6 @@ Rectangle {
onMenuClicked: {
wizardController.restart();
wizardController.createWallet();
wizardStateView.state = "wizardRestoreWallet1"
}
}

View file

@ -75,8 +75,7 @@ Rectangle {
viewKeyLine.error = !result[1] && viewKeyLineLength != 0
spendKeyLine.error = !result[2] && spendKeyLineLength != 0
return (!addressLine.error && !viewKeyLine.error && !spendKeyLine.error &&
addressLineLength != 0 && viewKeyLineLength != 0 && spendKeyLineLength != 0)
return (result[0] && result[1] && result[2])
}
function checkRestoreHeight() {
@ -273,7 +272,17 @@ Rectangle {
onNextClicked: {
wizardController.walletOptionsName = wizardWalletInput.walletName.text;
wizardController.walletOptionsLocation = wizardWalletInput.walletLocation.text;
switch (wizardController.walletRestoreMode) {
case 'seed':
wizardController.walletOptionsSeed = seedInput.text;
break;
default: // walletRestoreMode = keys or qr
wizardController.walletOptionsRecoverAddress = addressLine.text;
wizardController.walletOptionsRecoverViewkey = viewKeyLine.text
wizardController.walletOptionsRecoverSpendkey = spendKeyLine.text;
break;
}
var _restoreHeight = 0;
if(restoreHeight.text){
@ -299,6 +308,7 @@ Rectangle {
seedInput.text = "";
addressLine.text = "";
spendKeyLine.text = "";
viewKeyLine.text = "";
restoreHeight.text = "";
}
}

View file

@ -75,6 +75,7 @@ Rectangle {
}
}
onNextClicked: {
wizardController.recoveryWallet();
wizardController.writeWallet();
wizardController.useMoneroClicked();
}