-
-
Notifications
You must be signed in to change notification settings - Fork 178
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
[Token Detection V2] 6 of 7 - Introduce Detected Tokens #808
Conversation
…oken-detection/introduce-detected-tokens
…oken-detection/introduce-detected-tokens
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.
A few things, but this all looks pretty reasonable to me.
…TokenMetadata return type with null.
Looks like the unit test job is failing because coverage is now slightly lower. Interesting. Since this is mostly new, tested code, I would not expect this. Must have missed something with the tests. |
Ugh. I just tried running locally and it exceeded the coverage threshold. It looks like errors encountered on CI (related to network failures) are causing it to take different paths which is lowering the coverage, even though the actual tests still pass. |
…oken-detection/introduce-detected-tokens
Thanks @Cal-L, coverage looks a lot better now. There was one comment that I think should be addressed, but I only had minor (non-blocking) suggestions apart from that. |
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.
LGTM, great work!
Continued convo about occurrence criteria - https://consensys.slack.com/archives/G1L7H42BT/p1654560442953019?thread_ts=1650897225.469639&cid=G1L7H42BT |
* Introduce detected tokens and update other relevant controllers. * Update preferences controller with useTokenDetection * Set token detection to be true by default * Fix linting issues * Fix ComposableController test * Update ComposableController test * Use named export with AbortController * Remove typecasting as any on error * Reintroduce override keyword. Remove typecast any on error. * Clean up token list messenger in token detection controller. * Refine token detection tests * Remove unnecessary abort controller from TokenDetectionController * Change importTokens back to addTokens. Rename hex to decimal util function. * Remove redundant comment * Do not mutate token states directly on TokensController. Update fetchTokenMetadata return type with null. * Remove check for hexadecimal chainId on TokensController * Rename isTokenDetectionEnabledForNetwork to isTokenDetectionSupportedForNetwork * Throw error for fetchTokenMetadata when fetching from non supported network * Update imports on TokenListController * Make fetchTokenMetadata on TokensController private. Only return null on unsupported network. Throw any other errors. Fix TokensController tests. * Update TokenDetectionController import + clean up tests. * Add TokensController test for switching networks while adding token * Clean up token service tests * Fix linting * Return undefined instead of throwing for token metadata when no response. Clean up TokensController tests. * Fix TokensController test * Make token detection restart method private * Remove unused networkType from TokenDetectionController * Populate tokens with image property, which uses proxied url * Remove removeAndIgnore method from TokensController. Update TokensController related tests. * Update fetchTokenMetadata @returns doc * Update TokenListMessenger type * Test onTokensStateChange after introducing detected tokens for TokenRatesController * Test onTokensStateChange for detected tokens on TokenBalancesController * Clean up addToken doc * Update TokenDetectionController to respect disable property from config * Fix TokensController tes * Deprecate onTokensStateChange from TokenDetectionController * Fix formatting proxy token images. Re-introduce ability to provide image to addToken in TokensController * Fix tests * Update formatIconUrlWithProxy tokenAddress input to state mixed or lowercase * Increase test coverage for AssetsContractController * Increase branch coverage for AssetsContractController * Increase test coverage for TokensController and TokenDetectionController * Improve token detection test to check for getBalancesInSingle call * Update comments on TokenDetectionController * Update TokenDetectionController tests to check for getBalancesInSingleCall
* Introduce detected tokens and update other relevant controllers. * Update preferences controller with useTokenDetection * Set token detection to be true by default * Fix linting issues * Fix ComposableController test * Update ComposableController test * Use named export with AbortController * Remove typecasting as any on error * Reintroduce override keyword. Remove typecast any on error. * Clean up token list messenger in token detection controller. * Refine token detection tests * Remove unnecessary abort controller from TokenDetectionController * Change importTokens back to addTokens. Rename hex to decimal util function. * Remove redundant comment * Do not mutate token states directly on TokensController. Update fetchTokenMetadata return type with null. * Remove check for hexadecimal chainId on TokensController * Rename isTokenDetectionEnabledForNetwork to isTokenDetectionSupportedForNetwork * Throw error for fetchTokenMetadata when fetching from non supported network * Update imports on TokenListController * Make fetchTokenMetadata on TokensController private. Only return null on unsupported network. Throw any other errors. Fix TokensController tests. * Update TokenDetectionController import + clean up tests. * Add TokensController test for switching networks while adding token * Clean up token service tests * Fix linting * Return undefined instead of throwing for token metadata when no response. Clean up TokensController tests. * Fix TokensController test * Make token detection restart method private * Remove unused networkType from TokenDetectionController * Populate tokens with image property, which uses proxied url * Remove removeAndIgnore method from TokensController. Update TokensController related tests. * Update fetchTokenMetadata @returns doc * Update TokenListMessenger type * Test onTokensStateChange after introducing detected tokens for TokenRatesController * Test onTokensStateChange for detected tokens on TokenBalancesController * Clean up addToken doc * Update TokenDetectionController to respect disable property from config * Fix TokensController tes * Deprecate onTokensStateChange from TokenDetectionController * Fix formatting proxy token images. Re-introduce ability to provide image to addToken in TokensController * Fix tests * Update formatIconUrlWithProxy tokenAddress input to state mixed or lowercase * Increase test coverage for AssetsContractController * Increase branch coverage for AssetsContractController * Increase test coverage for TokensController and TokenDetectionController * Improve token detection test to check for getBalancesInSingle call * Update comments on TokenDetectionController * Update TokenDetectionController tests to check for getBalancesInSingleCall
Description
This PR is intended to introduce the concept of
detectedTokens
and are separate from the existingtokens
, which we display in the wallet today.What Changed
TokenBalancesController (non-breaking)
detectedTokens
duringonTokensStateChange
to support showing balances for detected tokens.TokenDetectionController (breaking)
addTokens
from constructor toaddDetectedTokens
since we're no longer automatically adding detected tokens directly to wallet. Since the action is to add detected tokens, the updated terminology makes more sense.onTokenListStateChange
to constructor, which will be triggered when token list updates fromTokenListController
. This was needed because there was a scenario where detection was triggering against an empty token list after switching networks (Since fetching token list may not be finished before detection happens). By introducing this listener, we're making it so that detection can be triggered by the token list update action.getNetworkState
in constructor to gets initial state of the network controller.getPreferencesState
in constructor to get initial state of the preferences controller.onTokensStateChange
in constructor. Do not need this anymore since tokens are managed internally by TokensController.TokenRatesController (non-breaking)
detectedTokens
duringonTokensStateChange
to support showing fiat balances for detected tokens.TokensController (non-breaking)
detectedTokens
addDetectedTokens
method, which is used byTokenDetectionController
when tokens are detected.addTokens
methods to account for detected tokens.fetchTokenMetadata
method to fetch aggregator info when adding a single token.removeAndIgnoreToken
method. In the case of ignoring a single token, useignoreTokens
and pass in an array with a single token address as the input.PreferencesController (breaking)
useStaticTokenList
touseTokenDetection
and set totrue
by default. This means that token detection will be auto detected on TD supported networks by default.utils (breaking)
convertPriceToDecimal
toconvertHexToDecimal
for better naming.6 of 7 PRs for #763