-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
chore: remove allDetectedTokens Earn references #30237
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
Changes from 1 commit
45dba1f
62598a3
9b8e5a7
dedd488
b3d40be
8aaf686
3d4bf79
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,14 @@ | ||
| import { Token } from '@metamask/assets-controllers'; | ||
| import { toHex } from '@metamask/controller-utils'; | ||
| import { CHAIN_ID_TO_AAVE_POOL_CONTRACT } from '@metamask/stake-sdk'; | ||
| import { Hex } from '@metamask/utils'; | ||
| import { useEffect, useState } from 'react'; | ||
| import { useSelector } from 'react-redux'; | ||
| import Engine from '../../../../core/Engine'; | ||
| import { selectSelectedInternalAccountByScope } from '../../../../selectors/multichainAccounts/accounts'; | ||
| import { selectUseTokenDetection } from '../../../../selectors/preferencesController'; | ||
| import useCurrencyRatePolling from '../../../hooks/AssetPolling/useCurrencyRatePolling'; | ||
| import useTokenBalancesPolling from '../../../hooks/AssetPolling/useTokenBalancesPolling'; | ||
| import useTokenDetectionPolling from '../../../hooks/AssetPolling/useTokenDetectionPolling'; | ||
| import useTokenRatesPolling from '../../../hooks/AssetPolling/useTokenRatesPolling'; | ||
| import { RootState } from '../../BasicFunctionality/BasicFunctionalityModal/BasicFunctionalityModal.test'; | ||
| import { EVM_SCOPE } from '../constants/networks'; | ||
|
|
||
| /** | ||
|
|
@@ -55,9 +52,6 @@ export const useEarnNetworkPolling = () => { | |
| EVM_SCOPE, | ||
| ); | ||
| const useTokenDetection = useSelector(selectUseTokenDetection); | ||
| const tokensState = useSelector( | ||
| (state: RootState) => state.engine?.backgroundState?.TokensController, | ||
| ); | ||
| const [lendingChainIds, setLendingChainIds] = useState<Hex[]>([]); | ||
|
|
||
| useTokenBalancesPolling({ chainIds: lendingChainIds }); | ||
|
|
@@ -78,56 +72,6 @@ export const useEarnNetworkPolling = () => { | |
| setLendingChainIds(validChainIds); | ||
| }, [setLendingChainIds]); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is really not doing anything, other than causing the first render to call the other hooks with an empty array and then call them again on second render with an exact copy of LENDING_CHAIN_IDS. I think both the useEffect and the useState are not necessary here. |
||
|
|
||
| // Import tokens from all lending chains | ||
| useEffect(() => { | ||
| const importLendingTokens = async () => { | ||
| if (!selectedAccount?.address || !useTokenDetection) return; | ||
|
|
||
| const { TokensController } = Engine.context; | ||
| const allDetectedTokens = tokensState?.allDetectedTokens || {}; | ||
|
|
||
| for (const chainId of LENDING_CHAIN_IDS) { | ||
| const chainDetectedTokens = | ||
| allDetectedTokens[chainId]?.[selectedAccount.address]; | ||
| if ( | ||
| chainDetectedTokens && | ||
| Object.keys(chainDetectedTokens).length > 0 | ||
| ) { | ||
| const tokensToImport = Object.values(chainDetectedTokens).map( | ||
| (token: Token) => ({ | ||
| address: token.address, | ||
| symbol: token.symbol, | ||
| decimals: token.decimals, | ||
| image: token.image, | ||
| name: token.name, | ||
| isERC721: false, | ||
| }), | ||
| ); | ||
|
|
||
| const networkClientId = | ||
| Engine.context.NetworkController.findNetworkClientIdByChainId( | ||
| chainId, | ||
| ); | ||
|
|
||
| if (networkClientId && tokensToImport.length > 0) { | ||
| await TokensController.addTokens(tokensToImport, networkClientId); | ||
| } | ||
| } | ||
| } | ||
| }; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| Engine.context.TokenDetectionController.detectTokens({ | ||
| chainIds: LENDING_CHAIN_IDS, | ||
| selectedAddress: selectedAccount?.address as Hex, | ||
| }) | ||
| .then(importLendingTokens) | ||
| .catch(console.error); | ||
| }, [ | ||
| tokensState?.allDetectedTokens, | ||
| selectedAccount?.address, | ||
| useTokenDetection, | ||
| ]); | ||
|
|
||
| return null; | ||
| }; | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.