diff --git a/.changeset/tame-brooms-breathe.md b/.changeset/tame-brooms-breathe.md new file mode 100644 index 000000000000..bdfacac62536 --- /dev/null +++ b/.changeset/tame-brooms-breathe.md @@ -0,0 +1,6 @@ +--- +"live-mobile": patch +"@ledgerhq/live-common": patch +--- + +Triggering proper errors on CLS diff --git a/apps/ledger-live-mobile/src/components/CustomLockScreenDeviceAction/index.tsx b/apps/ledger-live-mobile/src/components/CustomLockScreenDeviceAction/index.tsx index 8015f820d8f1..67f8ac599782 100644 --- a/apps/ledger-live-mobile/src/components/CustomLockScreenDeviceAction/index.tsx +++ b/apps/ledger-live-mobile/src/components/CustomLockScreenDeviceAction/index.tsx @@ -88,7 +88,19 @@ const CustomImageDeviceAction: React.FC void }> = ({ [dispatch, onResult], ); - const { error, imageCommitRequested, imageLoadRequested, loadingImage, progress } = status; + const { + error: CLSError, + imageCommitRequested, + imageLoadRequested, + loadingImage, + progress, + } = status; + const [error, setError] = useState(null); + useEffect(() => { + if (CLSError) { + setError(CLSError); + } + }, [CLSError]); const isError = !!error; const isRefusedOnStaxError = (error as unknown) instanceof ImageLoadRefusedOnDevice || diff --git a/libs/ledger-live-common/src/hw/customLockScreenLoad.ts b/libs/ledger-live-common/src/hw/customLockScreenLoad.ts index 18f2c5513e12..86516b9929dc 100644 --- a/libs/ledger-live-common/src/hw/customLockScreenLoad.ts +++ b/libs/ledger-live-common/src/hw/customLockScreenLoad.ts @@ -1,11 +1,12 @@ import { Observable, from, of, throwError } from "rxjs"; -import { catchError, concatMap, delay, mergeMap } from "rxjs/operators"; +import { catchError, concatMap, delay, mergeMap, timeout } from "rxjs/operators"; import { DeviceOnDashboardExpected, ManagerNotEnoughSpaceError, StatusCodes, TransportError, TransportStatusError, + DisconnectedDevice, } from "@ledgerhq/errors"; import { getDeviceModel } from "@ledgerhq/devices"; @@ -74,9 +75,7 @@ export default function loadImage({ deviceId, request }: Input): Observable new Observable(subscriber => { - const timeoutSub = of({ - type: "unresponsiveDevice", - }) + const timeoutSub = of({ type: "unresponsiveDevice" }) .pipe(delay(1000)) .subscribe(e => subscriber.next(e)); @@ -213,6 +212,14 @@ export default function loadImage({ deviceId, request }: Input): Observable { + if (err.name === "TimeoutError") { + return throwError(() => new DisconnectedDevice()); + } + return throwError(() => err); + }), ); return sub as Observable;