Skip to content

fix(utils): handle string scientific notation in parseUnits - #1990

Closed
Lesnak1 wants to merge 1 commit into
ProjectOpenSea:mainfrom
Lesnak1:fix/parse-units-scientific-notation-strings
Closed

fix(utils): handle string scientific notation in parseUnits#1990
Lesnak1 wants to merge 1 commit into
ProjectOpenSea:mainfrom
Lesnak1:fix/parse-units-scientific-notation-strings

Conversation

@Lesnak1

@Lesnak1 Lesnak1 commented Aug 12, 2026

Copy link
Copy Markdown

Summary

Fixes a SyntaxError in parseUnits when passing a string formatted in scientific notation (e.g. "1e-8", "1.5e-5", "1E-6").

Previously, the scientific notation check checked typeof value === "number" && str.includes("e"). When value was passed as a string containing exponential notation ("1e-8"), the condition evaluated to false, leaving str as "1e-8". During unit calculation, this produced "1e-8000000000000000000", causing BigInt(...) to throw SyntaxError: Cannot convert 1e-8000000000000000000 to a BigInt.

Changes

  • Updated parseUnits in src/utils/units.ts to check str.toLowerCase().includes("e") regardless of whether value was passed as a number or string.
  • Added unit test cases for string scientific notation in test/utils/units.spec.ts.

Testing

  • Confirmed test handles string scientific notation failed on main with SyntaxError.
  • Confirmed all 792 tests across 36 test files pass cleanly (npm test).

@ryanio

ryanio commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator

Thanks for this! We recreated the fix in our internal monorepo, with you credited as co-author on the commit: parseUnits now expands exponent notation from strings using string math, so parseUnits("1e-8", 18) works, and wrapEth / unwrapWeth / the listing price path no longer crash on small numeric amounts.

This repo is a read-only mirror, so we can't merge PRs here directly, but we read every one. This will ship in the next @opensea/sdk release. Note that we've also renamed this repo from opensea-js to opensea-sdk. Appreciate you taking the time.

@ryanio ryanio closed this Aug 14, 2026
@Lesnak1

Lesnak1 commented Aug 15, 2026

Copy link
Copy Markdown
Author

Thanks @ryanio ! Glad to help make @opensea/sdk more resilient for numeric edge cases. Looking forward to the upcoming release!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants