-
Notifications
You must be signed in to change notification settings - Fork 434
π (cls): Remap device disconnected error #10402
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
π (cls): Remap device disconnected error #10402
Conversation
The latest updates on your projects. Learn more about Vercel for Git βοΈ 4 Skipped Deployments
|
dd33de0
to
425ed34
Compare
425ed34
to
9fdd43a
Compare
9fdd43a
to
9db6fa1
Compare
9db6fa1
to
8bf165e
Compare
8bf165e
to
fe647a7
Compare
0adb632
to
746eb04
Compare
const translatedErrorStringId = `errors.${error._tag}.${field}`; | ||
if (t(translatedErrorStringId) !== translatedErrorStringId) { | ||
return <Text>{t(translatedErrorStringId)}</Text>; | ||
} else { | ||
const message = | ||
field === "title" | ||
? error._tag | ||
: (error?.originalError as Error)?.message ?? error.message ?? error._tag; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const translatedErrorStringId = `errors.${error._tag}.${field}`; | |
if (t(translatedErrorStringId) !== translatedErrorStringId) { | |
return <Text>{t(translatedErrorStringId)}</Text>; | |
} else { | |
const message = | |
field === "title" | |
? error._tag | |
: (error?.originalError as Error)?.message ?? error.message ?? error._tag; | |
const translatedKey = `errors.${error._tag}.${field}`; | |
const translated = t(translatedKey); | |
if (translated !== translatedKey) { | |
return <Text>{translated}</Text>; | |
} | |
const fallbackMessage = | |
field === "title" | |
? error._tag | |
: (error?.originalError as Error)?.message ?? error.message ?? error._tag; | |
return <Text>{t(`errors.generic.${field}`, { message: fallbackMessage })}</Text>; |
I think it has better readability and avoid repeated translation calls.
translatedKey
andtranslated
make the intent clearer.- We evaluate
t(translatedKey)
only once to avoid unnecessary function calls.
746eb04
to
0be0f1a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR remaps the device disconnected error from DMK during a custom lock screen update and updates the associated error handling and device selection workflows. Key changes include:
- Replacing withDevice with withTransport in customLockScreenLoad to address device session removal and updating error handling for DMK disconnect cases.
- Updating tests in customLockScreenLoad.test to align with the new transport API.
- Enhancing the device selection hook and UI in the mobile app by introducing selectDevice and registerDeviceSelection functions, along with updating related components and localization.
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
libs/ledger-live-common/src/hw/customLockScreenLoad.ts | Refactors device API usage by replacing withDevice with withTransport and adds DMK error type checking |
libs/ledger-live-common/src/hw/customLockScreenLoad.test.ts | Updates tests to support transportRef and DMK error scenarios |
apps/ledger-live-mobile/src/newArch/features/DeviceSelection/screens/SelectDevice/useSelectDeviceViewModel.ts | Adds a callback registration and updates device selection handling |
apps/ledger-live-mobile/src/newArch/features/DeviceSelection/screens/SelectDevice/index.tsx | Updates component props to use the new device selection API |
apps/ledger-live-mobile/src/locales/en/common.json | Extends localization for DMK errors |
apps/ledger-live-mobile/src/components/TranslatedError/TranslatedError.tsx | Adjusts error translation for DMK errors using new keys |
.changeset/*.md | Documents the changes with appropriate release notes |
Comments suppressed due to low confidence (1)
apps/ledger-live-mobile/src/components/TranslatedError/TranslatedError.tsx:31
- [nitpick] Consider adding a comment to explain the fallback behavior in error translation when a specific DMK error translation key is missing, so future developers understand the rationale behind calling the generic translation.
const translatedKey = `errors.${error._tag}.${field}`;
const isDmkDeviceDisconnectedError = (err: unknown): err is DeviceDisconnectedWhileSendingError => | ||
err !== null && | ||
(err instanceof DeviceDisconnectedWhileSendingError || | ||
(typeof err === "object" && | ||
"_tag" in err && | ||
err._tag === "DeviceDisconnectedWhileSendingError")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type guard for DMK device disconnection error works as expected; consider ensuring that checking for 'err !== null' and property '_tag' is sufficient for all cases you expect, and document its intent for future maintainers.
const isDmkDeviceDisconnectedError = (err: unknown): err is DeviceDisconnectedWhileSendingError => | |
err !== null && | |
(err instanceof DeviceDisconnectedWhileSendingError || | |
(typeof err === "object" && | |
"_tag" in err && | |
err._tag === "DeviceDisconnectedWhileSendingError")); | |
/** | |
* Type guard to check if the given error is a DeviceDisconnectedWhileSendingError. | |
* Ensures that the error is an object, is not null, and matches the expected structure. | |
* This is used to identify specific disconnection errors from the DMK device. | |
*/ | |
const isDmkDeviceDisconnectedError = (err: unknown): err is DeviceDisconnectedWhileSendingError => | |
typeof err === "object" && | |
err !== null && | |
(err instanceof DeviceDisconnectedWhileSendingError || | |
("_tag" in err && err._tag === "DeviceDisconnectedWhileSendingError")); |
Copilot uses AI. Check for mistakes.
5a04fff
0be0f1a
to
5a04fff
Compare
use withTransport instead of withDevice to fix retry after device session removed
use withTransport instead of withDevice to fix retry after device session removed
5a04fff
to
7b4329c
Compare
|
β Checklist
npx changeset
was attached.π Description
Map device disconnected from DMK during CLS update
use of withTransport instead of withDevice to fix retry after device session removed
β Context
π§ Checklist for the PR Reviewers