fix(orders): fix nullish coalescing on toString in getNFTItems#1922
Closed
Viktohblake wants to merge 3 commits intoProjectOpenSea:mainfrom
Closed
fix(orders): fix nullish coalescing on toString in getNFTItems#1922Viktohblake wants to merge 3 commits intoProjectOpenSea:mainfrom
Viktohblake wants to merge 3 commits intoProjectOpenSea:mainfrom
Conversation
quantities[index].toString() ?? "1" crashes with TypeError when quantities array is shorter than nfts array, because .toString() is called on undefined before the nullish coalescing can provide the fallback. Move the optional chain operator before .toString() so the ?? "1" default actually works as intended.
Verify that the optional chaining fix in getNFTItems correctly defaults the amount to "1" when quantities array index is undefined.
3 tasks
Collaborator
|
Great catch @Viktohblake! The optional chaining fix is spot-on — We've opened #1928 which cherry-picks your code fix and tests (without the unrelated Closing in favor of #1928. |
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.
Motivation
When bulk listing NFTs, if the quantities array is shorter than the nfts array, quantities[index] is undefined. Calling .toString() on undefined throws a TypeError before the ?? "1" fallback can execute — making the fallback dead code.
Solution
Fixed incorrect operator precedence in getNFTItems where quantities[index].toString() ?? "1" would crash with a TypeError instead of falling back to "1" when quantities[index] is undefined.
Applied optional chaining before .toString() so the nullish coalescing default actually triggers: quantities[index]?.toString() ?? "1".
Test
Verify bulk listing with matching quantities and nfts arrays still works as before
Verify bulk listing where quantities array is shorter than nfts gracefully defaults to "1" instead of crashing