Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add valid state transitions for Ledger signer #622

Merged
merged 1 commit into from
Nov 16, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions main/signers/ledger/Ledger/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const ns = '3bbcee75-cecc-5b56-8031-b6641c1ed1f1'
export const Status = {
INITIAL: 'Connecting',
OK: 'ok',
LOADING: 'loading',
DERIVING: 'Deriving addresses',
LOCKED: 'Please unlock your ledger',
WRONG_APP: 'Open your Ledger and select the Ethereum application',
Expand Down Expand Up @@ -184,8 +183,19 @@ export default class Ledger extends Signer {
}
}

private isValidStatusTransition (status: string) {
// TODO: outline all valid state transitions
if (status === Status.DERIVING) {
return [Status.OK, Status.INITIAL].includes(this.status)
}

return true
}

updateStatus (status: string) {
this.status = status
if (this.isValidStatusTransition(status)) {
this.status = status
}

if (this.status === Status.OK) {
clearInterval(this.statusPoller)
Expand Down