Skip to content

fix(typescript): distinguish malformed amount from non-positive in hosted order build - #2632

Open
ibrhmyi wants to merge 5 commits into
pmxt-dev:mainfrom
ibrhmyi:contributor/issue-2423-3e74fc194a
Open

ibrhmyi wants to merge 5 commits into
pmxt-dev:mainfrom
ibrhmyi:contributor/issue-2423-3e74fc194a

Conversation

@ibrhmyi

@ibrhmyi ibrhmyi commented Oct 31, 2026

Copy link
Copy Markdown

Closes #2423.

For a malformed (non-numeric) amount passed to hosted buildOrder/createOrder, the TypeScript SDK raised the same "amount must be positive" message it uses for a genuinely non-positive numeric amount (Number("garbage") is NaN, and NaN > 0 is false). The Python SDK distinguishes the two cases. This aligns TypeScript with Python's two-message scheme (the more informative of the two options in the issue):

Change

  • sdks/typescript/pmxt/client.ts (_hostedBuildOrderBody): a finite-number guard now raises InvalidOrder("amount must be a finite positive number") for malformed/non-finite input before the existing positivity check; the amount must be positive branch is unchanged for finite <= 0 values
  • Side effect: Infinity no longer leaks into to6dec (which died with "invalid amount: Infinity")

Tests

  • New hosted buildOrder amount validation suite (5 cases: non-numeric string, negative, zero, NaN, Infinity) — the guard runs before any network/wallet access, so all reject locally
  • RED on unmodified code: string/NaN threw the positivity message, Infinity threw the to6dec message (3 of 5 failing)
  • Full TS SDK suite: 98 passed (baseline 93); tsc --noEmit clean

AI assistance was used for this contribution (implementation and review).

This branch has not been deployed

No deployments
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.

SDK drift: hosted order-build amount-validation error message doesn't distinguish malformed vs. non-positive input in TypeScript, but does in Python

1 participant