Skip to content

Commit

Permalink
chore: minor ledger exception
Browse files Browse the repository at this point in the history
  • Loading branch information
bangjelkoski committed Nov 6, 2023
1 parent f509926 commit 416e40e
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 16 deletions.
12 changes: 12 additions & 0 deletions packages/exceptions/src/exceptions/LedgerException.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ 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
8 changes: 4 additions & 4 deletions packages/wallet-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@
"@injectivelabs/utils": "^1.14.2-beta.1",
"@keplr-wallet/cosmos": "^0.11.58",
"@keplr-wallet/types": "^0.11.58",
"@ledgerhq/hw-app-eth": "6.33.2",
"@ledgerhq/hw-transport": "6.28.3",
"@ledgerhq/hw-transport-webhid": "6.27.14",
"@ledgerhq/hw-transport-webusb": "6.27.14",
"@ledgerhq/hw-app-eth": "6.34.8",
"@ledgerhq/hw-transport": "6.28.8",
"@ledgerhq/hw-transport-webhid": "6.27.19",
"@ledgerhq/hw-transport-webusb": "6.27.19",
"@metamask/eth-sig-util": "^4.0.0",
"@solana/wallet-adapter-wallets": "^0.19.5",
"@toruslabs/torus-embed": "^1.39.0",
Expand Down
18 changes: 18 additions & 0 deletions packages/wallet-ts/src/broadcaster/MsgBroadcaster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,24 @@ export class MsgBroadcaster {
const { walletStrategy } = options
const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs]

/**
* We can only use this method when Keplr is connected
* with ledger
*/
if (walletStrategy.getWallet() === Wallet.Keplr) {
const walletDeviceType = await walletStrategy.getWalletDeviceType()
const isLedgerConnectedOnKeplr =
walletDeviceType === WalletDeviceType.Hardware

if (isLedgerConnectedOnKeplr) {
throw new GeneralException(
new Error(
'Keplr + Ledger is not available with fee delegation. Connect with Ledger directly.',
),
)
}
}

const feePayerPubKey = await this.fetchFeePayerPubKey(
options.feePayerPubKey,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import { Common, Chain, Hardfork } from '@ethereumjs/common'
import { FeeMarketEIP1559Transaction } from '@ethereumjs/tx'
import {
ErrorType,
GeneralException,
WalletException,
LedgerException,
GeneralException,
TransactionException,
UnspecifiedErrorCode,
WalletException,
} from '@injectivelabs/exceptions'
import { DirectSignResponse } from '@cosmjs/proto-signing'
import { TxGrpcApi, TxRaw, TxResponse, toUtf8 } from '@injectivelabs/sdk-ts'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import TransportWebHID from '@ledgerhq/hw-transport-webhid'
import TransportWebUSB from '@ledgerhq/hw-transport-webusb'
import type EthereumApp from '@ledgerhq/hw-app-eth'
import type Transport from '@ledgerhq/hw-transport'
import { LedgerException } from '@injectivelabs/exceptions'
import {
ErrorType,
LedgerException,
UnspecifiedErrorCode,
} from '@injectivelabs/exceptions'
import AccountManager from './AccountManager'

export default class LedgerTransport {
Expand Down Expand Up @@ -45,19 +49,27 @@ export default class LedgerTransport {
}

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

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) {
throw new LedgerException(new Error((e as any).message), {
code: UnspecifiedErrorCode,
type: ErrorType.WalletError,
contextModule: 'GetInstance',
})
}

return this.ledger
}

async getAccountManager(): Promise<AccountManager> {
Expand Down

0 comments on commit 416e40e

Please sign in to comment.