Skip to content

Commit

Permalink
add valid state transitions for Ledger signer (#622)
Browse files Browse the repository at this point in the history
  • Loading branch information
mholtzman authored Nov 16, 2021
1 parent d6bf5af commit 08c67e3
Showing 1 changed file with 12 additions and 2 deletions.
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

0 comments on commit 08c67e3

Please sign in to comment.