2024-10-15 19:26:12 +00:00
|
|
|
import QtQuick 2.15
|
|
|
|
import QtQuick.Layouts 1.15
|
|
|
|
import QtQuick.Controls 2.15
|
2022-07-21 11:29:18 +00:00
|
|
|
|
|
|
|
import StatusQ.Core 0.1
|
|
|
|
import StatusQ.Core.Theme 0.1
|
|
|
|
import StatusQ.Controls 0.1
|
|
|
|
|
|
|
|
import utils 1.0
|
|
|
|
|
|
|
|
import "../stores"
|
|
|
|
|
|
|
|
Item {
|
|
|
|
id: root
|
|
|
|
|
|
|
|
property StartupStore startupStore
|
|
|
|
|
|
|
|
Component.onCompleted: {
|
|
|
|
d.dirtyWordAtIndex = [false, false, false, false]
|
|
|
|
d.validWordAtIndex = [false, false, false, false]
|
|
|
|
d.anyInputDirty = false
|
|
|
|
d.allEntriesValid = false
|
|
|
|
|
|
|
|
let seedPhrase = root.startupStore.getSeedPhrase()
|
|
|
|
if(seedPhrase.length === 0)
|
|
|
|
return
|
|
|
|
|
|
|
|
d.seedPhrases = seedPhrase.split(" ")
|
|
|
|
|
|
|
|
let numbers = []
|
|
|
|
while (numbers.length < 4) {
|
|
|
|
let randomNo = Math.floor(Math.random() * 12)
|
|
|
|
if(numbers.indexOf(randomNo) == -1)
|
|
|
|
numbers.push(randomNo)
|
|
|
|
}
|
|
|
|
numbers.sort((a, b) => { return a < b? -1 : a > b? 1 : 0 })
|
|
|
|
d.wordNumbers = numbers
|
|
|
|
}
|
|
|
|
|
|
|
|
QtObject {
|
|
|
|
id: d
|
|
|
|
|
|
|
|
property var seedPhrases: []
|
|
|
|
property var wordNumbers: []
|
|
|
|
property var dirtyWordAtIndex: [false, false, false, false]
|
|
|
|
property var validWordAtIndex: [false, false, false, false]
|
|
|
|
property bool anyInputDirty: false
|
|
|
|
property bool allEntriesValid: false
|
|
|
|
readonly property int numOfColumns: 4
|
2024-10-15 19:26:12 +00:00
|
|
|
readonly property int rowSpacing: Theme.bigPadding
|
|
|
|
readonly property int columnSpacing: Theme.bigPadding
|
2022-07-21 11:29:18 +00:00
|
|
|
|
|
|
|
function updateValidity(index, valid, dirty) {
|
|
|
|
dirtyWordAtIndex[index] = dirty
|
|
|
|
validWordAtIndex[index] = valid
|
|
|
|
let anyDirty = false
|
|
|
|
let allValid = true
|
|
|
|
for(let i = 0; i < validWordAtIndex.length; ++i) {
|
|
|
|
allValid = allValid && validWordAtIndex[i]
|
|
|
|
anyDirty = anyDirty || (dirtyWordAtIndex[index] && !validWordAtIndex[index])
|
|
|
|
}
|
|
|
|
allEntriesValid = allValid
|
|
|
|
anyInputDirty = anyDirty
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-28 16:09:12 +00:00
|
|
|
ColumnLayout {
|
|
|
|
anchors.centerIn: parent
|
2023-05-09 16:23:48 +00:00
|
|
|
height: Constants.onboarding.loginHeight
|
2024-10-15 19:26:12 +00:00
|
|
|
spacing: Theme.bigPadding
|
2022-09-28 16:09:12 +00:00
|
|
|
|
|
|
|
StatusBaseText {
|
|
|
|
id: title
|
|
|
|
Layout.alignment: Qt.AlignHCenter
|
|
|
|
font.pixelSize: Constants.keycard.general.fontSize1
|
|
|
|
font.weight: Font.Bold
|
|
|
|
color: Theme.palette.directColor1
|
|
|
|
text: qsTr("Enter seed phrase words")
|
|
|
|
}
|
2022-07-21 11:29:18 +00:00
|
|
|
|
2022-09-28 16:09:12 +00:00
|
|
|
Item {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.fillHeight: true
|
|
|
|
}
|
|
|
|
|
|
|
|
GridLayout {
|
|
|
|
id: grid
|
|
|
|
Layout.alignment: Qt.AlignHCenter
|
|
|
|
columns: d.numOfColumns
|
|
|
|
rowSpacing: d.rowSpacing
|
|
|
|
columnSpacing: d.columnSpacing
|
|
|
|
height: Constants.keycard.general.enterSeedPhraseWordsHeight
|
|
|
|
width: Constants.keycard.general.enterSeedPhraseWordsWidth
|
|
|
|
|
|
|
|
Component.onCompleted: {
|
|
|
|
for (var i = 0; i < children.length - 1; ++i) {
|
|
|
|
if(children[i].inputField && children[i+1].inputField){
|
|
|
|
children[i].inputField.input.tabNavItem = children[i+1].inputField.input.edit
|
2022-07-21 11:29:18 +00:00
|
|
|
}
|
|
|
|
}
|
2022-09-28 16:09:12 +00:00
|
|
|
}
|
2022-07-21 11:29:18 +00:00
|
|
|
|
2022-09-28 16:09:12 +00:00
|
|
|
Repeater {
|
|
|
|
model: d.wordNumbers
|
|
|
|
delegate: Item {
|
|
|
|
Layout.preferredWidth: Constants.keycard.general.seedPhraseCellWidth
|
|
|
|
Layout.preferredHeight: Constants.keycard.general.seedPhraseCellHeight
|
|
|
|
|
|
|
|
property alias inputField: word
|
|
|
|
property alias wN: wordNumber
|
|
|
|
|
|
|
|
StatusBaseText {
|
|
|
|
id: wordNumber
|
|
|
|
width: Constants.keycard.general.seedPhraseCellNumberWidth
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
horizontalAlignment: Qt.AlignRight
|
|
|
|
font.pixelSize: Constants.keycard.general.seedPhraseCellFontSize
|
|
|
|
color: Theme.palette.directColor1
|
|
|
|
text: "%1.".arg(model.modelData + 1)
|
|
|
|
}
|
2022-07-21 11:29:18 +00:00
|
|
|
|
2022-09-28 16:09:12 +00:00
|
|
|
StatusInput {
|
|
|
|
id: word
|
|
|
|
anchors.left: wordNumber.right
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
2024-10-15 19:26:12 +00:00
|
|
|
anchors.leftMargin: Theme.xlPadding
|
2022-09-28 16:09:12 +00:00
|
|
|
input.edit.font.pixelSize: Constants.keycard.general.seedPhraseCellFontSize
|
|
|
|
input.acceptReturn: true
|
|
|
|
|
|
|
|
onTextChanged: {
|
|
|
|
if(text.length == 0)
|
|
|
|
return
|
|
|
|
if(/(^\s|^\r|^\n)|(\s$|^\r$|^\n$)/.test(text)) {
|
|
|
|
text = text.trim()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
else if(/\s|\r|\n/.test(text)) {
|
|
|
|
text = ""
|
|
|
|
return
|
2022-07-21 11:29:18 +00:00
|
|
|
}
|
2022-09-28 16:09:12 +00:00
|
|
|
valid = d.seedPhrases[model.modelData] === text
|
|
|
|
d.updateValidity(index, valid, text !== "")
|
|
|
|
}
|
2022-07-21 11:29:18 +00:00
|
|
|
|
2022-09-28 16:09:12 +00:00
|
|
|
onKeyPressed: {
|
|
|
|
if (d.allEntriesValid &&
|
|
|
|
(input.edit.keyEvent === Qt.Key_Return ||
|
|
|
|
input.edit.keyEvent === Qt.Key_Enter)) {
|
|
|
|
event.accepted = true
|
|
|
|
root.startupStore.doPrimaryAction()
|
2022-07-21 11:29:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-09-28 16:09:12 +00:00
|
|
|
}
|
2022-07-21 11:29:18 +00:00
|
|
|
|
2022-09-28 16:09:12 +00:00
|
|
|
StatusBaseText {
|
|
|
|
id: info
|
|
|
|
Layout.alignment: Qt.AlignHCenter
|
|
|
|
font.pixelSize: Constants.keycard.general.fontSize3
|
|
|
|
color: Theme.palette.dangerColor1
|
|
|
|
horizontalAlignment: Qt.AlignHCenter
|
|
|
|
text: d.anyInputDirty && !d.allEntriesValid? qsTr("Invalid word") : ""
|
2022-07-21 11:29:18 +00:00
|
|
|
}
|
|
|
|
|
2022-09-28 16:09:12 +00:00
|
|
|
Item {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.fillHeight: true
|
|
|
|
}
|
2022-07-21 11:29:18 +00:00
|
|
|
|
|
|
|
StatusButton {
|
2022-09-28 16:09:12 +00:00
|
|
|
Layout.alignment: Qt.AlignHCenter
|
2022-07-21 11:29:18 +00:00
|
|
|
enabled: d.allEntriesValid
|
2024-04-24 16:31:22 +00:00
|
|
|
text: qsTr("Next")
|
2022-07-21 11:29:18 +00:00
|
|
|
onClicked: {
|
|
|
|
root.startupStore.doPrimaryAction()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|