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 NimQml, chronicles, std/wrapnils
import status/[signals, status, keycard] import status/[signals, status, keycard]
import types/keycard as keycardtypes
import view, pairing import view, pairing
logScope: logScope:
@ -29,11 +30,25 @@ proc attemptOpenSecureChannel(self: KeycardController) : bool =
if pairing == "": if pairing == "":
return false 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 return false
proc getCardState(self: KeycardController) = 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 self.view.appInfo = appInfo
if not appInfo.installed: if not appInfo.installed:
@ -43,7 +58,16 @@ proc getCardState(self: KeycardController) =
self.view.cardState = PreInit self.view.cardState = PreInit
self.view.cardPreInit() self.view.cardPreInit()
elif self.attemptOpenSecureChannel(): 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.cardState = Paired
self.view.cardPaired() self.view.cardPaired()
elif appInfo.availableSlots > 0: elif appInfo.availableSlots > 0:

View File

@ -1,6 +1,6 @@
import NimQml, chronicles import NimQml, chronicles
import status/[status, keycard] import status/[status, keycard]
import status/types/keycard as keycardtypes import types/keycard as keycardtypes
import pairing import pairing
logScope: logScope:
@ -47,18 +47,47 @@ QtObject:
proc cardFrozen*(self: KeycardView) {.signal.} proc cardFrozen*(self: KeycardView) {.signal.}
proc cardBlocked*(self: KeycardView) {.signal.} proc cardBlocked*(self: KeycardView) {.signal.}
proc cardAuthenticated*(self: KeycardView) {.signal.} proc cardAuthenticated*(self: KeycardView) {.signal.}
proc cardUnhandledError*(self: KeycardView, error: string) {.signal.}
proc startConnection*(self: KeycardView) {.slot.} = 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.} = proc stopConnection*(self: KeycardView) {.slot.} =
self.cardState = Disconnected 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.} = proc pair*(self: KeycardView, password: string) {.slot.} =
discard """ discard """
on succesful pairing, save and change card state let pairing = self.status.keycard.pair(password)
otherwise throw error
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 "./Keycard"
import "../shared/keycard" import "../shared/keycard"
// this will be the entry point. for now it opens all keycard-related dialogs in sequence for test
Item { Item {
enum OnboardingFlow {
Recover,
Generate,
ImportMnemonic
}
property var onClosed: function () {} property var onClosed: function () {}
property bool connected: false property bool connected: false
property int flow: OnboardingFlow.Recover
id: keycardView id: keycardView
anchors.fill: parent anchors.fill: parent
@ -17,9 +23,11 @@ Item {
CreatePINModal { CreatePINModal {
id: createPinModal id: createPinModal
onClosed: function () { onClosed: function () {
if (!createPinModal.submitted) {
keycardView.onClosed() keycardView.onClosed()
} }
} }
}
PairingModal { PairingModal {
id: pairingModal id: pairingModal
@ -33,9 +41,11 @@ Item {
PINModal { PINModal {
id: pinModal id: pinModal
onClosed: function () { onClosed: function () {
if (!pinModal.submitted) {
keycardView.onClosed() keycardView.onClosed()
} }
} }
}
InsertCard { InsertCard {
id: insertCard id: insertCard
@ -54,13 +64,28 @@ Item {
} }
onCardPaired: { 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 //TODO: support the states below
onCardPreInit: { onCardPreInit: {
keycardView.onClosed() createPinModal.open()
} }
onCardFrozen: { onCardFrozen: {
@ -76,14 +101,11 @@ Item {
// later add factory reset option for the NoFreeSlots case // later add factory reset option for the NoFreeSlots case
onCardNoFreeSlots: { onCardNoFreeSlots: {
//status-lib currently always returns availableSlots = 0 so we end up here keycardView.onClosed()
//keycardView.onClosed()
pairingModal.open()
} }
onCardNotKeycard: { onCardNotKeycard: {
keycardView.onClosed() keycardView.onClosed()
} }
} }

View File

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

View File

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

View File

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