Skip to content

Commit

Permalink
fix: ledger exception
Browse files Browse the repository at this point in the history
  • Loading branch information
bangjelkoski committed Nov 7, 2023
1 parent f6b269c commit 9d9b7f8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 21 deletions.
15 changes: 3 additions & 12 deletions packages/exceptions/src/exceptions/LedgerException.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ const isCommonLockedError = (error: string) => {
'Ledger device: Incorrect length',
'Ledger device: INS_NOT_SUPPORTED',
'Ledger device: CLA_NOT_SUPPORTED',
'CLA_NOT_SUPPORTED',
'CLA',
'Locked',
'Failed to open the device',
'Failed to open the device',
'Ledger Device is busy',
Expand Down Expand Up @@ -44,18 +47,6 @@ export class LedgerException extends ConcreteException {
)
}

if (message.includes('locked')) {
this.setMessage(
'Please make sure your Ledger device is connected, unlocked and your Ethereum app is open',
)
}

if (message.includes('CLA')) {
this.setMessage(
'Please make sure your Ledger device is connected, unlocked and your Ethereum app is open',
)
}

if (message.includes('Unable to set device configuration.')) {
this.setMessage(
'Please restart your Ledger device and try connecting again',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,21 @@ export default class LedgerTransport {
}

async getInstance(): Promise<EthereumApp> {
const EthereumApp = await import('@ledgerhq/hw-app-eth')

if (this.ledger) {
return this.ledger
}

try {
if (!this.ledger) {
const transport = await LedgerTransport.getTransport()
const EthereumApp = await import('@ledgerhq/hw-app-eth')
const transport = await LedgerTransport.getTransport()

this.ledger = new EthereumApp.default(transport)
this.ledger = new EthereumApp.default(transport)

transport.on('disconnect', () => {
this.ledger = null
this.accountManager = null
})
}
transport.on('disconnect', () => {
this.ledger = null
this.accountManager = null
})

return this.ledger
} catch (e) {
Expand Down

0 comments on commit 9d9b7f8

Please sign in to comment.