Open
Conversation
Replace manual useState + useEffect + fetch pattern with @tanstack/react-query useQuery. Benefits: - Built-in caching (staleTime: 60s, cacheTime: 5min) - Automatic deduplication of concurrent requests for same asset - No manual loading/setPrices/setMetadata state management - Metadata derived via useMemo instead of a second useEffect - Fetch logic extracted to pure async function Non-EVM hook (useHistoricalPricesNonEvm) is unchanged as it uses Redux dispatch, not direct fetch. Co-authored-by: Francis Nepomuceno <n3ps@users.noreply.github.com>
Contributor
Builds ready [bf53a17]
⚡ Performance Benchmarks
🌐 Dapp Page Load BenchmarksCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚀 Bundle size reduced!]
|
Contributor
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
60d608e to
e4a39bb
Compare
e4a39bb to
793b25d
Compare
793b25d to
b9dbbb8
Compare
n3ps
commented
Feb 28, 2026
| setLoading(true); | ||
| const timePeriod = fromIso8601DurationToPriceApiTimePeriod(timeRange); | ||
| fetch( | ||
| `https://price.api.cx.metamask.io/v1/chains/${chainId}/historical-prices/${address}?vsCurrency=${currency}&timePeriod=${timePeriod}`, |
n3ps
commented
Feb 28, 2026
| ); | ||
|
|
||
| // Fetch the prices, and set them locally as a result of the fetch | ||
| useEffect(() => { |
n3ps
commented
Feb 28, 2026
| @@ -118,83 +124,34 @@ const useHistoricalPricesEvm = ({ | |||
| getShouldShowFiat(state, hexChainId), | |||
| ); | |||
|
|
|||
| const [loading, setLoading] = useState<boolean>(false); | |||
Contributor
Author
There was a problem hiding this comment.
- And manual loading and data states
n3ps
commented
Feb 28, 2026
| }); | ||
| }, [isEvm, chainId, address, currency, timeRange, showFiat]); | ||
| // Fetch the prices, and set them locally as a result of the fetch | ||
| const { data: prices = [], isFetching } = useQuery({ |
b9dbbb8 to
2c2ed53
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
|
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.



Replace manual useState + useEffect + fetch pattern with useQuery
Description
Changelog
CHANGELOG entry: refactor: migrate useHistoricalPricesEvm to useQuery
Related issues
Fixes:
Manual testing steps
Screenshots/Recordings
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Medium Risk
Touches the asset price chart data-fetching path by switching from manual
fetch/state touseQuery+apiClient, which can subtly change loading/empty-state behavior and caching across assets/chains.Overview
EVM historical price fetching is refactored from a manual
useEffect+fetch+ local state pattern touseQueryusingapiClient.prices.getV1HistoricalPricesQueryOptions, including aselecttransform forpricesand deriving metadata inline.UI/tests are adjusted to reflect the new request path and states:
AssetChartEmptyStatenow exposesdata-testid="asset-chart-empty-state", asset page tests mockgetBearerTokenand broadennockinterception/cleanup, and snapshots/assertions update from a chart loading skeleton to the empty-state when the API returns no price data.Written by Cursor Bugbot for commit 403be16. This will update automatically on new commits. Configure here.