Skip to content

fix(wallet): trim zeros exposed by the 4-significant-digit cut - #976

Merged
fathah merged 5 commits into
fathah:mainfrom
sprayberry-code:fix/token-balance-trailing-zeros
Oct 11, 2026
Merged

fathah merged 5 commits into
fathah:mainfrom
sprayberry-code:fix/token-balance-trailing-zeros

Conversation

@askalf

@askalf askalf commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • formatTokenBalanceFull in src/shared/tokens.ts documents "up to 4 significant digits with trailing zeros removed", but it trims the fraction before capping it to 4 digits.
  • When the 4-digit cut lands on a zero that was only interior in the untrimmed fraction, that zero becomes trailing and is still rendered: 1.20001 displays as 1.2000, 1.00001 as 1.0000.
  • The fix re-trims after the slice in both branches of the function (2 lines). formatTokenBalance inherits the fix below the K threshold, where it delegates to formatTokenBalanceFull.
  • The sub-1 branch cannot trim to empty: significantDigits starts at the first nonzero digit.

Tests

Two cases in the existing formatTokenBalanceFull block of src/main/wallet-balances.test.ts, one per branch: both fail on main and pass with the fix, and the rest of the file passes unchanged (npx vitest run src/main/wallet-balances.test.ts).

AI assistance: this bug was found and the fix and tests were drafted with AI tooling in my workflow; the tests and checks above were run as described. I'm responsible for the change and will handle review feedback.

formatTokenBalanceFull promises "up to 4 significant digits with
trailing zeros removed", but it trimmed the fraction before capping it
to 4 digits. When the cut lands on a zero that was only interior in the
untrimmed fraction, that zero becomes trailing and was still rendered:
1.20001 HD showed as "1.2000" and 1.00001 HD as "1.0000".

Both branches now re-trim after the slice. The sub-1 branch keeps its
leading zeros (they are emitted separately) and its first significant
digit is non-zero, so a digit always survives. formatTokenBalance
inherits the fix below the K threshold, where it delegates here.
Adds the ledger rows the first pass left untested: an interior zero kept
while the cut's exposed tail goes, the sub-1 branch with no leading zeros
at both 18 and 6 decimals, a fraction entirely past the 4-digit window,
and a control pinning that the compact K path never reaches the changed
lines.
@greptile-apps

greptile-apps Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium risk] Fixes token balance display formatting.

The PR appears safe to merge; no outstanding findings remain.

Summary

The PR trims trailing zeros exposed by the four-digit cut in both branches of formatTokenBalanceFull and adds regression coverage, including the integer-only result. The previously noted coverage gap is closed.

Reviews (5) · Last reviewed commit: "test(wallet): cover a cut that leaves on..."

askalf and others added 2 commits September 18, 2026 08:07
Comment thread src/main/wallet-balances.test.ts Resolved
fathah added a commit that referenced this pull request Oct 11, 2026
Trim trailing zeros exposed by the four-significant-digit wallet balance cut while preserving integer and small-balance formatting. Retain the original contributor commits from #976 and integrate the fix with current production dependencies and architecture documentation.

Validated after integration with current main: focused regression tests, TypeScript checks, repository lint, lat check and diff checks passed. GitHub checks passed for the exact reviewed head.

Thanks @askalf for the contribution and regression coverage.
@fathah
fathah merged commit 0ee3be3 into fathah:main Oct 11, 2026
1 of 2 checks passed
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.

2 participants