-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
160 additions
and
24 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
49 changes: 49 additions & 0 deletions
49
app/components/hooks/AssetPolling/useTokenAutoDetectionPolling.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { useSelector } from 'react-redux'; | ||
import { selectNetworkConfigurations } from '../../../selectors/networkController'; | ||
import { selectUseTokenDetection } from '../../../selectors/preferencesController'; | ||
import { selectAllDetectedTokensForSelectedAddress } from '../../../selectors/tokensController'; | ||
import usePolling from '../usePolling'; | ||
import Engine from '../../../core/Engine'; | ||
import { selectSelectedInternalAccountAddress } from '../../../selectors/accountsController'; | ||
import { Hex } from '@metamask/utils'; | ||
|
||
type TokenDetectionPollingInput = { | ||
chainIds: Hex[]; | ||
address: string; | ||
}; | ||
|
||
const useTokenDetectionPolling = () => { | ||
const networkConfigurations = useSelector(selectNetworkConfigurations); | ||
const selectedAddress = useSelector(selectSelectedInternalAccountAddress); | ||
|
||
const useTokenDetection = useSelector(selectUseTokenDetection); | ||
const chainIds = Object.keys(networkConfigurations); | ||
|
||
const detectedTokens = useSelector(selectAllDetectedTokensForSelectedAddress); | ||
|
||
const { TokenDetectionController } = Engine.context; | ||
|
||
const pollingInput: TokenDetectionPollingInput[] = [ | ||
{ | ||
chainIds: chainIds as Hex[], | ||
address: selectedAddress ?? '', | ||
}, | ||
]; | ||
|
||
usePolling({ | ||
startPolling: TokenDetectionController.startPolling.bind( | ||
TokenDetectionController, | ||
), | ||
stopPollingByPollingToken: | ||
TokenDetectionController.stopPollingByPollingToken.bind( | ||
TokenDetectionController, | ||
), | ||
input: useTokenDetection ? pollingInput : [{ chainIds: [], address: '' }], | ||
}); | ||
|
||
return { | ||
detectedTokens, | ||
}; | ||
}; | ||
|
||
export default useTokenDetectionPolling; |
This file contains 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
This file contains 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
This file contains 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
This file contains 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