fix: omit balances without reliable decimals#8267
Conversation
- RpcDataSource: skip human-readable balance when decimals stay falsy after RPC - TokenDetector: skip detectedBalances when token list has no decimals - BalanceFetcher: native stays 18; ERC-20 without tokenInfos uses 1; explicit tokenInfo without decimals skips - Add unit tests for RpcDataSource, BalanceFetcher, and TokenDetector
|
@metamaskbot publish-preview |
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
Made-with: Cursor
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
|
@metamaskbot publish-preview |
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
| /** Token decimals used for formatting */ | ||
| decimals: number; | ||
| /** Token decimals used for formatting; omitted when unknown (raw `balance` only; resolved downstream). */ | ||
| decimals?: number; |
There was a problem hiding this comment.
in theory the token api should always return decimals , in case it's not we fallback to rpc calls
| const rawAmount = new BigNumberJS(rawBalance); | ||
| const divisor = new BigNumberJS(10).pow(decimals); | ||
| return rawAmount.dividedBy(divisor).toString(); | ||
| return rawAmount.dividedBy(divisor).toFixed(); |
There was a problem hiding this comment.
we use default rounding on toFixed , but this can be changed
| }; | ||
| } | ||
| // Unknown ERC-20: omit from assetsInfo until decimals are known. | ||
| // #handleBalanceUpdate resolves decimals via RPC or omits the balance. |
There was a problem hiding this comment.
we just skip in case of non decimals

Explanation
References
Checklist
Note
Medium Risk
Changes core balance/token-detection behavior by no longer defaulting ERC-20 decimals to 18, which can remove balances/metadata from responses until decimals resolve and may impact downstream consumers expecting entries to exist.
Overview
Stops the EVM RPC assets pipeline from guessing ERC-20 decimals:
RpcDataSource,BalanceFetcher, andTokenDetectornow omit human-readable balances (and relatedassetsInfo/detectedBalancesentries) when decimals are unknown, rather than defaulting to18(native tokens remain18).BalanceFetchernow treats ERC-20 decimals as optional inTokenFetchInfo/AssetBalanceand passes raw balances through when decimals aren’t provided;RpcDataSourceadds#tokenFetchInfosForCustomErc20sand updates balance conversion logic to skip formatting without decimals and avoid emitting placeholder metadata. Test suites are updated/expanded to cover the new omission behavior and edge cases (missing/zero decimals).Written by Cursor Bugbot for commit 419030b. This will update automatically on new commits. Configure here.