From b34f0a473655e26b37246eb4198f3c66d7be66ad Mon Sep 17 00:00:00 2001 From: Sale Djenic Date: Fri, 12 Aug 2022 09:33:12 +0200 Subject: [PATCH] fix(@desktop/keycard): keycard is not recognized when inserted with wrong side Fixes: #6960 --- .../keycard_popup/controller.nim | 3 +++ .../internal/insert_keycard_state.nim | 6 +++++ .../keycard_popup/io_interface.nim | 3 +++ .../shared_modules/keycard_popup/module.nim | 3 +++ .../shared_modules/keycard_popup/view.nim | 13 +++++++++++ .../internal/keycard_insert_keycard_state.nim | 6 +++++ ...eycard_max_pairing_slots_reached_state.nim | 7 +++++- .../keycard_max_puk_retries_reached_state.nim | 7 +++++- .../internal/keycard_not_empty_state.nim | 11 ++++++++-- .../login_keycard_insert_keycard_state.nim | 6 +++++ .../Onboarding/views/KeycardInitView.qml | 22 +++++++++++++++++++ .../AppLayouts/Onboarding/views/LoginView.qml | 8 ++++--- .../popups/keycard/states/KeycardInit.qml | 6 +++-- vendor/status-keycard-go | 2 +- 14 files changed, 93 insertions(+), 10 deletions(-) diff --git a/src/app/modules/shared_modules/keycard_popup/controller.nim b/src/app/modules/shared_modules/keycard_popup/controller.nim index e047da52cb0..fb0f7944965 100644 --- a/src/app/modules/shared_modules/keycard_popup/controller.nim +++ b/src/app/modules/shared_modules/keycard_popup/controller.nim @@ -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 diff --git a/src/app/modules/shared_modules/keycard_popup/internal/insert_keycard_state.nim b/src/app/modules/shared_modules/keycard_popup/internal/insert_keycard_state.nim index d85077d0870..58c87cc0c11 100644 --- a/src/app/modules/shared_modules/keycard_popup/internal/insert_keycard_state.nim +++ b/src/app/modules/shared_modules/keycard_popup/internal/insert_keycard_state.nim @@ -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 \ No newline at end of file diff --git a/src/app/modules/shared_modules/keycard_popup/io_interface.nim b/src/app/modules/shared_modules/keycard_popup/io_interface.nim index 07ab8f9fc66..82523d8c0d6 100644 --- a/src/app/modules/shared_modules/keycard_popup/io_interface.nim +++ b/src/app/modules/shared_modules/keycard_popup/io_interface.nim @@ -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") diff --git a/src/app/modules/shared_modules/keycard_popup/module.nim b/src/app/modules/shared_modules/keycard_popup/module.nim index 9d4184d7716..7f4954b2f39 100644 --- a/src/app/modules/shared_modules/keycard_popup/module.nim +++ b/src/app/modules/shared_modules/keycard_popup/module.nim @@ -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: diff --git a/src/app/modules/shared_modules/keycard_popup/view.nim b/src/app/modules/shared_modules/keycard_popup/view.nim index 19c793e302a..ae89abe18dc 100644 --- a/src/app/modules/shared_modules/keycard_popup/view.nim +++ b/src/app/modules/shared_modules/keycard_popup/view.nim @@ -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() diff --git a/src/app/modules/startup/internal/keycard_insert_keycard_state.nim b/src/app/modules/startup/internal/keycard_insert_keycard_state.nim index 8390afa5644..a1b2fbd0766 100644 --- a/src/app/modules/startup/internal/keycard_insert_keycard_state.nim +++ b/src/app/modules/startup/internal/keycard_insert_keycard_state.nim @@ -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 \ No newline at end of file diff --git a/src/app/modules/startup/internal/keycard_max_pairing_slots_reached_state.nim b/src/app/modules/startup/internal/keycard_max_pairing_slots_reached_state.nim index ba70fcc4237..c7d1d182da4 100644 --- a/src/app/modules/startup/internal/keycard_max_pairing_slots_reached_state.nim +++ b/src/app/modules/startup/internal/keycard_max_pairing_slots_reached_state.nim @@ -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 = diff --git a/src/app/modules/startup/internal/keycard_max_puk_retries_reached_state.nim b/src/app/modules/startup/internal/keycard_max_puk_retries_reached_state.nim index e412d499c0d..3ae8e89193a 100644 --- a/src/app/modules/startup/internal/keycard_max_puk_retries_reached_state.nim +++ b/src/app/modules/startup/internal/keycard_max_puk_retries_reached_state.nim @@ -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 = diff --git a/src/app/modules/startup/internal/keycard_not_empty_state.nim b/src/app/modules/startup/internal/keycard_not_empty_state.nim index 7abee2cf255..e35661b881b 100644 --- a/src/app/modules/startup/internal/keycard_not_empty_state.nim +++ b/src/app/modules/startup/internal/keycard_not_empty_state.nim @@ -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 = diff --git a/src/app/modules/startup/internal/login_keycard_insert_keycard_state.nim b/src/app/modules/startup/internal/login_keycard_insert_keycard_state.nim index a587d18f1fc..4384deb5c02 100644 --- a/src/app/modules/startup/internal/login_keycard_insert_keycard_state.nim +++ b/src/app/modules/startup/internal/login_keycard_insert_keycard_state.nim @@ -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 \ No newline at end of file diff --git a/ui/app/AppLayouts/Onboarding/views/KeycardInitView.qml b/ui/app/AppLayouts/Onboarding/views/KeycardInitView.qml index 1ce7e0ff15e..23696aa38c5 100644 --- a/ui/app/AppLayouts/Onboarding/views/KeycardInitView.qml +++ b/ui/app/AppLayouts/Onboarding/views/KeycardInitView.qml @@ -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 + } } ] } diff --git a/ui/app/AppLayouts/Onboarding/views/LoginView.qml b/ui/app/AppLayouts/Onboarding/views/LoginView.qml index 695fbe0b431..738a304d5a0 100644 --- a/ui/app/AppLayouts/Onboarding/views/LoginView.qml +++ b/ui/app/AppLayouts/Onboarding/views/LoginView.qml @@ -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 { } } ] -} \ No newline at end of file +} diff --git a/ui/imports/shared/popups/keycard/states/KeycardInit.qml b/ui/imports/shared/popups/keycard/states/KeycardInit.qml index 78367c497d6..cff244f63a3 100644 --- a/ui/imports/shared/popups/keycard/states/KeycardInit.qml +++ b/ui/imports/shared/popups/keycard/states/KeycardInit.qml @@ -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 { diff --git a/vendor/status-keycard-go b/vendor/status-keycard-go index b6b29bc4975..3fd18f5ff11 160000 --- a/vendor/status-keycard-go +++ b/vendor/status-keycard-go @@ -1 +1 @@ -Subproject commit b6b29bc4975039bef73578c5bc52c51a63f5d25c +Subproject commit 3fd18f5ff11a0efffa8a1a2a672351dd6da63d39