fix(@desktop/keycard): keycard is not recognized when inserted with wrong side

Fixes: #6960
This commit is contained in:
Sale Djenic 2022-08-12 09:33:12 +02:00 committed by saledjenic
parent 3d2d48a705
commit b34f0a4736
14 changed files with 93 additions and 10 deletions

View File

@ -41,6 +41,9 @@ proc disconnect*(self: Controller) =
for id in self.connectionIds:
self.events.disconnect(id)
proc setKeycardData*(self: Controller, value: string) =
self.delegate.setKeycardData(value)
proc containsMetadata*(self: Controller): bool =
return self.tmpKeycardContainsMetadata

View File

@ -14,6 +14,12 @@ method executePrimaryCommand*(self: InsertKeycardState, controller: Controller)
method resolveKeycardNextState*(self: InsertKeycardState, keycardFlowType: string, keycardEvent: KeycardEvent,
controller: Controller): State =
if keycardFlowType == ResponseTypeValueInsertCard and
keycardEvent.error.len > 0 and
keycardEvent.error == ErrorConnection:
controller.setKeycardData(ResponseTypeValueInsertCard)
return nil
if keycardFlowType == ResponseTypeValueCardInserted:
controller.setKeycardData("")
return createState(StateType.ReadingKeycard, self.flowType, nil)
return nil

View File

@ -17,6 +17,9 @@ method delete*(self: AccessInterface) {.base.} =
method getModuleAsVariant*(self: AccessInterface): QVariant {.base.} =
raise newException(ValueError, "No implementation available")
method setKeycardData*(self: AccessInterface, value: string) {.base.} =
raise newException(ValueError, "No implementation available")
method onBackActionClicked*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -40,6 +40,9 @@ method delete*[T](self: Module[T]) =
method getModuleAsVariant*[T](self: Module[T]): QVariant =
return self.viewVariant
method setKeycardData*[T](self: Module[T], value: string) =
self.view.setKeycardData(value)
method onBackActionClicked*[T](self: Module[T]) =
let currStateObj = self.view.currentStateObj()
if currStateObj.isNil:

View File

@ -8,6 +8,7 @@ QtObject:
delegate: io_interface.AccessInterface
currentState: StateWrapper
currentStateVariant: QVariant
keycardData: string # used to temporary store the data coming from keycard, depends on current state different data may be stored
proc delete*(self: View) =
self.currentStateVariant.delete
@ -35,6 +36,18 @@ QtObject:
QtProperty[QVariant] currentState:
read = getCurrentState
proc keycardDataChanged*(self: View) {.signal.}
proc setKeycardData*(self: View, value: string) =
if self.keycardData == value:
return
self.keycardData = value
self.keycardDataChanged()
proc getKeycardData*(self: View): string {.slot.} =
return self.keycardData
QtProperty[string] keycardData:
read = getKeycardData
notify = keycardDataChanged
proc onBackActionClicked*(self: View) {.slot.} =
self.delegate.onBackActionClicked()

View File

@ -10,6 +10,12 @@ proc delete*(self: KeycardInsertKeycardState) =
method resolveKeycardNextState*(self: KeycardInsertKeycardState, keycardFlowType: string, keycardEvent: KeycardEvent,
controller: Controller): State =
if keycardFlowType == ResponseTypeValueInsertCard and
keycardEvent.error.len > 0 and
keycardEvent.error == ErrorConnection:
controller.setKeycardData(ResponseTypeValueInsertCard)
return nil
if keycardFlowType == ResponseTypeValueCardInserted:
controller.setKeycardData("")
return createState(StateType.KeycardReadingKeycard, self.flowType, self.getBackState)
return nil

View File

