Skip to content

fix: make numberFormat always return a string - #858

Merged
grunch merged 1 commit into
mainfrom
fix/numberformat-always-string
Jul 2, 2026
Merged

fix: make numberFormat always return a string#858
grunch merged 1 commit into
mainfrom
fix/numberformat-always-string

Conversation

@grunch

@grunch grunch commented Jul 2, 2026

Copy link
Copy Markdown
Member

Closes #855

numberFormat had an inconsistent return type (false | number | string), and its results are interpolated directly into user-facing strings (order descriptions, order titles, trading volume). Nothing breaks today because every caller validates the currency first, but that invariant was implicit — the first future caller that skips the getCurrency check would publish a title like "Selling false sats" to the order channel.

Changes

  • numberFormat now has an explicit : string return type and falls back to String(number) in every non-formattable case (invalid ISO-4217 code, unknown currency, missing locale, NaN).
  • Updated tests/util/index.spec.ts to the new contract (TDD: tests updated first and confirmed failing, then the fix), including a new case asserting the return is always a string.

All 19 existing call sites (bot/ordersActions.ts, bot/messages.ts) already treat the result as display text; none compares against false, so no behavior changes for valid inputs.

Re: the suggestion to enable @typescript-eslint/explicit-function-return-type — measured it: 381 warnings repo-wide today, so it's a separate effort; this PR adds the explicit return type to the function at hand. Follow-up discussion in #855.

Test plan

  • Updated tests fail against old implementation (RED) and pass against new one (GREEN)
  • Full suite: 151 passing, 0 failing
  • npm run lint clean
  • npx tsc full build clean

@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@grunch, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 30 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: ee14cef4-dc43-4924-bef9-4f91cf971b4a

📥 Commits

Reviewing files that changed from the base of the PR and between 0e87ea9 and 187582a.

📒 Files selected for processing (2)
  • tests/util/index.spec.ts
  • util/index.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/numberformat-always-string

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@grunch
grunch merged commit b80cb35 into main Jul 2, 2026
7 checks passed
@grunch
grunch deleted the fix/numberformat-always-string branch July 2, 2026 19:19
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.

numberFormat() returns false | number | string — latent 'Selling false sats' footgun

1 participant