2020-06-22 11:43:34 +00:00
import QtQuick 2.12
import QtQuick . Controls 2.3
import QtQuick . Layouts 1.3
2021-09-28 15:04:06 +00:00
import utils 1.0
2020-06-22 11:43:34 +00:00
import "../../../../shared"
2021-10-14 10:01:34 +00:00
import "../../../../shared/popups"
2021-10-14 11:07:19 +00:00
import "../../../../shared/controls"
2021-01-28 11:04:10 +00:00
import "../../../../shared/status"
2020-06-22 11:43:34 +00:00
2021-10-14 11:07:19 +00:00
// TODO: replace with StatusModal
2020-06-22 11:43:34 +00:00
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: ""
2020-06-22 11:43:34 +00:00
2021-08-18 16:11:17 +00:00
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
}
}
2020-06-22 11:43:34 +00:00
2020-08-25 20:19:46 +00:00
Loader {
2020-10-26 20:20:31 +00:00
active: popup . opened && ! showWarning && seedWord1Idx == - 1
2020-08-25 20:19:46 +00:00
width: parent . width
2020-09-23 18:01:33 +00:00
height: item ? item.height : 0
2020-06-22 11:43:34 +00:00
2020-08-25 20:19:46 +00:00
sourceComponent: Component {
id: seedComponent
Item {
id: seed
width: parent . width
height: children [ 0 ] . height
2020-06-22 11:43:34 +00:00
2020-08-25 20:19:46 +00:00
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
2020-06-22 11:43:34 +00:00
2020-08-25 20:19:46 +00:00
Repeater {
id: mnemonicRepeater
2020-12-06 22:15:51 +00:00
model: profileModel . mnemonic . get . split ( " " )
2020-08-25 20:19:46 +00:00
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
2020-06-22 11:43:34 +00:00
2020-08-25 20:19:46 +00:00
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
}
2020-06-22 11:43:34 +00:00
2020-08-25 20:19:46 +00:00
StyledText {
id: count
text: index + 1
2021-07-07 17:20:09 +00:00
color: Style . current . secondaryText
2020-08-25 20:19:46 +00:00
anchors.bottom: parent . bottom
anchors.bottomMargin: Style . current . smallPadding
anchors.left: parent . left
anchors.leftMargin: Style . current . bigPadding
font.pixelSize: 15
}
2020-06-22 11:43:34 +00:00
2020-08-25 20:19:46 +00:00
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-06-22 11:43:34 +00:00
}
}
}
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 {
2021-08-18 16:11:17 +00:00
id: textInput
2020-10-26 20:20:31 +00:00
visible: seedWord1Idx > - 1 || seedWord2Idx > - 1
anchors.left: parent . left
anchors.right: parent . right
2021-08-18 16:11:17 +00:00
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
}
2021-04-26 15:23:14 +00:00
Component {
id: removeSeedPhraseConfirmDialogComponent
ConfirmationDialog {
id: confirmPopup
//% "Are you sure?"
2021-09-09 09:10:29 +00:00
header.title: qsTrId ( "are-you-sure?" )
2021-04-26 15:23:14 +00:00
//% "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
}
}
}
2020-07-13 18:45:54 +00:00
StyledText {
2020-08-25 20:19:46 +00:00
id: confirmationsInfo
2020-10-26 20:20:31 +00:00
visible: ! showWarning && seedWord1Idx == - 1
2020-08-25 20:19:46 +00:00
//% "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
2021-07-07 17:20:09 +00:00
color: Style . current . secondaryText
2020-08-25 20:19:46 +00:00
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-06-22 11:43:34 +00:00
}
2020-10-26 20:20:31 +00:00
2021-01-28 11:04:10 +00:00
footer: StatusButton {
2021-08-18 16:11:17 +00:00
id: confirmButton
2021-01-28 11:04:10 +00:00
text: showWarning ?
2021-02-18 16:36:05 +00:00
//% "Okay, continue"
qsTrId ( "ok-continue" ) :
//% "Next"
qsTrId ( "next" )
2020-08-25 20:19:46 +00:00
anchors.right: parent . right
anchors.rightMargin: Style . current . smallPadding
anchors.bottom: parent . bottom
2021-08-18 16:11:17 +00:00
focus: ! textInput . visible
Keys.onReturnPressed: function ( event ) {
confirmButton . clicked ( )
}
2020-08-25 20:19:46 +00:00
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 = "" ;
2021-04-26 15:23:14 +00:00
openPopup ( removeSeedPhraseConfirmDialogComponent ) ;
2020-10-26 20:20:31 +00:00
}
}
}
2020-08-25 20:19:46 +00:00
}
2020-06-22 11:43:34 +00:00
}
}