Skip to content
This repository has been archived by the owner on Jun 2, 2022. It is now read-only.

Commit

Permalink
Make node-ble transport optional again (LedgerHQ#1736)
Browse files Browse the repository at this point in the history
  • Loading branch information
gre authored and aimxhaisse committed Mar 5, 2022
1 parent ff681ea commit bc11caa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
4 changes: 3 additions & 1 deletion cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@
"peerDependencies": {
"@ledgerhq/hw-transport-node-ble": "5.7.0"
},
"optionalDependencies": {
"@ledgerhq/hw-transport-node-ble": "^6.24.1"
},
"dependencies": {
"@ledgerhq/cryptoassets": "6.24.1",
"@ledgerhq/errors": "6.10.0",
"@ledgerhq/hw-app-btc": "6.24.1",
"@ledgerhq/hw-transport-http": "6.24.1",
"@ledgerhq/hw-transport-mocker": "6.24.1",
"@ledgerhq/hw-transport-node-ble": "^6.24.1",
"@ledgerhq/hw-transport-node-hid": "6.24.1",
"@ledgerhq/hw-transport-node-speculos": "6.24.1",
"@ledgerhq/ledger-core": "6.14.5",
Expand Down
19 changes: 10 additions & 9 deletions cli/src/live-common-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ checkLibs({
connect,
});
import implementLibcore from "@ledgerhq/live-common/lib/libcore/platforms/nodejs";
import BluetoothTransport from "@ledgerhq/hw-transport-node-ble";

type BluetoothTransport = any;

implementLibcore({
lib: () => require("@ledgerhq/ledger-core"),
// eslint-disable-line global-require
Expand Down Expand Up @@ -78,6 +80,7 @@ if (process.env.DEVICE_PROXY_URL) {
registerTransportModule({
id: "http",
open: () =>
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
retry(() => Tr.create(3000, 5000), {
context: "open-http-proxy",
Expand Down Expand Up @@ -118,6 +121,8 @@ async function init() {

const getTransport = async (): Promise<BluetoothTransport> => {
if (!TransportNodeBle) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const { default: mod } = await import("@ledgerhq/hw-transport-node-ble");
TransportNodeBle = mod;
}
Expand All @@ -131,13 +136,9 @@ async function init() {
const [, q] = m;
if (cacheBle[query]) return cacheBle[query];
const t = await (!q
? (
(await getTransport().constructor) as typeof BluetoothTransport
).create()
? ((await getTransport().constructor) as typeof TransportNodeBle).create()
: new Observable(
(
(await getTransport().constructor) as typeof BluetoothTransport
).listen
((await getTransport().constructor) as typeof TransportNodeBle).listen
)
.pipe(
first(
Expand Down Expand Up @@ -166,7 +167,7 @@ async function init() {
let s: any;

getTransport().then((module) => {
(module.constructor as typeof BluetoothTransport).listen(o);
(module.constructor as typeof TransportNodeBle).listen(o);
s = module;
});

Expand All @@ -182,7 +183,7 @@ async function init() {
query.startsWith("ble")
? cacheBle[query]
? (
(await getTransport().constructor) as typeof BluetoothTransport
(await getTransport().constructor) as typeof TransportNodeBle
).disconnect(cacheBle[query].id)
: Promise.resolve()
: undefined,
Expand Down

0 comments on commit bc11caa

Please sign in to comment.