monero-gui/wizard/WizardManageWalletUI.qml

288 lines
9.3 KiB
QML
Raw Normal View History

// Copyright (c) 2014-2015, 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.
import QtQuick 2.2
2016-10-07 23:05:51 +03:00
import moneroComponents.TranslationManager 1.0
import QtQuick.Dialogs 1.2
2017-01-26 22:54:31 +02:00
import QtQuick.Layouts 1.2
2016-10-08 02:48:42 +03:00
import "../components"
2017-01-26 22:54:31 +02:00
import 'utils.js' as Utils
// Reusable component for managing wallet (account name, path, private key)
2017-01-26 22:54:31 +02:00
ColumnLayout {
anchors.left: parent.left
anchors.right: parent.right
spacing: 5
property alias titleText: titleText.text
property alias accountNameText: accountName.text
property alias wordsTextTitle: frameHeader.text
property alias walletPath: fileUrlInput.text
property alias wordsTextItem : memoTextItem
2016-10-08 02:48:42 +03:00
property alias restoreHeight : restoreHeightItem.text
property alias restoreHeightVisible: restoreHeightItem.visible
property alias walletName : accountName.text
property alias progressDotsModel : progressDots.model
2017-01-26 22:54:31 +02:00
property alias recoverFromKeysAddress: addressLine.text;
property alias recoverFromKeysViewKey: viewKeyLine.text;
property alias recoverFromKeysSpendKey: spendKeyLine.text;
// recover mode or create new wallet
property bool recoverMode: false
// Recover form seed or keys
property bool recoverFromSeedMode: true
2017-01-26 22:54:31 +02:00
function checkFields(){
var addressOK = walletManager.addressValid(addressLine.text, wizard.settings.testnet)
var viewKeyOK = walletManager.keyValid(viewKeyLine.text, addressLine.text, true, wizard.settings.testnet)
// Spendkey is optional
var spendKeyOK = (spendKeyLine.text.length > 0)? walletManager.keyValid(spendKeyLine.text, addressLine.text, false, wizard.settings.testnet) : true
2017-01-26 22:54:31 +02:00
addressLine.error = !addressOK && addressLine.text.length != 0
viewKeyLine.error = !viewKeyOK && viewKeyLine.text.length != 0
spendKeyLine.error = !spendKeyOK && spendKeyLine.text.length != 0
return addressOK && viewKeyOK && spendKeyOK
}
function checkNextButton(){
wizard.nextButton.enabled = false
console.log("check next", recoverFromSeed.visible)
if(recoverMode && !recoverFromSeedMode) {
console.log("checking key fields")
wizard.nextButton.enabled = checkFields();
} else if (recoverMode && recoverFromSeedMode) {
wizard.nextButton.enabled = checkSeed()
} else
wizard.nextButton.enabled = true;
}
function checkSeed() {
console.log("Checking seed")
var wordsArray = Utils.lineBreaksToSpaces(uiItem.wordsTextItem.memoText).split(" ");
return wordsArray.length === 25
}
RowLayout {
id: dotsRow
2017-01-26 22:54:31 +02:00
Layout.topMargin: 85
Layout.alignment: Qt.AlignRight
spacing: 6
ListModel {
id: dotsModel
ListElement { dotColor: "#36B05B" }
//ListElement { dotColor: "#DBDBDB" }
ListElement { dotColor: "#DBDBDB" }
ListElement { dotColor: "#DBDBDB" }
}
Repeater {
id: progressDots
model: dotsModel
delegate: Rectangle {
width: 12; height: 12
radius: 6
color: dotColor
}
}
}
2017-01-26 22:54:31 +02:00
RowLayout {
id: headerColumn
Text {
2017-01-26 22:54:31 +02:00
Layout.fillWidth: true
horizontalAlignment: Text.AlignHCenter
id: titleText
font.family: "Arial"
font.pixelSize: 28
wrapMode: Text.Wrap
color: "#3F3F3F"
}
}
2017-01-26 22:54:31 +02:00
ColumnLayout {
2017-01-26 22:54:31 +02:00
Label {
Layout.fillWidth: true
Layout.topMargin: 20
fontSize: 14
text: qsTr("Wallet name")
+ translationManager.emptyString
}
LineEdit {
id: accountName
2017-01-26 22:54:31 +02:00
Layout.fillWidth: true
text: defaultAccountName
2017-01-26 22:54:31 +02:00
onTextUpdated: checkNextButton()
}
}
2017-01-26 22:54:31 +02:00
RowLayout{
visible: recoverMode
StandardButton {
id: recoverFromSeedButton
text: qsTr("Restore from seed") + translationManager.emptyString
shadowReleasedColor: "#FF4304"
shadowPressedColor: "#B32D00"
releasedColor: "#FF6C3C"
pressedColor: "#FF4304"
enabled: recoverFromKeys.visible
onClicked: {
recoverFromSeedMode = true;
checkNextButton();
}
}
2017-01-26 22:54:31 +02:00
StandardButton {
id: recoverFromKeysButton
text: qsTr("Restore from keys") + translationManager.emptyString
shadowReleasedColor: "#FF4304"
shadowPressedColor: "#B32D00"
releasedColor: "#FF6C3C"
pressedColor: "#FF4304"
enabled: recoverFromSeed.visible
onClicked: {
recoverFromSeedMode = false;
checkNextButton();
}
}
}
2017-01-26 22:54:31 +02:00
// Recover from seed
RowLayout {
id: recoverFromSeed
visible: !recoverMode || ( recoverMode && recoverFromSeedMode)
WizardMemoTextInput {
id : memoTextItem
Layout.fillWidth: true
Layout.preferredWidth: 600
Layout.minimumWidth: 300
}
}
2017-01-26 22:54:31 +02:00
// Recover from keys
GridLayout {
id: recoverFromKeys
visible: recoverMode && !recoverFromSeedMode
columns: 1
LineEdit {
Layout.fillWidth: true
id: addressLine
placeholderText: qsTr("Account address (public)")
onTextUpdated: checkNextButton()
}
LineEdit {
Layout.fillWidth: true
id: viewKeyLine
placeholderText: qsTr("View key (private)")
onTextUpdated: checkNextButton()
2017-01-26 22:54:31 +02:00
}
LineEdit {
Layout.fillWidth: true
id: spendKeyLine
placeholderText: qsTr("Spend key (private)")
onTextUpdated: checkNextButton()
2016-10-08 02:48:42 +03:00
}
}
2017-01-26 22:54:31 +02:00
RowLayout {
Text {
2017-01-26 22:54:31 +02:00
visible: false
Layout.fillWidth: true
id: frameHeader
font.family: "Arial"
2017-01-26 22:54:31 +02:00
font.pixelSize: 24
font.bold: true
wrapMode: Text.Wrap
color: "#4A4646"
}
2017-01-26 22:54:31 +02:00
}
2017-01-26 22:54:31 +02:00
RowLayout {
// Restore Height
LineEdit {
id: restoreHeightItem
Layout.preferredWidth: 250
placeholderText: qsTr("Restore height (optional)")
validator: IntValidator {
bottom:0
}
2017-01-26 22:54:31 +02:00
}
}
2017-01-26 22:54:31 +02:00
ColumnLayout {
2017-01-26 22:54:31 +02:00
Label {
Layout.fillWidth: true
Layout.topMargin: 20
fontSize: 14
text: qsTr("Your wallet is stored in") + translationManager.emptyString
+ translationManager.emptyString
}
TextInput {
Layout.fillWidth: true
id: fileUrlInput
clip: true
font.family: "Arial"
font.pixelSize: 18
color: "#6B0072"
selectByMouse: true
text: moneroAccountsDir + "/"
// workaround for the bug "filechooser only opens once"
MouseArea {
anchors.fill: parent
onClicked: {
mouse.accepted = false
fileDialog.folder = walletManager.localPathToUrl(fileUrlInput.text)
fileDialog.open()
fileUrlInput.focus = true
}
}
2017-01-26 22:54:31 +02:00
}
2017-01-26 22:54:31 +02:00
FileDialog {
id: fileDialog
selectMultiple: false
selectFolder: true
title: qsTr("Please choose a directory") + translationManager.emptyString
onAccepted: {
fileUrlInput.text = walletManager.urlToLocalPath(fileDialog.folder)
fileDialog.visible = false
}
onRejected: {
fileDialog.visible = false
}
}
}
}