-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Omit HID libraries for hardware-wallets package on unsupported enviro…
…nments (#798).
- Loading branch information
Showing
2 changed files
with
26 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,29 @@ | ||
"use strict"; | ||
|
||
import hid from "@ledgerhq/hw-transport-node-hid"; | ||
|
||
export type TransportCreator = { | ||
create: () => Promise<Transport>; | ||
}; | ||
|
||
export const transports: { [ name: string ]: TransportCreator } = { | ||
"hid": hid, | ||
"default": hid | ||
}; | ||
let hidCache: Promise<typeof import("@ledgerhq/hw-transport-node-hid")> = null; | ||
|
||
const hidWrapper = Object.freeze({ | ||
create: function(): Promise<Transport> { | ||
// Load the library if not loaded | ||
if (hidCache == null) { | ||
hidCache = import("@ledgerhq/hw-transport-node-hid").then((hid) => { | ||
if (hid.create == null) { return hid["default"]; } | ||
return hid; | ||
}); | ||
} | ||
|
||
return hidCache.then((hid) => { | ||
console.log(hid, hid.create); | ||
return hid.create() | ||
}); | ||
} | ||
}); | ||
|
||
export const transports: { [ name: string ]: TransportCreator } = Object.freeze({ | ||
"hid": hidWrapper, | ||
"default": hidWrapper | ||
}); |