@ -14,7 +14,12 @@ method executePrimaryCommand*(self: KeycardMaxPairingSlotsReachedState, controll
method executeSecondaryCommand*(self: KeycardMaxPairingSlotsReachedState, controller: Controller) =
if self.flowType == FlowType.FirstRunOldUserKeycardImport:
controller.resumeCurrentFlow()
controller.runRecoverAccountFlow()
method getNextSecondaryState*(self: KeycardMaxPairingSlotsReachedState, controller: Controller): State =
if self.flowType == FlowType.FirstRunOldUserKeycardImport:
return createState(StateType.KeycardPluginReader, self.flowType, nil)
return nil
method resolveKeycardNextState*(self: KeycardMaxPairingSlotsReachedState, keycardFlowType: string, keycardEvent: KeycardEvent,
controller: Controller): State =

View File

@ -14,7 +14,12 @@ method executePrimaryCommand*(self: KeycardMaxPukRetriesReachedState, controller
method executeSecondaryCommand*(self: KeycardMaxPukRetriesReachedState, controller: Controller) =
if self.flowType == FlowType.FirstRunOldUserKeycardImport:
controller.resumeCurrentFlow()
controller.runRecoverAccountFlow()
method getNextSecondaryState*(self: KeycardMaxPukRetriesReachedState, controller: Controller): State =
if self.flowType == FlowType.FirstRunOldUserKeycardImport:
return createState(StateType.KeycardPluginReader, self.flowType, nil)
return nil
method resolveKeycardNextState*(self: KeycardMaxPukRetriesReachedState, keycardFlowType: string, keycardEvent: KeycardEvent,
controller: Controller): State =

View File

@ -14,8 +14,15 @@ method executePrimaryCommand*(self: KeycardNotEmptyState, controller: Controller
controller.runFactoryResetPopup()
method executeSecondaryCommand*(self: KeycardNotEmptyState, controller: Controller) =
if self.flowType == FlowType.FirstRunNewUserNewKeycardKeys:
controller.resumeCurrentFlow()
if self.flowType == FlowType.FirstRunNewUserNewKeycardKeys or
self.flowType == FlowType.FirstRunNewUserImportSeedPhraseIntoKeycard:
controller.runLoadAccountFlow()
method getNextSecondaryState*(self: KeycardNotEmptyState, controller: Controller): State =
if self.flowType == FlowType.FirstRunNewUserNewKeycardKeys or
self.flowType == FlowType.FirstRunNewUserImportSeedPhraseIntoKeycard:
return createState(StateType.KeycardPluginReader, self.flowType, nil)
return nil
method resolveKeycardNextState*(self: KeycardNotEmptyState, keycardFlowType: string, keycardEvent: KeycardEvent,
controller: Controller): State =

View File

@ -16,6 +16,12 @@ method getNextTertiaryState*(self: LoginKeycardInsertKeycardState, controller: C
method resolveKeycardNextState*(self: LoginKeycardInsertKeycardState, keycardFlowType: string, keycardEvent: KeycardEvent,
controller: Controller): State =
if keycardFlowType == ResponseTypeValueInsertCard and
keycardEvent.error.len > 0 and
keycardEvent.error == ErrorConnection:
controller.setKeycardData(ResponseTypeValueInsertCard)
return nil
if keycardFlowType == ResponseTypeValueCardInserted:
controller.setKeycardData("")
return createState(StateType.LoginKeycardReadingKeycard, self.flowType, nil)
return nil

View File

@ -59,6 +59,13 @@ Item {
id: title
Layout.alignment: Qt.AlignHCenter
font.weight: Font.Bold
wrapMode: Text.WordWrap
}
StatusBaseText {
id: info
Layout.alignment: Qt.AlignHCenter
wrapMode: Text.WordWrap
}
}
@ -72,6 +79,10 @@ Item {
font.pixelSize: Constants.keycard.general.fontSize1
color: Theme.palette.directColor1
}
PropertyChanges {
target: info
visible: false
}
},
State {
name: Constants.startupState.keycardInsertKeycard
@ -82,6 +93,13 @@ Item {
font.pixelSize: Constants.keycard.general.fontSize1
color: Theme.palette.directColor1
}
PropertyChanges {
target: info
visible: root.startupStore.startupModuleInst.keycardData !== ""
text: qsTr("Check the card, it might be wrongly inserted")
font.pixelSize: Constants.keycard.general.fontSize3
color: Theme.palette.baseColor1
}
},
State {
name: Constants.startupState.keycardReadingKeycard
@ -92,6 +110,10 @@ Item {
font.pixelSize: Constants.keycard.general.fontSize2
color: Theme.palette.baseColor1
}
PropertyChanges {
target: info
visible: false
}
}
]
}

View File

@ -544,8 +544,10 @@ Item {
}
PropertyChanges {
target: message
text: ""
visible: false
visible: root.startupStore.startupModuleInst.keycardData !== ""
text: qsTr("Check the card, it might be wrongly inserted")
font.pixelSize: Constants.keycard.general.fontSize3
color: Theme.palette.baseColor1
}
PropertyChanges {
target: button
@ -880,4 +882,4 @@ Item {
}
}
]
}
}

View File

@ -103,8 +103,10 @@ Item {
}
PropertyChanges {
target: message
text: ""
visible: false
visible: root.sharedKeycardModule.keycardData !== ""
text: qsTr("Check the card, it might be wrongly inserted")
font.pixelSize: Constants.keycard.general.fontSize3
color: Theme.palette.baseColor1
}
},
State {

@ -1 +1 @@
Subproject commit b6b29bc4975039bef73578c5bc52c51a63f5d25c
Subproject commit 3fd18f5ff11a0efffa8a1a2a672351dd6da63d39