Skip to content

fix(common): correct formatTokenAmount for integer amounts + add util tests#34

Open
saltxd wants to merge 2 commits into
mainfrom
fix/format-token-amount
Open

fix(common): correct formatTokenAmount for integer amounts + add util tests#34
saltxd wants to merge 2 commits into
mainfrom
fix/format-token-amount

Conversation

@saltxd

@saltxd saltxd commented Jun 19, 2026

Copy link
Copy Markdown
Owner

Bug

formatTokenAmount ran .replace(/\.?0+$/, '') unconditionally. For 0-decimal tokens, toFixed(0) yields an integer string ("100") and the strip ate real trailing zeros: "100" -> "1", "1200" -> "12". The function is exported from @chainward/common but currently has zero call sites, so this fixes a latent display bug before first use.

Fix + tests

  • Only strip trailing zeros when a decimal point is present.
  • Adds 25 unit tests for the previously-untested pure utils: format.ts (incl. a regression test for this bug), address.ts, and spam.ts.

pnpm --filter @chainward/common test → 32 passing.

🤖 Generated with Claude Code

saltxd added 2 commits June 18, 2026 21:13
formatTokenAmount ran .replace(/\.?0+$/, '') unconditionally, so for 0-decimal
tokens toFixed(0) produced an integer string ('100') and the strip ate real
trailing zeros ('100' -> '1', '1200' -> '12'). Only strip when a decimal point
is present.

formatTokenAmount is exported from @chainward/common but currently has zero call
sites, so this fixes a latent display bug before first use.
Adds unit tests for previously-untested pure utilities in @chainward/common:
- format.ts: USD/compact/gwei formatting + formatTokenAmount, including a
  regression test for the 0-decimal trailing-zero bug fixed in the prior commit.
- address.ts: EVM checksum/validation, Solana base58 bounds, truncation.
- spam.ts: isSpamToken known/spam-list short-circuits, name patterns, non-ASCII
  lookalikes (also documents the TLD-suffix pattern's known over-match).

25 new tests, all green via `pnpm --filter @chainward/common test`.
@saltxd saltxd force-pushed the fix/format-token-amount branch from 70c8ea8 to b42183f Compare June 20, 2026 13:06
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.

1 participant