-
Notifications
You must be signed in to change notification settings - Fork 5k
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
feat: multi chain polling for token prices #28158
Merged
Merged
Changes from all commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
85fe12d
bump asset controllers to 39
bergeron 0f3cd64
update ConfirmTransaction
bergeron bdf921b
fix useGasFeeEstimates unit test
bergeron 9bc4ecf
fix usePolling tests
bergeron 9b1529b
bump controller utils
bergeron c8bcc0b
remove patch
bergeron d1a3782
Merge branch 'develop' into brian/asset-controller-39
bergeron 05fd6ef
Update LavaMoat policies
metamaskbot 9dfdfa8
lint
bergeron 04ea3d6
Merge branch 'brian/asset-controller-39' of github.com:MetaMask/metam…
bergeron cf66072
Merge branch 'develop' into brian/asset-controller-39
bergeron 785de28
initial multi chain polling for currency and token rates
bergeron f461767
fix testnets
bergeron f1da818
only refetch prices on chains whose tokens changed
bergeron 878f407
poll multiple native currencies
bergeron e8a9d6a
fix test
bergeron 245f8d3
yarn dedupe
bergeron 1afebee
Update LavaMoat policies
metamaskbot e99e2ef
Merge branch 'develop' into brian/currency-rate-multichain-polling2
bergeron ca590ec
fix e2e test mocks
bergeron d2191ac
Merge branch 'develop' of github.com:MetaMask/metamask-extension into…
bergeron 70c0db4
fix e2e test
bergeron 6b7df4d
.
bergeron 4e816c2
lint
bergeron aaef377
fix e2e test
bergeron 48bff46
Merge branch 'brian/currency-rate-multichain-polling2' of github.com:…
bergeron 0450b04
package.json
bergeron fdc04ad
Merge branch 'develop' of github.com:MetaMask/metamask-extension into…
bergeron 3ec3574
bump controller preview version
bergeron dcc8a64
Merge branch 'develop' into brian/multiexchangerate
bergeron 0e7a872
fix: fix lint
sahar-fehri ea95aca
fix: update js file to tsx
sahar-fehri 3bf7b78
Merge branch 'develop' into brian/multiexchangerate
sahar-fehri bb1f278
make polling input a chain id
bergeron 14dc84b
Merge branch 'develop' into brian/multiexchangerate
bergeron ef3ef10
bump to asset controller v42
bergeron ab6e7cc
.
bergeron 44861d9
Merge branch 'brian/multiexchangerate' of github.com:MetaMask/metamas…
bergeron 5833fb8
AssetPollingProvider
bergeron 095b870
comment
bergeron be976f6
comments
bergeron 237fd4d
lint
bergeron 795f27d
Merge branch 'develop' into brian/multiexchangerate
bergeron f9b5763
input type
bergeron d445e84
stopAllPolling
bergeron bbf0e4e
comment
bergeron 316da04
tsx
bergeron 9a777f6
.
bergeron File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React, { ReactNode } from 'react'; | ||
import useCurrencyRatePolling from '../hooks/useCurrencyRatePolling'; | ||
import useTokenRatesPolling from '../hooks/useTokenRatesPolling'; | ||
|
||
// 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(); | ||
|
||
return <>{children}</>; | ||
}; |
This file was deleted.
Oops, something went wrong.
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,57 @@ | ||
import { useEffect, useState } from 'react'; | ||
|
||
type UseMultiPollingOptions<PollingInput> = { | ||
startPolling: (input: PollingInput) => Promise<string>; | ||
stopPollingByPollingToken: (pollingToken: string) => void; | ||
input: PollingInput[]; | ||
}; | ||
|
||
// A hook that manages multiple polling loops of a polling controller. | ||
// Callers provide an array of inputs, and the hook manages starting | ||
// and stopping polling loops for each input. | ||
const useMultiPolling = <PollingInput>( | ||
usePollingOptions: UseMultiPollingOptions<PollingInput>, | ||
) => { | ||
const [polls, setPolls] = useState(new Map()); | ||
|
||
useEffect(() => { | ||
// start new polls | ||
for (const input of usePollingOptions.input) { | ||
const key = JSON.stringify(input); | ||
if (!polls.has(key)) { | ||
usePollingOptions | ||
.startPolling(input) | ||
.then((token) => | ||
setPolls((prevPolls) => new Map(prevPolls).set(key, token)), | ||
); | ||
} | ||
} | ||
|
||
// stop existing polls | ||
for (const [inputKey, token] of polls.entries()) { | ||
const exists = usePollingOptions.input.some( | ||
(i) => inputKey === JSON.stringify(i), | ||
); | ||
|
||
if (!exists) { | ||
usePollingOptions.stopPollingByPollingToken(token); | ||
setPolls((prevPolls) => { | ||
const newPolls = new Map(prevPolls); | ||
newPolls.delete(inputKey); | ||
return newPolls; | ||
}); | ||
} | ||
} | ||
}, [usePollingOptions.input && JSON.stringify(usePollingOptions.input)]); | ||
|
||
// stop all polling on dismount | ||
useEffect(() => { | ||
return () => { | ||
for (const token of polls.values()) { | ||
usePollingOptions.stopPollingByPollingToken(token); | ||
} | ||
}; | ||
}, []); | ||
}; | ||
|
||
export default useMultiPolling; |
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,40 @@ | ||
import { useSelector } from 'react-redux'; | ||
import { | ||
getMarketData, | ||
getNetworkConfigurationsByChainId, | ||
getTokenExchangeRates, | ||
getTokensMarketData, | ||
getUseCurrencyRateCheck, | ||
} from '../selectors'; | ||
import { | ||
tokenRatesStartPolling, | ||
tokenRatesStopPollingByPollingToken, | ||
} from '../store/actions'; | ||
import useMultiPolling from './useMultiPolling'; | ||
|
||
const useTokenRatesPolling = ({ chainIds }: { chainIds?: string[] } = {}) => { | ||
// Selectors to determine polling input | ||
const useCurrencyRateCheck = useSelector(getUseCurrencyRateCheck); | ||
const networkConfigurations = useSelector(getNetworkConfigurationsByChainId); | ||
|
||
// Selectors returning state updated by the polling | ||
const tokenExchangeRates = useSelector(getTokenExchangeRates); | ||
const tokensMarketData = useSelector(getTokensMarketData); | ||
const marketData = useSelector(getMarketData); | ||
|
||
useMultiPolling({ | ||
startPolling: tokenRatesStartPolling, | ||
stopPollingByPollingToken: tokenRatesStopPollingByPollingToken, | ||
input: useCurrencyRateCheck | ||
? chainIds ?? Object.keys(networkConfigurations) | ||
: [], | ||
}); | ||
|
||
return { | ||
tokenExchangeRates, | ||
tokensMarketData, | ||
marketData, | ||
}; | ||
}; | ||
|
||
export default useTokenRatesPolling; |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This hook would be used by other controllers that need multiple active polling loops like TokenListController