Skip to content

Commit

Permalink
fix(@desktop/keycard): keycard is not recognized when inserted with w…
Browse files Browse the repository at this point in the history
…rong side

Fixes: #6960
  • Loading branch information
saledjenic committed Aug 16, 2022
1 parent 3d2d48a commit b34f0a4
Show file tree
Hide file tree
Showing 14 changed files with 93 additions and 10 deletions.
3 changes: 3 additions & 0 deletions src/app/modules/shared_modules/keycard_popup/controller.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions src/app/modules/shared_modules/keycard_popup/io_interface.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
3 changes: 3 additions & 0 deletions src/app/modules/shared_modules/keycard_popup/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 13 additions & 0 deletions src/app/modules/shared_modules/keycard_popup/view.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
11 changes: 9 additions & 2 deletions src/app/modules/startup/internal/keycard_not_empty_state.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
22 changes: 22 additions & 0 deletions ui/app/AppLayouts/Onboarding/views/KeycardInitView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand All @@ -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
Expand All @@ -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
Expand All @@ -92,6 +110,10 @@ Item {
font.pixelSize: Constants.keycard.general.fontSize2
color: Theme.palette.baseColor1
}
PropertyChanges {
target: info
visible: false
}
}
]
}
8 changes: 5 additions & 3 deletions ui/app/AppLayouts/Onboarding/views/LoginView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -880,4 +882,4 @@ Item {
}
}
]
}
}
6 changes: 4 additions & 2 deletions ui/imports/shared/popups/keycard/states/KeycardInit.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion vendor/status-keycard-go

0 comments on commit b34f0a4

Please sign in to comment.