From 0984ef84a7f5a15bccf00e202514c065ed30bc0e Mon Sep 17 00:00:00 2001 From: Matt Holtzman Date: Fri, 29 Oct 2021 12:13:18 -0400 Subject: [PATCH] add valid state transitions for Ledger signer --- main/signers/ledger/Ledger/index.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/main/signers/ledger/Ledger/index.ts b/main/signers/ledger/Ledger/index.ts index 63dbb4e49..3b6751b7d 100644 --- a/main/signers/ledger/Ledger/index.ts +++ b/main/signers/ledger/Ledger/index.ts @@ -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', @@ -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)