Skip to content

Commit

Permalink
Do not pass options.digits or options.preset when undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
bpierre committed Jan 29, 2025
1 parent 02ff540 commit 95ea440
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions frontend/app/src/comps/Amount/Amount.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { FmtnumPresetName } from "@/src/formatting";
import type { FmtnumOptions, FmtnumPresetName } from "@/src/formatting";

import { fmtnum } from "@/src/formatting";
import { css } from "@/styled-system/css";
Expand Down Expand Up @@ -29,12 +29,14 @@ export function Amount({

const showFallback = value === null || value === undefined;

const content = showFallback ? fallback : fmtnum(value, {
digits: typeof format === "number" ? format : undefined,
prefix,
preset: typeof format === "number" ? undefined : format,
scale,
}) + suffix;
const fmtOptions: FmtnumOptions = { prefix, scale, suffix };
if (typeof format === "number") {
fmtOptions.digits = format;
} else if (typeof format === "string") {
fmtOptions.preset = format;
}

const content = showFallback ? fallback : fmtnum(value, fmtOptions);

const title = showFallback ? undefined : (
titleProp === undefined
Expand Down

0 comments on commit 95ea440

Please sign in to comment.