-
-
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
7 changed files
with
66 additions
and
14 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
11 changes: 11 additions & 0 deletions
11
app/components/hooks/AssetPolling/AssetPollingProvider.tsx
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,11 @@ | ||
import React, { ReactNode } from 'react'; | ||
import useCurrencyRatePolling from './useCurrencyRatePolling'; | ||
|
||
// 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(); | ||
|
||
return <>{children}</>; | ||
}; |
39 changes: 39 additions & 0 deletions
39
app/components/hooks/AssetPolling/useCurrencyRatePolling.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,39 @@ | ||
import { useSelector } from 'react-redux'; | ||
import usePolling from '../usePolling'; | ||
import { selectNetworkConfigurations } from '../../../selectors/networkController'; | ||
import Engine from '../../../core/Engine'; | ||
import { selectConversionRate, selectCurrencyRates } from '../../../selectors/currencyRateController'; | ||
|
||
// Polls native currency prices across networks. | ||
const useCurrencyRatePolling = () => { | ||
|
||
// Selectors to determine polling input | ||
const networkConfigurations = useSelector(selectNetworkConfigurations); | ||
|
||
// Selectors returning state updated by the polling | ||
const conversionRate = useSelector(selectConversionRate); | ||
const currencyRates = useSelector(selectCurrencyRates); | ||
|
||
const nativeCurrencies = [ | ||
...new Set( | ||
Object.values(networkConfigurations).map((n) => n.nativeCurrency), | ||
), | ||
]; | ||
|
||
const { CurrencyRateController } = Engine.context; | ||
|
||
usePolling({ | ||
startPolling: | ||
CurrencyRateController.startPolling.bind(CurrencyRateController), | ||
stopPollingByPollingToken: | ||
CurrencyRateController.stopPollingByPollingToken.bind(CurrencyRateController), | ||
input: [{nativeCurrencies}], | ||
}); | ||
|
||
return { | ||
conversionRate, | ||
currencyRates, | ||
}; | ||
}; | ||
|
||
export default useCurrencyRatePolling; |
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