status-desktop/ui/app/AppLayouts/Onboarding2/pages/KeycardCreatePinPage.qml
Lukáš Tinkl 151ffbe503 feat(LoginWithKeycardFlow): implement "Unlock with recovery phrase"
- instead of the factory reset when the keycard is locked
2025-01-14 10:49:42 +01:00

126 lines
3.3 KiB
QML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import QtQuick 2.15
import QtQuick.Layouts 1.15
import QtQml 2.15
import StatusQ.Core 0.1
import StatusQ.Components 0.1
import StatusQ.Controls 0.1
import StatusQ.Controls.Validators 0.1
import StatusQ.Core.Theme 0.1
import StatusQ.Core.Backpressure 0.1
import AppLayouts.Onboarding2.controls 1.0
import utils 1.0
KeycardBasePage {
id: root
signal keycardPinCreated(string pin)
pageClassName: "KeycardCreatePinPage"
image.source: Theme.png("onboarding/keycard/reading")
QtObject {
id: d
property string pin
property string pin2
function setPins() {
if (pinInput.valid) {
if (root.state === "creating")
d.pin = pinInput.pinInput
else if (root.state === "repeating" || root.state === "mismatch")
d.pin2 = pinInput.pinInput
if (root.state === "mismatch")
pinInput.statesInitialization()
}
}
}
buttons: [
StatusPinInput {
id: pinInput
anchors.horizontalCenter: parent.horizontalCenter
validator: StatusIntValidator { bottom: 0; top: 999999 }
Component.onCompleted: {
statesInitialization()
forceFocus()
}
onPinInputChanged: {
Qt.callLater(d.setPins)
}
},
StatusBaseText {
id: errorText
anchors.horizontalCenter: parent.horizontalCenter
text: qsTr("PINs dont match")
font.pixelSize: Theme.tertiaryTextFontSize
color: Theme.palette.dangerColor1
visible: false
}
]
state: "creating"
states: [
State {
name: "creating"
PropertyChanges {
target: root
title: qsTr("Create new Keycard PIN")
}
},
State {
name: "mismatch"
extend: "repeating"
when: !!d.pin && !!d.pin2 && d.pin !== d.pin2
PropertyChanges {
target: errorText
visible: true
}
PropertyChanges {
target: root
image.source: Theme.png("onboarding/keycard/error")
}
},
State {
name: "success"
extend: "repeating"
when: !!d.pin && !!d.pin2 && d.pin === d.pin2
PropertyChanges {
target: root
title: qsTr("Keycard PIN set")
}
PropertyChanges {
target: pinInput
enabled: false
}
PropertyChanges {
target: root
image.source: Theme.png("onboarding/keycard/success")
}
StateChangeScript {
script: {
pinInput.setPin(d.pin)
Backpressure.debounce(root, 2000, () => root.keycardPinCreated(d.pin))()
}
}
},
State {
name: "repeating"
when: d.pin !== ""
PropertyChanges {
target: root
title: qsTr("Repeat Keycard PIN")
}
StateChangeScript {
script: {
pinInput.statesInitialization()
}
}
}
]
}