refactor: Extract shared buildTokenData utility (preparation for withdrawals to any token)#7774
Closed
refactor: Extract shared buildTokenData utility (preparation for withdrawals to any token)#7774
Conversation
78c347c to
b88bf87
Compare
dan437
commented
Jan 29, 2026
| * @param chainId - Id of the chain. | ||
| * @returns The token info or undefined if not found. | ||
| */ | ||
| function getTokenInfoFromTokenList( |
Contributor
Author
There was a problem hiding this comment.
Do we want this fallback?
Member
There was a problem hiding this comment.
The TokensController automatically gets populated by the TokensListController so it should already include the same data.
Move duplicate token data building logic from update-payment-token.ts into a shared buildTokenData function in utils/token.ts. Changes: - Add `buildTokenData()` function to utils/token.ts - Add `getTokenInfoFromTokenList()` fallback for tokens not in user's list - Refactor `update-payment-token.ts` to use `buildTokenData()` - Add TokenListController mock to messenger-mock.ts - Add comprehensive tests for new utilities This reduces code duplication and prepares for the update-selected-token action which will reuse the same token building logic.
b88bf87 to
4a1613f
Compare
matthewwalsh0
requested changes
Jan 29, 2026
|
|
||
| ### Changed | ||
|
|
||
| - Extract shared `buildTokenData` utility and add `TokenListController` fallback for token lookups ([#7774](https://github.com/MetaMask/core/pull/7774)) |
Member
There was a problem hiding this comment.
We only include public API or external changes in the changelog, so not internal function references.
| * @param chainId - Id of the chain. | ||
| * @returns The token info or undefined if not found. | ||
| */ | ||
| function getTokenInfoFromTokenList( |
Member
There was a problem hiding this comment.
The TokensController automatically gets populated by the TokensListController so it should already include the same data.
| * @param request.tokenAddress - The token address. | ||
| * @returns The payment token or undefined if the token data could not be retrieved. | ||
| */ | ||
| function getPaymentToken({ |
Member
There was a problem hiding this comment.
Not sure why we are moving this logic? Why is this needed for the withdrawal support?
Contributor
Author
|
Closing in favor of #7783 |
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.
Explanation
This PR is a pure refactoring + a small enhancement. No withdrawal-specific code.
What it does:
Extracts the token building logic from update-payment-token.ts into a shared buildTokenData() function
Adds getTokenInfoFromTokenList() fallback - looks up tokens from TokenListController if not in user's added tokens
Both are generic utilities that work for any token lookup. The withdrawal-specific code (updateSelectedToken, setIsPostQuote, post-quote logic in buildQuoteRequests) will be in another PR.
References
Checklist
Note
Medium Risk
Medium risk because it changes how token decimals/symbol are resolved (new
TokenListControllerfallback), which can affect balance/fiat calculations and any flows depending on token metadata.Overview
Refactors payment token construction by extracting the inlined logic in
update-payment-tokeninto a sharedbuildTokenDatautility inutils/token.Enhances token lookups by updating
getTokenInfoto fall back toTokenListControllerwhen a token isn’t in the user’s added tokens, and updates the test messenger mock + unit tests to cover the new behavior.Updates the package
CHANGELOG.mdto document the refactor and fallback.Written by Cursor Bugbot for commit 4a1613f. This will update automatically on new commits. Configure here.