Repository navigation
fix(wallet): trim zeros exposed by the 4-significant-digit cut - #976
Merged
fathah merged 5 commits intoOct 11, 2026
Merged
Conversation
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.
Contributor
|
…eFull tests One case per truncation branch, beside the existing formatter tests.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
formatTokenBalanceFullinsrc/shared/tokens.tsdocuments "up to 4 significant digits with trailing zeros removed", but it trims the fraction before capping it to 4 digits.1.20001displays as1.2000,1.00001as1.0000.formatTokenBalanceinherits the fix below the K threshold, where it delegates toformatTokenBalanceFull.significantDigitsstarts at the first nonzero digit.Tests
Two cases in the existing
formatTokenBalanceFullblock ofsrc/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.