fix(common): improve resilience when market API returns no data for currency#14922
Merged
gre-ledger merged 1 commit intodevelopfrom Mar 2, 2026
Merged
Conversation
…urrency id Guard getCurrencyData transformResponse against empty API response to prevent 'Cannot read property id of undefined' crash. Return undefined when id does not resolve to a currency. Add test for empty response case. Made-with: Cursor
Contributor
There was a problem hiding this comment.
Pull request overview
Improves robustness of the market “currency data” query in @ledgerhq/live-common by preventing a crash when the Countervalues Market API returns an empty array for an unknown/unsupported currency id.
Changes:
- Update
getCurrencyDataRTK Query endpoint to returnundefinedwhen the API returns no items instead of callingformat(response[0])and crashing. - Add a unit test covering the empty-array response scenario with MSW.
- Add a changeset describing the behavior change.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| libs/ledger-live-common/src/market/state-manager/countervaluesApi.ts | Guards transformResponse and widens the endpoint’s data type to allow undefined on empty API response. |
| libs/ledger-live-common/src/market/hooks/tests/useCurrencyData.test.ts | Adds MSW override + assertion that the query succeeds with data: undefined for empty responses. |
| .changeset/market-currency-id-resilience.md | Declares the package release bump for the change. |
|
mcayuelas-ledger
approved these changes
Mar 2, 2026
LucasWerey
approved these changes
Mar 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



✅ Checklist
npx changesetwas attached.useCurrencyData.test.ts.useCurrencyDatareturnsdata: undefined. QA: open Market coin detail for an unsupported/edge currency and confirm no crash and graceful handling.📝 Description
Problem: Requesting market data for a currency id that doesn’t exist in the API (e.g. unknown or unsupported coin) returned an empty array. The code did
format(response[0])without checking, causingTypeError: Cannot read property 'id' of undefinedin thegetCurrencyDatatransformResponse.Solution: Guard the transformResponse: only call
format(response[0])whenresponse?.[0]exists; otherwise returnundefined. Type the endpoint asMarketCurrencyData | undefined. Added a unit test for the empty-response case.[]for the requested iddata: undefined; callers can handle “no market data”❓ Context
🧐 Checklist for the PR Reviewers