-
-
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
4 changed files
with
110 additions
and
93 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,17 @@ | ||
import React, { ReactNode } from 'react'; | ||
import useCurrencyRatePolling from './useCurrencyRatePolling'; | ||
import useTokenRatesPolling from './useTokenRatesPolling'; | ||
import useTokenList from '../DisplayName/useTokenList'; | ||
import useTokenBalancesPolling from './useTokenBalancesPolling'; | ||
import useTokenListPolling from './useTokenListPolling'; | ||
|
||
// This provider is a step towards making controller polling fully UI based. | ||
// Eventually, individual UI components will call the use*Polling hooks to | ||
// poll and return particular data. This polls globally in the meantime. | ||
export const AssetPollingProvider = ({ children }: { children: ReactNode }) => { | ||
useCurrencyRatePolling(); | ||
useTokenRatesPolling(); | ||
// useTokenList(); | ||
useTokenListPolling(); | ||
useTokenBalancesPolling(); | ||
|
||
return <>{children}</>; | ||
}; |
35 changes: 35 additions & 0 deletions
35
app/components/hooks/AssetPolling/useTokenBalancesPolling.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,35 @@ | ||
import { useSelector } from 'react-redux'; | ||
import { selectNetworkConfigurations } from '../../../selectors/networkController'; | ||
import Engine from '../../../core/Engine'; | ||
import usePolling from '../usePolling'; | ||
import { selectTokensBalances } from '../../../selectors/tokenBalancesController'; | ||
|
||
const useTokenBalancesPolling = () => { | ||
// Selectors to determine polling input | ||
const networkConfigurations = useSelector(selectNetworkConfigurations); | ||
|
||
const tokensBalances = useSelector(selectTokensBalances); | ||
|
||
const input = Object.values(networkConfigurations).map(({ chainId }) => ({ | ||
chainId, | ||
})); | ||
|
||
const { TokenBalancesController } = Engine.context; | ||
|
||
usePolling({ | ||
startPolling: TokenBalancesController.startPolling.bind( | ||
TokenBalancesController, | ||
), | ||
stopPollingByPollingToken: | ||
TokenBalancesController.stopPollingByPollingToken.bind( | ||
TokenBalancesController, | ||
), | ||
input, | ||
}); | ||
|
||
return { | ||
tokensBalances, | ||
}; | ||
}; | ||
|
||
export default useTokenBalancesPolling; |
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