Skip to content

Commit

Permalink
ubuntu yolo fix errorRemapping
Browse files Browse the repository at this point in the history
  • Loading branch information
valpinkman committed Jan 17, 2025
1 parent 2e8b0cc commit 541dc53
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { useEffect } from "react";
import { useDispatch } from "react-redux";
import { Subscription, Observable } from "rxjs";
import { useFeature } from "@ledgerhq/live-common/featureFlags/index";
import { useDeviceManagementKit, DeviceManagementKitTransport } from "@ledgerhq/live-dmk";
import {
useDeviceManagementKit,
DeviceManagementKitTransport,
useDeviceSessionRefresherToggle,
} from "@ledgerhq/live-dmk";
import { DeviceModelId } from "@ledgerhq/types-devices";
import { IPCTransport } from "~/renderer/IPCTransport";
import { addDevice, removeDevice, resetDevices } from "~/renderer/actions/devices";
Expand All @@ -13,6 +17,8 @@ export const useListenToHidDevices = () => {

const deviceManagementKit = useDeviceManagementKit();

useDeviceSessionRefresherToggle(ldmkFeatureFlag?.enabled ?? false);

useEffect(() => {
let sub: Subscription;

Expand Down
1 change: 1 addition & 0 deletions libs/ledger-live-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@
"@ledgerhq/live-config": "workspace:^",
"@ledgerhq/live-countervalues": "workspace:^",
"@ledgerhq/live-countervalues-react": "workspace:^",
"@ledgerhq/live-dmk": "workspace:^",
"@ledgerhq/live-env": "workspace:^",
"@ledgerhq/live-hooks": "workspace:*",
"@ledgerhq/live-network": "workspace:^",
Expand Down
4 changes: 2 additions & 2 deletions libs/ledger-live-common/src/hw/actions/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ const getInitialState = (device?: Device | null | undefined, request?: AppReques
});

const reducer = (state: State, e: Event): State => {
switch (e.type) {
switch (e?.type) {
case "unresponsiveDevice":
return { ...state, unresponsive: true };

Expand Down Expand Up @@ -512,7 +512,7 @@ export const createAction = (

const sub = impl
.pipe(
tap((e: any) => log("actions-app-event", e.type, e)),
tap((e: any) => log("actions-app-event", e?.type, e)),
debounce((e: Event) => ("replaceable" in e && e.replaceable ? interval(100) : of(null))),
scan(reducer, getInitialState()),
takeWhile((s: State) => !s.requiresAppInstallation && !s.error, true),
Expand Down
13 changes: 10 additions & 3 deletions libs/ledger-live-common/src/hw/deviceAccess.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Observable, throwError, timer } from "rxjs";
import { Observable, of, throwError, timer } from "rxjs";
import { retryWhen, mergeMap, catchError } from "rxjs/operators";
import Transport from "@ledgerhq/hw-transport";
import {
Expand All @@ -17,6 +17,7 @@ import {
} from "@ledgerhq/errors";
import { LocalTracer, TraceContext, trace } from "@ledgerhq/logs";
import { getEnv } from "@ledgerhq/live-env";
import { isAllowedWithDeviceErrorDmk } from "@ledgerhq/live-dmk";
import { open, close } from ".";

const LOG_TYPE = "hw";
Expand All @@ -32,6 +33,10 @@ const initialErrorRemapping = (error: unknown, context?: TraceContext) => {
}
}

if (isAllowedWithDeviceErrorDmk(error)) {
return of(undefined);
}

trace({
type: LOG_TYPE,
message: `Initial error remapping: ${error}`,
Expand Down Expand Up @@ -273,8 +278,10 @@ export const withDevice =
.subscribe({
next: event => {
// This kind of log should be a "debug" level for ex
// tracer.trace("Job next", { event });
o.next(event);
tracer.trace("Job next", { event });
if (event) {
o.next(event);
}
},
error: error => {
tracer.trace("Job error", { error });
Expand Down
8 changes: 8 additions & 0 deletions libs/live-dmk/src/config/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,11 @@ export const isAllowedOnboardingStatePollingErrorDmk = (error: unknown): boolean

return false;
};

export const isAllowedWithDeviceErrorDmk = (error: unknown): boolean => {
if (error) {
return error instanceof DeviceBusyError || error instanceof WebHidSendReportError;
}

return false;
};
9 changes: 6 additions & 3 deletions libs/live-dmk/src/hooks/useDeviceSessionRefresherToggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export const useDeviceSessionRefresherToggle = (enabled: boolean) => {
if (sessionId.current) {
sdk.toggleDeviceSessionRefresher({
sessionId: sessionId.current,
enabled: true,
// TODO: remove this once we have a proper way to disable the refresher
enabled: false,
});
}

Expand All @@ -36,7 +37,8 @@ export const useDeviceSessionRefresherToggle = (enabled: boolean) => {
if (sessionId.current) {
sdk.toggleDeviceSessionRefresher({
sessionId: sessionId.current,
enabled: true,
// TODO: remove this once we have a proper way to disable the refresher
enabled: false,
});
}
};
Expand All @@ -48,7 +50,8 @@ export const useDeviceSessionRefresherToggle = (enabled: boolean) => {
if (sessionId.current) {
sdk.toggleDeviceSessionRefresher({
sessionId: sessionId.current,
enabled: true,
// TODO: remove this once we have a proper way to disable the refresher
enabled: false,
});
}
}, [sdk]);
Expand Down
5 changes: 4 additions & 1 deletion libs/live-dmk/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
export { DeviceManagementKitTransport } from "./transport/DeviceManagementKitTransport";
export * from "./hooks";
export { isAllowedOnboardingStatePollingErrorDmk } from "./config/errors";
export {
isAllowedOnboardingStatePollingErrorDmk,
isAllowedWithDeviceErrorDmk,
} from "./config/errors";
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 541dc53

Please sign in to comment.