Skip to content

Commit

Permalink
bugfix: LIVE-11803 - rename device broken if an app is open
Browse files Browse the repository at this point in the history
  • Loading branch information
valpinkman committed Apr 30, 2024
1 parent de5de2d commit cdb2fc9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/sharp-rabbits-accept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ledgerhq/live-common": patch
---

Add a quitApp before launching the renameDevice device flow
10 changes: 7 additions & 3 deletions libs/ledger-live-common/src/hw/actions/implementations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ type PollingImplementationConfig = {

type PollingImplementationParams<Request, EmittedEvents> = {
deviceSubject: ReplaySubject<Device | null | undefined>;
task: (params: { deviceId: string; request: Request }) => Observable<EmittedEvents>;
task: (params: {
deviceId: string;
request: Request;
wired: boolean;
}) => Observable<EmittedEvents>;
request: Request;
config?: PollingImplementationConfig;
// retryableWithDelayDisconnectedErrors has default value of [DisconnectedDevice, DisconnectedDeviceDuringOperation]
Expand Down Expand Up @@ -120,7 +124,7 @@ const pollingImplementation: Implementation = <SpecificType, GenericRequestType>
device: currentDevice,
replaceable: !firstRound,
}),
task({ deviceId: currentDevice.deviceId, request }),
task({ deviceId: currentDevice.deviceId, request, wired: currentDevice.wired }),
)
.pipe(
// Any event should clear the initialTimeout.
Expand Down Expand Up @@ -230,7 +234,7 @@ const eventImplementation: Implementation = <SpecificType, GenericRequestType>(

return concat(
initialEvent,
!device ? EMPTY : task({ deviceId: device.deviceId, request }),
!device ? EMPTY : task({ deviceId: device.deviceId, request, wired: device.wired }),
);
}),
catchError((error: Error) =>
Expand Down
28 changes: 23 additions & 5 deletions libs/ledger-live-common/src/hw/renameDevice.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Observable, concat, from, of } from "rxjs";
import { map, catchError } from "rxjs/operators";
import { map, catchError, switchMap, delay } from "rxjs/operators";
import { withDevice } from "./deviceAccess";
import editDeviceName from "./editDeviceName";
import quitApp from "./quitApp";

export type RenameDeviceEvent =
| { type: "quitApp" }
| {
type: "unresponsiveDevice";
}
Expand All @@ -19,15 +21,29 @@ export type RenameDeviceRequest = { name: string };
export type Input = {
deviceId: string;
request: RenameDeviceRequest;
wired: boolean;
};

export default function renameDevice({ deviceId, request }: Input): Observable<RenameDeviceEvent> {
export default function renameDevice({
deviceId,
request,
wired,
}: Input): Observable<RenameDeviceEvent> {
const { name } = request;

const sub = withDevice(deviceId)(
const quitAppFlow = withDevice(deviceId)(transport =>
concat(
from(quitApp(transport)).pipe(delay(wired ? 100 : 3000)),
of(<RenameDeviceEvent>{
type: "quitApp",
}),
),
);

const renameAppFlow = withDevice(deviceId)(
transport =>
new Observable(o => {
const sub = concat(
const innerSub = concat(
of(<RenameDeviceEvent>{
type: "permission-requested",
}),
Expand All @@ -45,10 +61,12 @@ export default function renameDevice({ deviceId, request }: Input): Observable<R
.subscribe(e => o.next(e));

return () => {
sub.unsubscribe();
innerSub.unsubscribe();
};
}),
);

const sub = quitAppFlow.pipe(switchMap(_ => concat(renameAppFlow)));

return sub as Observable<RenameDeviceEvent>;
}

0 comments on commit cdb2fc9

Please sign in to comment.