2019-01-14 01:02:44 +01:00
|
|
|
// Copyright (c) 2014-2019, The Monero Project
|
|
|
|
//
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without modification, are
|
|
|
|
// permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
|
|
|
// conditions and the following disclaimer.
|
|
|
|
//
|
|
|
|
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
|
|
|
// of conditions and the following disclaimer in the documentation and/or other
|
|
|
|
// materials provided with the distribution.
|
|
|
|
//
|
|
|
|
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
|
|
|
// used to endorse or promote products derived from this software without specific
|
|
|
|
// prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
|
|
|
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
|
|
|
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
|
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
|
|
|
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
2019-04-11 03:17:29 +02:00
|
|
|
import QtQuick 2.9
|
2019-01-14 01:02:44 +01:00
|
|
|
import QtQuick.Layouts 1.2
|
|
|
|
import QtQuick.Controls 2.0
|
|
|
|
|
|
|
|
import "../js/Wizard.js" as Wizard
|
2019-05-15 05:21:09 +02:00
|
|
|
import "../js/Utils.js" as Utils
|
2019-01-14 01:02:44 +01:00
|
|
|
import "../components" as MoneroComponents
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
id: wizardRestoreWallet1
|
|
|
|
|
|
|
|
color: "transparent"
|
2019-07-24 05:07:54 +02:00
|
|
|
property alias pageHeight: pageRoot.height
|
2019-04-06 00:07:03 +02:00
|
|
|
property string viewName: "wizardRestoreWallet1"
|
2019-01-14 01:02:44 +01:00
|
|
|
|
|
|
|
function verify() {
|
2018-12-15 02:28:07 +01:00
|
|
|
if (restoreHeight.text.indexOf('-') === 4 && restoreHeight.text.length !== 10) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
var valid = false;
|
2019-01-14 01:02:44 +01:00
|
|
|
if(wizardController.walletRestoreMode === "keys") {
|
2018-12-15 02:28:07 +01:00
|
|
|
valid = wizardRestoreWallet1.verifyFromKeys();
|
2019-01-14 01:02:44 +01:00
|
|
|
return valid;
|
|
|
|
} else if(wizardController.walletRestoreMode === "seed") {
|
2018-12-15 02:28:07 +01:00
|
|
|
valid = wizardWalletInput.verify();
|
2019-01-14 01:02:44 +01:00
|
|
|
if(!valid) return false;
|
|
|
|
valid = Wizard.checkSeed(seedInput.text);
|
|
|
|
return valid;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function verifyFromKeys() {
|
|
|
|
var result = Wizard.restoreWalletCheckViewSpendAddress(
|
|
|
|
walletManager,
|
|
|
|
persistentSettings.nettype,
|
|
|
|
viewKeyLine.text,
|
|
|
|
spendKeyLine.text,
|
|
|
|
addressLine.text
|
|
|
|
);
|
|
|
|
|
|
|
|
var addressLineLength = addressLine.text.length
|
|
|
|
var viewKeyLineLength = viewKeyLine.text.length
|
|
|
|
var spendKeyLineLength = spendKeyLine.text.length
|
|
|
|
|
|
|
|
addressLine.error = !result[0] && addressLineLength != 0
|
|
|
|
viewKeyLine.error = !result[1] && viewKeyLineLength != 0
|
|
|
|
spendKeyLine.error = !result[2] && spendKeyLineLength != 0
|
|
|
|
|
2019-04-21 22:09:12 +02:00
|
|
|
// allow valid viewOnly
|
|
|
|
if (spendKeyLine.text.length === 0)
|
|
|
|
return (result[0] && result[1])
|
|
|
|
|
2019-02-23 03:26:51 +01:00
|
|
|
return (result[0] && result[1] && result[2])
|
2019-01-14 01:02:44 +01:00
|
|
|
}
|
|
|
|
|
2018-12-15 02:28:07 +01:00
|
|
|
function checkRestoreHeight() {
|
|
|
|
return (parseInt(restoreHeight) >= 0 || restoreHeight === "") && restoreHeight.indexOf("-") === -1;
|
|
|
|
}
|
|
|
|
|
2019-01-14 01:02:44 +01:00
|
|
|
ColumnLayout {
|
2019-07-24 05:07:54 +02:00
|
|
|
id: pageRoot
|
2019-01-14 01:02:44 +01:00
|
|
|
Layout.alignment: Qt.AlignHCenter;
|
|
|
|
width: parent.width - 100
|
|
|
|
Layout.fillWidth: true
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter;
|
|
|
|
|
|
|
|
spacing: 0
|
|
|
|
|
|
|
|
ColumnLayout {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.topMargin: wizardController.wizardSubViewTopMargin
|
|
|
|
Layout.maximumWidth: wizardController.wizardSubViewWidth
|
|
|
|
Layout.alignment: Qt.AlignHCenter
|
2019-04-25 21:09:23 +02:00
|
|
|
spacing: 20
|
2019-01-14 01:02:44 +01:00
|
|
|
|
|
|
|
WizardHeader {
|
|
|
|
title: qsTr("Restore wallet") + translationManager.emptyString
|
|
|
|
subtitle: qsTr("Restore wallet from keys or mnemonic seed.") + translationManager.emptyString
|
|
|
|
}
|
|
|
|
|
|
|
|
WizardWalletInput{
|
|
|
|
id: wizardWalletInput
|
|
|
|
}
|
|
|
|
|
2019-07-31 18:14:13 +02:00
|
|
|
RowLayout {
|
|
|
|
Layout.topMargin: 10
|
|
|
|
spacing: 30
|
|
|
|
Layout.fillWidth: true
|
2019-01-14 01:02:44 +01:00
|
|
|
|
2019-07-31 18:14:13 +02:00
|
|
|
MoneroComponents.RadioButton {
|
|
|
|
id: seedRadioButton
|
2019-01-14 01:02:44 +01:00
|
|
|
text: qsTr("Restore from seed") + translationManager.emptyString
|
2019-07-31 18:14:13 +02:00
|
|
|
fontSize: 16
|
|
|
|
checked: true
|
2019-01-14 01:02:44 +01:00
|
|
|
onClicked: {
|
2019-07-31 18:14:13 +02:00
|
|
|
checked = true;
|
|
|
|
keysRadioButton.checked = false;
|
|
|
|
qrRadioButton.checked = false;
|
2019-01-14 01:02:44 +01:00
|
|
|
wizardController.walletRestoreMode = 'seed';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-31 18:14:13 +02:00
|
|
|
MoneroComponents.RadioButton {
|
|
|
|
id: keysRadioButton
|
2019-01-14 01:02:44 +01:00
|
|
|
text: qsTr("Restore from keys") + translationManager.emptyString
|
2019-07-31 18:14:13 +02:00
|
|
|
fontSize: 16
|
|
|
|
checked: false
|
2019-01-14 01:02:44 +01:00
|
|
|
onClicked: {
|
2019-07-31 18:14:13 +02:00
|
|
|
checked = true;
|
|
|
|
seedRadioButton.checked = false;
|
|
|
|
qrRadioButton.checked = false;
|
2019-01-14 01:02:44 +01:00
|
|
|
wizardController.walletRestoreMode = 'keys';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-31 18:14:13 +02:00
|
|
|
MoneroComponents.RadioButton {
|
|
|
|
id: qrRadioButton
|
|
|
|
text: qsTr("Restore from QR Code") + translationManager.emptyString
|
|
|
|
fontSize: 16
|
2019-01-14 01:02:44 +01:00
|
|
|
visible: appWindow.qrScannerEnabled
|
2019-07-31 18:14:13 +02:00
|
|
|
checked: false
|
2019-01-14 01:02:44 +01:00
|
|
|
onClicked: {
|
2019-07-31 18:14:13 +02:00
|
|
|
checked = true;
|
|
|
|
seedRadioButton.checked = false;
|
|
|
|
keysRadioButton.checked = false;
|
2019-01-14 01:02:44 +01:00
|
|
|
wizardController.walletRestoreMode = 'qr';
|
2019-07-31 18:14:13 +02:00
|
|
|
cameraUi.state = "Capture";
|
|
|
|
cameraUi.qrcode_decoded.connect(Wizard.updateFromQrCode);
|
2019-01-14 01:02:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ColumnLayout {
|
|
|
|
// seed textarea
|
|
|
|
visible: wizardController.walletRestoreMode === 'seed'
|
|
|
|
Layout.fillWidth: true
|
2020-02-12 00:34:15 +01:00
|
|
|
spacing: 10
|
2019-01-14 01:02:44 +01:00
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
color: "transparent"
|
|
|
|
radius: 4
|
|
|
|
|
2019-04-25 21:09:23 +02:00
|
|
|
Layout.preferredHeight: 100
|
2019-01-14 01:02:44 +01:00
|
|
|
Layout.fillWidth: true
|
|
|
|
|
|
|
|
border.width: 1
|
|
|
|
border.color: {
|
|
|
|
if(seedInput.text !== "" && seedInput.error){
|
|
|
|
return MoneroComponents.Style.inputBorderColorInvalid;
|
|
|
|
} else if(seedInput.activeFocus){
|
|
|
|
return MoneroComponents.Style.inputBorderColorActive;
|
|
|
|
} else {
|
|
|
|
return MoneroComponents.Style.inputBorderColorInActive;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-08 01:56:10 +01:00
|
|
|
MoneroComponents.InputMulti {
|
2019-01-14 01:02:44 +01:00
|
|
|
id: seedInput
|
|
|
|
property bool error: false
|
|
|
|
width: parent.width
|
2019-04-25 21:09:23 +02:00
|
|
|
height: 100
|
2019-01-14 01:02:44 +01:00
|
|
|
|
|
|
|
color: MoneroComponents.Style.defaultFontColor
|
2019-04-25 21:09:23 +02:00
|
|
|
textMargin: 2
|
2019-01-14 01:02:44 +01:00
|
|
|
text: ""
|
|
|
|
|
|
|
|
font.family: MoneroComponents.Style.fontRegular.name
|
2019-04-25 21:09:23 +02:00
|
|
|
font.pixelSize: 16
|
2019-04-11 03:17:29 +02:00
|
|
|
selectionColor: MoneroComponents.Style.textSelectionColor
|
|
|
|
selectedTextColor: MoneroComponents.Style.textSelectedColor
|
2019-01-14 01:02:44 +01:00
|
|
|
wrapMode: TextInput.Wrap
|
|
|
|
|
|
|
|
selectByMouse: true
|
|
|
|
|
2019-04-11 03:17:29 +02:00
|
|
|
MoneroComponents.TextPlain {
|
2019-01-14 01:02:44 +01:00
|
|
|
id: memoTextPlaceholder
|
|
|
|
opacity: 0.35
|
|
|
|
anchors.fill:parent
|
2019-04-25 21:09:23 +02:00
|
|
|
font.pixelSize: 16
|
|
|
|
anchors.margins: 8
|
|
|
|
anchors.leftMargin: 10
|
2019-01-14 01:02:44 +01:00
|
|
|
font.family: MoneroComponents.Style.fontRegular.name
|
|
|
|
text: qsTr("Enter your 25 (or 24) word mnemonic seed") + translationManager.emptyString
|
|
|
|
color: MoneroComponents.Style.defaultFontColor
|
2019-12-04 23:05:42 +01:00
|
|
|
visible: !seedInput.text
|
2019-01-14 01:02:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-02-12 00:34:15 +01:00
|
|
|
|
|
|
|
MoneroComponents.CheckBox2 {
|
|
|
|
id: seedOffsetCheckbox
|
|
|
|
text: qsTr("Seed offset passphrase (optional)") + translationManager.emptyString
|
|
|
|
}
|
|
|
|
|
|
|
|
MoneroComponents.LineEdit {
|
|
|
|
id: seedOffset
|
2020-04-28 14:15:18 +02:00
|
|
|
password: true
|
2020-02-12 00:34:15 +01:00
|
|
|
Layout.fillWidth: true
|
|
|
|
placeholderFontSize: 16
|
|
|
|
placeholderText: qsTr("Passphrase") + translationManager.emptyString
|
|
|
|
visible: seedOffsetCheckbox.checked
|
|
|
|
}
|
2019-01-14 01:02:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
MoneroComponents.LineEdit {
|
|
|
|
id: addressLine
|
|
|
|
visible: wizardController.walletRestoreMode === 'keys'
|
|
|
|
Layout.fillWidth: true
|
2019-04-25 21:09:23 +02:00
|
|
|
placeholderFontSize: 16
|
2019-01-14 01:02:44 +01:00
|
|
|
placeholderText: qsTr("Account address (public)") + translationManager.emptyString
|
|
|
|
|
|
|
|
onTextUpdated: {
|
|
|
|
wizardRestoreWallet1.verifyFromKeys();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MoneroComponents.LineEdit {
|
|
|
|
id: viewKeyLine
|
|
|
|
visible: wizardController.walletRestoreMode === 'keys'
|
|
|
|
Layout.fillWidth: true
|
2019-04-25 21:09:23 +02:00
|
|
|
placeholderFontSize: 16
|
2019-01-14 01:02:44 +01:00
|
|
|
placeholderText: qsTr("View key (private)") + translationManager.emptyString
|
|
|
|
|
|
|
|
onTextUpdated: {
|
|
|
|
wizardRestoreWallet1.verifyFromKeys();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MoneroComponents.LineEdit {
|
|
|
|
id: spendKeyLine
|
|
|
|
visible: wizardController.walletRestoreMode === 'keys'
|
|
|
|
Layout.fillWidth: true
|
2019-04-25 21:09:23 +02:00
|
|
|
placeholderFontSize: 16
|
2019-01-14 01:02:44 +01:00
|
|
|
placeholderText: qsTr("Spend key (private)") + translationManager.emptyString
|
|
|
|
|
|
|
|
onTextUpdated: {
|
|
|
|
wizardRestoreWallet1.verifyFromKeys();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GridLayout{
|
|
|
|
MoneroComponents.LineEdit {
|
|
|
|
id: restoreHeight
|
|
|
|
Layout.fillWidth: true
|
2018-12-15 02:28:07 +01:00
|
|
|
labelText: qsTr("Wallet creation date as `YYYY-MM-DD` or restore height") + translationManager.emptyString
|
2019-04-25 21:09:23 +02:00
|
|
|
labelFontSize: 14
|
|
|
|
placeholderFontSize: 16
|
2019-01-14 01:02:44 +01:00
|
|
|
placeholderText: qsTr("Restore height") + translationManager.emptyString
|
2018-12-15 02:28:07 +01:00
|
|
|
validator: RegExpValidator {
|
|
|
|
regExp: /^(\d+|\d{4}-\d{2}-\d{2})$/
|
|
|
|
}
|
2019-01-14 01:02:44 +01:00
|
|
|
text: "0"
|
|
|
|
}
|
|
|
|
|
|
|
|
Item {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
}
|
|
|
|
|
|
|
|
Item {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WizardNav {
|
|
|
|
id: nav
|
2020-04-22 06:32:55 +02:00
|
|
|
progressSteps: appWindow.walletMode <= 1 ? 3 : 4
|
|
|
|
progress: 0
|
2019-01-14 01:02:44 +01:00
|
|
|
btnNext.enabled: wizardRestoreWallet1.verify();
|
|
|
|
btnPrev.text: qsTr("Back to menu") + translationManager.emptyString
|
|
|
|
onPrevClicked: {
|
|
|
|
wizardStateView.state = "wizardHome";
|
|
|
|
}
|
|
|
|
onNextClicked: {
|
|
|
|
wizardController.walletOptionsName = wizardWalletInput.walletName.text;
|
|
|
|
wizardController.walletOptionsLocation = wizardWalletInput.walletLocation.text;
|
2019-02-23 03:26:51 +01:00
|
|
|
|
|
|
|
switch (wizardController.walletRestoreMode) {
|
|
|
|
case 'seed':
|
|
|
|
wizardController.walletOptionsSeed = seedInput.text;
|
2020-02-12 00:34:15 +01:00
|
|
|
wizardController.walletOptionsSeedOffset = seedOffsetCheckbox.checked ? seedOffset.text : "";
|
2019-02-23 03:26:51 +01:00
|
|
|
break;
|
|
|
|
default: // walletRestoreMode = keys or qr
|
|
|
|
wizardController.walletOptionsRecoverAddress = addressLine.text;
|
|
|
|
wizardController.walletOptionsRecoverViewkey = viewKeyLine.text
|
|
|
|
wizardController.walletOptionsRecoverSpendkey = spendKeyLine.text;
|
|
|
|
break;
|
|
|
|
}
|
2018-12-15 02:28:07 +01:00
|
|
|
|
|
|
|
var _restoreHeight = 0;
|
|
|
|
if(restoreHeight.text){
|
|
|
|
// Parse date string or restore height as integer
|
|
|
|
if(restoreHeight.text.indexOf('-') === 4 && restoreHeight.text.length === 10){
|
2019-05-15 05:21:09 +02:00
|
|
|
_restoreHeight = Wizard.getApproximateBlockchainHeight(restoreHeight.text, Utils.netTypeToString());
|
2018-12-15 02:28:07 +01:00
|
|
|
} else {
|
|
|
|
_restoreHeight = parseInt(restoreHeight.text)
|
|
|
|
}
|
|
|
|
|
|
|
|
wizardController.walletOptionsRestoreHeight = _restoreHeight;
|
|
|
|
}
|
2019-01-14 01:02:44 +01:00
|
|
|
|
|
|
|
wizardStateView.state = "wizardRestoreWallet2";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onPageCompleted(previousView){
|
|
|
|
if(previousView.viewName == "wizardHome"){
|
|
|
|
// cleanup
|
2019-04-06 00:07:03 +02:00
|
|
|
wizardWalletInput.reset();
|
2019-01-14 01:02:44 +01:00
|
|
|
seedInput.text = "";
|
2020-02-12 00:34:15 +01:00
|
|
|
seedOffsetCheckbox.checked = false;
|
|
|
|
seedOffset.text = "";
|
2019-01-14 01:02:44 +01:00
|
|
|
addressLine.text = "";
|
|
|
|
spendKeyLine.text = "";
|
2019-02-23 03:26:51 +01:00
|
|
|
viewKeyLine.text = "";
|
2019-01-14 01:02:44 +01:00
|
|
|
restoreHeight.text = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|