From 541dc536468d10ebe4b237fb502e87f8c03bd1d6 Mon Sep 17 00:00:00 2001 From: "Valentin D. Pinkman" Date: Fri, 17 Jan 2025 16:12:33 +0100 Subject: [PATCH] ubuntu yolo fix errorRemapping --- .../src/renderer/hooks/useListenToHidDevices.ts | 8 +++++++- libs/ledger-live-common/package.json | 1 + libs/ledger-live-common/src/hw/actions/app.ts | 4 ++-- libs/ledger-live-common/src/hw/deviceAccess.ts | 13 ++++++++++--- libs/live-dmk/src/config/errors.ts | 8 ++++++++ .../src/hooks/useDeviceSessionRefresherToggle.tsx | 9 ++++++--- libs/live-dmk/src/index.ts | 5 ++++- pnpm-lock.yaml | 3 +++ 8 files changed, 41 insertions(+), 10 deletions(-) diff --git a/apps/ledger-live-desktop/src/renderer/hooks/useListenToHidDevices.ts b/apps/ledger-live-desktop/src/renderer/hooks/useListenToHidDevices.ts index 64708532fc6c..e4f42d5d0290 100644 --- a/apps/ledger-live-desktop/src/renderer/hooks/useListenToHidDevices.ts +++ b/apps/ledger-live-desktop/src/renderer/hooks/useListenToHidDevices.ts @@ -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"; @@ -13,6 +17,8 @@ export const useListenToHidDevices = () => { const deviceManagementKit = useDeviceManagementKit(); + useDeviceSessionRefresherToggle(ldmkFeatureFlag?.enabled ?? false); + useEffect(() => { let sub: Subscription; diff --git a/libs/ledger-live-common/package.json b/libs/ledger-live-common/package.json index 81ec3edb20b1..9026a99b81a1 100644 --- a/libs/ledger-live-common/package.json +++ b/libs/ledger-live-common/package.json @@ -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:^", diff --git a/libs/ledger-live-common/src/hw/actions/app.ts b/libs/ledger-live-common/src/hw/actions/app.ts index 08bdb5a10e29..e1963fbeb4b5 100644 --- a/libs/ledger-live-common/src/hw/actions/app.ts +++ b/libs/ledger-live-common/src/hw/actions/app.ts @@ -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 }; @@ -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), diff --git a/libs/ledger-live-common/src/hw/deviceAccess.ts b/libs/ledger-live-common/src/hw/deviceAccess.ts index 553465e8acf2..1fdecf9aca54 100644 --- a/libs/ledger-live-common/src/hw/deviceAccess.ts +++ b/libs/ledger-live-common/src/hw/deviceAccess.ts @@ -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 { @@ -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"; @@ -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}`, @@ -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 }); diff --git a/libs/live-dmk/src/config/errors.ts b/libs/live-dmk/src/config/errors.ts index 369eb4eb9079..6972a7b70d21 100644 --- a/libs/live-dmk/src/config/errors.ts +++ b/libs/live-dmk/src/config/errors.ts @@ -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; +}; diff --git a/libs/live-dmk/src/hooks/useDeviceSessionRefresherToggle.tsx b/libs/live-dmk/src/hooks/useDeviceSessionRefresherToggle.tsx index 148b66b60180..6aacf02cc6fe 100644 --- a/libs/live-dmk/src/hooks/useDeviceSessionRefresherToggle.tsx +++ b/libs/live-dmk/src/hooks/useDeviceSessionRefresherToggle.tsx @@ -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, }); } @@ -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, }); } }; @@ -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]); diff --git a/libs/live-dmk/src/index.ts b/libs/live-dmk/src/index.ts index f50f212d4cd1..0724234c537b 100644 --- a/libs/live-dmk/src/index.ts +++ b/libs/live-dmk/src/index.ts @@ -1,3 +1,6 @@ export { DeviceManagementKitTransport } from "./transport/DeviceManagementKitTransport"; export * from "./hooks"; -export { isAllowedOnboardingStatePollingErrorDmk } from "./config/errors"; +export { + isAllowedOnboardingStatePollingErrorDmk, + isAllowedWithDeviceErrorDmk, +} from "./config/errors"; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b2e41fea9589..bb1c14780e4c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4095,6 +4095,9 @@ importers: '@ledgerhq/live-countervalues-react': specifier: workspace:^ version: link:../live-countervalues-react + '@ledgerhq/live-dmk': + specifier: workspace:^ + version: link:../live-dmk '@ledgerhq/live-env': specifier: workspace:^ version: link:../env