Skip to content

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

Description

@grunch

Context

Found while reviewing #852.

Problem

numberFormat in util/index.ts has an inconsistent return type:

const numberFormat = (code: string, number: number) => {
  if (!isIso4217(code)) return false;      // boolean
  if (!currencies[code]) return number;    // number
  ...
  if (!locale || isNaN(number)) return number; // number
  return numberToLocaleString.format(number);  // string
};

Its results are interpolated directly into user-facing strings (order descriptions, order titles via #852, trading volume). Today nothing breaks because every current caller validates the currency first (e.g. createOrder checks getCurrency(fiatCode) before buildDescription), but that invariant is implicit. The first future caller that skips the check publishes a title like "Selling false sats" to the order channel.

Suggested fix

Make numberFormat always return a string:

  • String(number) as the fallback instead of returning the raw number;
  • for the invalid-ISO-4217 case, either String(number) as well, or make the function throw / narrow the signature so TypeScript forces callers to handle it.

Low-risk change; all existing call sites already treat the result as display text.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions