-
-
Notifications
You must be signed in to change notification settings - Fork 267
refactor: Extract shared buildTokenData utility (preparation for withdrawals to any token) #7774
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
78c347c to
b88bf87
Compare
| * @param chainId - Id of the chain. | ||
| * @returns The token info or undefined if not found. | ||
| */ | ||
| function getTokenInfoFromTokenList( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want this fallback?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
|
|
||
| ### Changed | ||
|
|
||
| - Extract shared `buildTokenData` utility and add `TokenListController` fallback for token lookups ([#7774](https://github.com/MetaMask/core/pull/7774)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why we are moving this logic? Why is this needed for the withdrawal support?
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.