Skip to content

Commit 65a9d9b

Browse files
committed
Dynamically import hardware wallet dependencies
1 parent 80f9f79 commit 65a9d9b

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

src/modules/select/wallets/hd-wallet.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import HDKey from 'hdkey'
2-
import { publicToAddress, toChecksumAddress } from 'ethereumjs-util'
2+
import * as ethUtil from 'ethereumjs-util'
33
import buffer from 'buffer'
44

5+
const { publicToAddress, toChecksumAddress } = ethUtil
6+
57
const numberToGet = 5
68

79
export function generateAddresses(

src/modules/select/wallets/ledger.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,8 @@ import {
44
Helpers,
55
CommonWalletOptions
66
} from '../../../interfaces'
7-
import ledgerIcon from '../wallet-icons/icon-ledger'
8-
9-
import createProvider from './providerEngine'
10-
import { generateAddresses, isValidPath } from './hd-wallet'
11-
12-
import TransportU2F from '@ledgerhq/hw-transport-u2f'
13-
import Eth from '@ledgerhq/hw-app-eth'
14-
import * as EthereumTx from 'ethereumjs-tx'
15-
import * as ethUtil from 'ethereumjs-util'
167

17-
import buffer from 'buffer'
8+
import ledgerIcon from '../wallet-icons/icon-ledger'
189

1910
const LEDGER_LIVE_PATH = `m/44'/60'`
2011
const ACCOUNTS_TO_GET = 5
@@ -81,6 +72,16 @@ async function ledgerProvider(options: {
8172
BigNumber: any
8273
networkName: (id: number) => string
8374
}) {
75+
console.log('importing hardware libraries')
76+
const { default: createProvider } = await import('./providerEngine')
77+
const { generateAddresses, isValidPath } = await import('./hd-wallet')
78+
const { default: TransportU2F } = await import('@ledgerhq/hw-transport-u2f')
79+
const { default: Eth } = await import('@ledgerhq/hw-app-eth')
80+
81+
const EthereumTx = await import('ethereumjs-tx')
82+
const ethUtil = await import('ethereumjs-util')
83+
const buffer = await import('buffer')
84+
8485
const { networkId, rpcUrl, LedgerTransport, BigNumber, networkName } = options
8586

8687
let dPath = ''

src/modules/select/wallets/trezor.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@ import trezorIcon from '../wallet-icons/icon-trezor'
99
import createProvider from './providerEngine'
1010
import { generateAddresses, isValidPath } from './hd-wallet'
1111

12-
import * as TrezorConnectLibrary from 'trezor-connect'
13-
import * as EthereumTx from 'ethereumjs-tx'
14-
import * as ethUtil from 'ethereumjs-util'
15-
16-
const { default: TrezorConnect, DEVICE_EVENT, DEVICE } = TrezorConnectLibrary
17-
1812
const TREZOR_DEFAULT_PATH = "m/44'/60'/0'/0"
1913

2014
function trezor(options: TrezorOptions & CommonWalletOptions): WalletModule {
@@ -82,6 +76,12 @@ async function trezorProvider(options: {
8276
BigNumber: any
8377
networkName: (id: number) => string
8478
}) {
79+
const TrezorConnectLibrary = await import('trezor-connect')
80+
const EthereumTx = await import('ethereumjs-tx')
81+
const ethUtil = await import('ethereumjs-util')
82+
83+
const { default: TrezorConnect, DEVICE_EVENT, DEVICE } = TrezorConnectLibrary
84+
8585
const { networkId, email, appUrl, rpcUrl, BigNumber, networkName } = options
8686
let dPath: string = ''
8787

0 commit comments

Comments
 (0)