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.
Context
Found while reviewing #852.
Problem
numberFormatinutil/index.tshas an inconsistent return type: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.
createOrderchecksgetCurrency(fiatCode)beforebuildDescription), 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
numberFormatalways return astring:String(number)as the fallback instead of returning the rawnumber;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.