status-desktop/ui/app/AppLayouts/Profile/Sections/BackupSeedModal.qml

287 lines
10 KiB
QML
Raw Normal View History

import QtQuick 2.12
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.3
import "../../../../imports"
import "../../../../shared"
import "../../../../shared/status"
ModalPopup {
id: popup
2020-10-26 20:20:31 +00:00
property bool showWarning: true
property int seedWord1Idx: -1;
property int seedWord2Idx: -1;
property string validationError: ""
focus: visible
2020-10-26 20:20:31 +00:00
onOpened: {
seedWord1Idx = -1;
seedWord2Idx = -1;
txtFieldWord.text = "";
validationError = "";
}
header: Item {
height: 50
StyledText {
id: lblTitle
2021-02-18 16:36:05 +00:00
//% "Back up seed phrase"
text: qsTrId("back-up-seed-phrase")
2020-10-26 20:20:31 +00:00
font.pixelSize: 17
font.bold: true
anchors.left: parent.left
}
StyledText {
anchors.top: lblTitle.bottom
anchors.topMargin: Style.current.smallPadding
2021-02-18 16:36:05 +00:00
//% "Step %1 of 3"
text: qsTrId("step--1-of-3").arg(seedWord2Idx > -1 ? 3 : (seedWord1Idx > -1 ? 2 : 1))
2020-10-26 20:20:31 +00:00
font.pixelSize: 14
anchors.left: parent.left
}
}
Loader {
2020-10-26 20:20:31 +00:00
active: popup.opened && !showWarning && seedWord1Idx == -1
width: parent.width
height: item ? item.height : 0
sourceComponent: Component {
id: seedComponent
Item {
id: seed
width: parent.width
height: children[0].height
Rectangle {
id: wrapper
property int len: mnemonicRepeater.count
anchors.top: parent.top
anchors.topMargin: Style.current.padding
height: 40 * (len / 2)
width: 350
border.width: 1
color: Style.current.background
border.color: Style.current.border
radius: Style.current.radius
anchors.horizontalCenter: parent.horizontalCenter
Repeater {
id: mnemonicRepeater
2020-12-06 22:15:51 +00:00
model: profileModel.mnemonic.get.split(" ")
Rectangle {
id: word
height: 40
width: 175
color: "transparent"
anchors.top: (index == 0
|| index == (wrapper.len / 2)) ? parent.top : parent.children[index - 1].bottom
anchors.left: (index < (wrapper.len / 2)) ? parent.left : undefined
anchors.right: (index >= wrapper.len / 2) ? parent.right : undefined
Rectangle {
width: 1
height: parent.height
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.right: parent.right
anchors.rightMargin: 175
color: Style.current.inputBackground
visible: index >= wrapper.len / 2
}
StyledText {
id: count
text: index + 1
color: Style.current.secondaryText
anchors.bottom: parent.bottom
anchors.bottomMargin: Style.current.smallPadding
anchors.left: parent.left
anchors.leftMargin: Style.current.bigPadding
font.pixelSize: 15
}
StyledTextEdit {
text: modelData
font.pixelSize: 15
anchors.bottom: parent.bottom
anchors.bottomMargin: Style.current.smallPadding
anchors.left: count.right
anchors.leftMargin: Style.current.padding
selectByMouse: true
readOnly: true
}
}
}
}
}
}
}
2020-10-26 20:20:31 +00:00
Item {
visible: showWarning
anchors.left: parent.left
anchors.right: parent.right
StyledText {
id: lblLoseSeed
2021-02-18 16:36:05 +00:00
//% "If you lose your seed phrase you lose your data and funds"
text: qsTrId("your-data-belongs-to-you")
2020-10-26 20:20:31 +00:00
wrapMode: Text.WordWrap
font.pixelSize: 17
font.bold: true
anchors.left: parent.left
anchors.right: parent.right
}
StyledText {
anchors.top: lblLoseSeed.bottom
anchors.topMargin: Style.current.smallPadding
wrapMode: Text.WordWrap
2021-02-18 16:36:05 +00:00
//% "If you lose access, for example by losing your phone, you can only access your keys with your seed phrase. No one, but you has your seed phrase. Write it down. Keep it safe"
text: qsTrId("your-data-belongs-to-you-description")
2020-10-26 20:20:31 +00:00
anchors.left: parent.left
anchors.right: parent.right
}
}
Item {
id: textInput
2020-10-26 20:20:31 +00:00
visible: seedWord1Idx > -1 || seedWord2Idx > -1
anchors.left: parent.left
anchors.right: parent.right
focus: visible
onActiveFocusChanged: {
if (activeFocus)
txtFieldWord.forceActiveFocus(Qt.MouseFocusReason)
}
Keys.onReturnPressed: function(event) {
confirmButton.clicked()
}
2020-10-26 20:20:31 +00:00
StyledText {
id: txtChk
2021-02-18 16:36:05 +00:00
//% "Check your seed phrase"
text: qsTrId("check-your-recovery-phrase")
2020-10-26 20:20:31 +00:00
}
StyledText {
2021-02-18 16:36:05 +00:00
//% "Word #%1"
text: qsTrId("word---1").arg((seedWord2Idx > -1 ? seedWord2Idx : seedWord1Idx) + 1)
2020-10-26 20:20:31 +00:00
anchors.left: txtChk.right
anchors.leftMargin: 5
color: Style.current.secondaryText
}
Input {
id: txtFieldWord
anchors.top: txtChk.bottom
anchors.topMargin: Style.current.padding
anchors.left: txtChk.left
anchors.right: parent.right
2021-02-18 16:36:05 +00:00
//% "Enter word"
placeholderText: qsTrId("enter-word")
2020-10-26 20:20:31 +00:00
text: ""
validationError: popup.validationError
}
StyledText {
anchors.top: txtFieldWord.bottom
anchors.topMargin: Style.current.padding
wrapMode: Text.WordWrap
anchors.left: parent.left
anchors.right: parent.right
2021-02-18 16:36:05 +00:00
//% "In order to check if you have backed up your seed phrase correctly, enter the word #%1 above"
text: qsTrId("in-order-to-check-if-you-have-backed-up-your-seed-phrase-correctly--enter-the-word---1-above").arg((seedWord2Idx > -1 ? seedWord2Idx : seedWord1Idx) + 1)
2020-10-26 20:20:31 +00:00
color: Style.current.secondaryText
}
Component {
id: removeSeedPhraseConfirmDialogComponent
ConfirmationDialog {
id: confirmPopup
//% "Are you sure?"
title: qsTrId("are-you-sure?")
//% "You will not be able to see the whole seed phrase again"
confirmationText: qsTrId("are-you-sure-description")
onConfirmButtonClicked: {
profileModel.mnemonic.remove()
popup.close();
confirmPopup.close();
}
onClosed: {
destroy();
}
2020-10-26 20:20:31 +00:00
}
}
}
StyledText {
id: confirmationsInfo
2020-10-26 20:20:31 +00:00
visible: !showWarning && seedWord1Idx == -1
//% "With this 12 words you can always get your key back. Write it down. Keep it safe, offline, and separate from this device."
text: qsTrId(
"with-this-12-words-you-can-always-get-your-key-back.-write-it-down.-keep-it-safe,-offline,-and-separate-from-this-device.")
font.pixelSize: 14
font.weight: Font.Medium
color: Style.current.secondaryText
anchors.bottom: parent.bottom
anchors.bottomMargin: Style.current.padding
anchors.left: parent.left
anchors.leftMargin: Style.current.smallPadding
anchors.right: parent.right
anchors.rightMargin: Style.current.smallPadding
wrapMode: Text.WordWrap
}
2020-10-26 20:20:31 +00:00
footer: StatusButton {
id: confirmButton
text: showWarning ?
2021-02-18 16:36:05 +00:00
//% "Okay, continue"
qsTrId("ok-continue") :
//% "Next"
qsTrId("next")
anchors.right: parent.right
anchors.rightMargin: Style.current.smallPadding
anchors.bottom: parent.bottom
focus: !textInput.visible
Keys.onReturnPressed: function(event) {
confirmButton.clicked()
}
onClicked: {
2020-10-26 20:20:31 +00:00
if(showWarning){
showWarning = false;
} else {
if(seedWord1Idx == -1){
seedWord1Idx = Math.floor(Math.random() * 12);
} else {
if(seedWord2Idx == -1){
2020-12-06 22:15:51 +00:00
if(profileModel.mnemonic.getWord(seedWord1Idx) !== txtFieldWord.text){
2021-02-18 16:36:05 +00:00
//% "Wrong word"
validationError = qsTrId("wrong-word");
2020-10-26 20:20:31 +00:00
return;
}
validationError = "";
txtFieldWord.text = "";
do {
seedWord2Idx = Math.floor(Math.random() * 12);
} while(seedWord2Idx == seedWord1Idx);
} else {
2020-12-06 22:15:51 +00:00
if(profileModel.mnemonic.getWord(seedWord2Idx) !== txtFieldWord.text){
2021-02-18 16:36:05 +00:00
//% "Wrong word"
validationError = qsTrId("wrong-word");
2020-10-26 20:20:31 +00:00
return;
}
validationError = "";
txtFieldWord.text = "";
openPopup(removeSeedPhraseConfirmDialogComponent);
2020-10-26 20:20:31 +00:00
}
}
}
}
}
}