Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: LIVE-11803 - rename device broken if an app is open #6773

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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>;
}