Skip to content

Commit

Permalink
LIVE-2641 Prevent emitting an event when device descriptor is null (#…
Browse files Browse the repository at this point in the history
…1070)

* LIVE-2641 Prevent emitting an event when device descriptor is null

* LIVE-2641 Add changeset

* LIVE-2641 fix linting

* LIVE-2641 Fix linting
  • Loading branch information
grsoares21 committed Aug 29, 2022
1 parent 10916fa commit 533e658
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
6 changes: 6 additions & 0 deletions .changeset/rotten-seals-mix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"live-mobile": patch
"@ledgerhq/react-native-hw-transport-ble": patch
---

Fix crash when scanning for bluetooth devices
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import Transport from "@ledgerhq/hw-transport";
import { from } from "rxjs";
import { take, first, filter } from "rxjs/operators";
import type { Device } from "@ledgerhq/react-native-hw-transport-ble/lib/types";
import type {
Observer as TransportObserver,
DescriptorEvent,
} from "@ledgerhq/hw-transport";
import type { ApduMock } from "../logic/createAPDUMock";
import { hookRejections } from "../logic/debugReject";
import { e2eBridgeSubject } from "../../e2e/bridge/client";
Expand Down Expand Up @@ -36,7 +41,7 @@ export default (opts: Opts) => {
// eslint-disable-next-line @typescript-eslint/no-empty-function
static setLogLevel = (_param: string) => {};

static listen(observer: any) {
static listen(observer: TransportObserver<DescriptorEvent<Device>>) {
return e2eBridgeSubject
.pipe(
filter(msg => msg.type === "add"),
Expand Down
3 changes: 2 additions & 1 deletion apps/ledger-live-mobile/src/screens/PairDevices/Scanning.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useTranslation } from "react-i18next";
import { Observable } from "rxjs";
import { InfiniteLoader } from "@ledgerhq/native-ui";
import { getInfosForServiceUuid, DeviceModelId } from "@ledgerhq/devices";
import { DescriptorEvent } from "@ledgerhq/hw-transport";
import logger from "../../logger";
import { BLE_SCANNING_NOTHING_TIMEOUT } from "../../constants";
import { knownDevicesSelector } from "../../reducers/ble";
Expand Down Expand Up @@ -61,7 +62,7 @@ export default function Scanning({ onTimeout, onError, onSelect }: Props) {
}, BLE_SCANNING_NOTHING_TIMEOUT);

const sub = Observable.create(TransportBLE.listen).subscribe({
next: (e: { type: string; descriptor: any }) => {
next: (e: DescriptorEvent<Device>) => {
if (e.type === "add") {
clearTimeout(timeout);
const device = e.descriptor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ export default class BluetoothTransport extends Transport {
* Scan for bluetooth Ledger devices
*/
static listen(
observer: TransportObserver<DescriptorEvent<Device | null>>
observer: TransportObserver<DescriptorEvent<Device>>
): TransportSubscription {
log("ble-verbose", "listen...");
let unsubscribed;
Expand Down Expand Up @@ -369,11 +369,14 @@ export default class BluetoothTransport extends Transport {

const res = retrieveInfos(device);
const deviceModel = res && res.deviceModel;
observer.next({
type: "add",
descriptor: device,
deviceModel,
});

if (device) {
observer.next({
type: "add",
descriptor: device,
deviceModel,
});
}
}
);
}
Expand Down

0 comments on commit 533e658

Please sign in to comment.