Stop emitting tokens with default decimals=18 when metadata is missing#10
Open
benwoody wants to merge 1 commit into
Open
Conversation
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.
Refs #9 — addresses the primary symptom (off-by-10¹² displayed balance for non-18-decimal tokens) on the swap-screen path.
Problem
AlchemyTokenBalanceRepository#getCombinedTokenswas constructing aTokenAssetwithdecimals = 18whenever a token had a balance row but no matchingTokenMetadataEntityin the local DB. For6-decimal tokens like USDC, a real balance of ~10 USDC displayed as ~10⁻¹¹ USDC.
The home view already filters tokens without metadata via
DefaultGroupedTokenRepository, so in practice this code path only fed the swap UI — which is exactly where the wildly wrong number wasvisible.
Fix
Drop the
assetsWithoutMetadatabranch entirely. Tokens without metadata are no longer emitted fromgetCombinedTokens()until theirTokenMetadataEntityrow is populated. Matches the home-viewbehavior and stops emitting wrong numbers.
Out of scope, intentional follow-ups
Same
decimals = 18antipattern exists in two more places not touched by this PR:SwapViewModel.kt:920–928and:947–957— theelsefallback and the catch block inconvertToSwapTokenboth fabricate aTokenAssetwithdecimals = 18and a zero address. Fixing properlyrequires either restructuring the function to return
SwapToken?and updating callers, or surfacing failure as a UI-level error. Worth a separate PR.DefaultGroupedTokenRepository.kt:79–83— silently skips tokens without metadata. Not strictly a bug, but amplifies the symptom. Belongs in the principled follow-up that wiresOnChainTokenMetadataFetcherinto the no-metadata path so non-18-decimal tokens display correctly rather than being hidden.Happy to tackle either as follow-up PRs if you want.
No test added
No existing test coverage for
AlchemyTokenBalanceRepository#getCombinedTokensand no MockWebServer-style pattern in the repo. Happy to add one (and any necessary test infrastructure) in a follow-upif desired.
To maintainers:
Can the branches get cleaned up if you accept PRs? I would assume
mainwould be the main branch to build from.