continue flow implementation

This commit is contained in:
Michele Balistreri 2021-10-01 13:22:51 +03:00 committed by Iuri Matias
parent 5cf58a78e5
commit 101e77cc14
6 changed files with 103 additions and 18 deletions

View File

@ -1,5 +1,6 @@
import NimQml, chronicles, std/wrapnils
import status/[signals, status, keycard]
import types/keycard as keycardtypes
import view, pairing
logScope:
@ -29,11 +30,25 @@ proc attemptOpenSecureChannel(self: KeycardController) : bool =
if pairing == "":
return false
# actually open secure channel
discard """let err = self.status.keycard.openSecureChannel(pairing)
if err == Ok:
return true
self.view.pairings.removePairing(self.view.appInfo.instanceUID)
""""
return false
proc getCardState(self: KeycardController) =
let appInfo = self.status.keycard.select()
var appInfo: KeycardApplicationInfo
try:
appInfo = self.status.keycard.select()
except KeycardSelectException as ex:
self.view.cardUnhandledError(ex.error)
return
self.view.appInfo = appInfo
if not appInfo.installed:
@ -43,7 +58,16 @@ proc getCardState(self: KeycardController) =
self.view.cardState = PreInit
self.view.cardPreInit()
elif self.attemptOpenSecureChannel():
# here we will also be able to check if the card is Frozen/Blocked
discard """
self.view.appStatus = self.status.keycard.getStatusApplication()
if self.view.appStatus.pukRetryCounter == 0:
self.view.cardState = Blocked
self.view.cardBlocked()
elif self.view.appStatus.pinRetryCounter == 0:
self.view.cardState = Frozen
self.view.cardFrozen()
else:
"""
self.view.cardState = Paired
self.view.cardPaired()
elif appInfo.availableSlots > 0:

View File

@ -1,6 +1,6 @@
import NimQml, chronicles
import status/[status, keycard]
import status/types/keycard as keycardtypes
import types/keycard as keycardtypes
import pairing
logScope:
@ -47,18 +47,47 @@ QtObject:
proc cardFrozen*(self: KeycardView) {.signal.}
proc cardBlocked*(self: KeycardView) {.signal.}
proc cardAuthenticated*(self: KeycardView) {.signal.}
proc cardUnhandledError*(self: KeycardView, error: string) {.signal.}
proc startConnection*(self: KeycardView) {.slot.} =
discard self.status.keycard.start()
try:
self.status.keycard.start()
except KeycardStartException as ex:
self.cardUnhandledError(ex.error)
proc stopConnection*(self: KeycardView) {.slot.} =
self.cardState = Disconnected
discard self.status.keycard.stop()
try:
self.status.keycard.stop()
except KeycardStopException as ex:
self.cardUnhandledError(ex.error)
proc pair*(self: KeycardView, password: string) {.slot.} =
discard """
on succesful pairing, save and change card state
otherwise throw error
let pairing = self.status.keycard.pair(password)
self.status.keycard.pair(password)
if pairing == "":
error
self.pairings.addPairing(self.appInfo.instanceUID, pairing)
self.cardState = Paired
self.cardPaired()
"""
proc authenticate*(self: KeycardView, pin: string) {.slot.} =
discard """
let resp = self.status.keycard.verifyPIN(pin)
if resp is error:
handle error
self.cardAuthenticated()
"""
proc init*(self: KeycardView, pin: string) {.slot.} =
discard """
"""
proc recoverAccount*(self: KeycardView) {.slot.} =
discard """
"""

View File

@ -2,10 +2,16 @@ import QtQuick 2.13
import "./Keycard"
import "../shared/keycard"
// this will be the entry point. for now it opens all keycard-related dialogs in sequence for test
Item {
enum OnboardingFlow {
Recover,
Generate,
ImportMnemonic
}
property var onClosed: function () {}
property bool connected: false
property int flow: OnboardingFlow.Recover
id: keycardView
anchors.fill: parent
@ -17,7 +23,9 @@ Item {
CreatePINModal {
id: createPinModal
onClosed: function () {
keycardView.onClosed()
if (!createPinModal.submitted) {
keycardView.onClosed()
}
}
}
@ -33,7 +41,9 @@ Item {
PINModal {
id: pinModal
onClosed: function () {
keycardView.onClosed()
if (!pinModal.submitted) {
keycardView.onClosed()
}
}
}
@ -54,13 +64,28 @@ Item {
}
onCardPaired: {
pinModal.open()
}
onCardAuthenticated: {
switch (flow) {
case OnboardingFlow.Recover: {
keycardModel.recoverAccount();
break;
}
case OnboardingFlow.Generate: {
break;
}
case OnboardingFlow.ImportMnemonic: {
break;
}
}
}
//TODO: support the states below
onCardPreInit: {
keycardView.onClosed()
createPinModal.open()
}
onCardFrozen: {
@ -76,14 +101,11 @@ Item {
// later add factory reset option for the NoFreeSlots case
onCardNoFreeSlots: {
//status-lib currently always returns availableSlots = 0 so we end up here
//keycardView.onClosed()
pairingModal.open()
keycardView.onClosed()
}
onCardNotKeycard: {
keycardView.onClosed()
}
}

View File

@ -11,12 +11,14 @@ ModalPopup {
property bool repeatPINFieldValid: false
property string pinValidationError: ""
property string repeatPINValidationError: ""
property bool submitted: false
id: popup
title: qsTr("Create PIN")
height: 500
onOpened: {
submitted = false
firstPINField.text = "";
firstPINField.forceActiveFocus(Qt.MouseFocusReason)
}
@ -102,6 +104,9 @@ ModalPopup {
enabled: firstPINFieldValid && repeatPINFieldValid
onClicked: {
submitted = true
keycardModel.init(firstPINField.text)
popup.close()
}
}
}

View File

@ -7,12 +7,14 @@ import "../../shared"
ModalPopup {
property bool pinFieldValid: false
property bool submitted: false
id: popup
title: qsTr("Authenticate PIN")
height: 400
onOpened: {
submitted = false
pinField.text = "";
pinField.forceActiveFocus(Qt.MouseFocusReason)
}
@ -58,7 +60,9 @@ ModalPopup {
enabled: pinFieldValid
onClicked: {
submitted = true
keycardModel.authenticate(pinField.text)
popup.close()
}
}
}

View File

@ -14,6 +14,7 @@ ModalPopup {
height: 400
onOpened: {
submitted = false
pairingPasswordField.text = "";
pairingPasswordField.forceActiveFocus(Qt.MouseFocusReason)
}