You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit b4fbb14
Browse filesBrowse the repository at this point in the historyBrowse files
feat: host-backed OHLCV pagination for older bars (#47753)
## **Description**
Pagination PR (3/3, top of the stack) for the Token Details Page
advanced charts work. Stacked on **#47751** (chart UI), which is stacked
on **#47749** (foundation).
Adds host-backed ("RN-backed") pagination of older OHLCV bars so the
chart can load more history as the user scrolls back in time, without
granting the sandboxed chart iframe any network access:
- The initial bulk data (`SET_OHLCV_DATA`) now carries an
`rnBackedPagination: { enabled: true }` flag, telling the engine to
request older bars from the host rather than fetching them itself.
- When the user scrolls to the edge of loaded data, the iframe posts a
`FETCH_OLDER_BARS_REQUEST` (with `requestId`, `seriesGeneration`,
symbol/resolution/window). The host (`advanced-chart-iframe.tsx`)
fetches the next older page from the Price API by cursor and replies
with `FETCH_OLDER_BARS_RESPONSE`; the engine echo-guards on
`seriesGeneration`, dedupes, and prepends the bars.
- `useOHLCVChart` gains cursor-aware paging (`fetchOHLCVPage` + a stable
`fetchOlderBars`), surfaced through `useAdvancedChartData` and wired
down via `advanced-chart-section`.
- Paging terminates cleanly when the API reports no more data (one cheap
terminal round-trip, no wasted fetch).
All changes are confined to the 8 chart files already introduced in
#47751. Still gated behind the `AdvancedCharts` remote feature flag.
Base branch: `feat/advanced-charts-ui` (#47751).
## **Changelog**
CHANGELOG entry: Added loading of older historical data when scrolling
back on the token details page chart.
<!--
## **Related issues**
Fixes:
-->
## **Manual testing steps**
1. Enable the `AdvancedCharts` remote feature flag, then build and run
the extension.
2. Unlock the wallet and open a token details page for an asset with a
long price history.
3. With the candlestick chart shown, scroll/drag the chart back in time
toward the oldest loaded candle.
4. Verify older candles load and prepend as you keep scrolling back (the
chart extends further into the past).
5. Keep scrolling until history is exhausted and confirm it stops
gracefully (no errors, no infinite spinner, no duplicated candles).
6. Switch interval/token and repeat to confirm paging restarts correctly
for the new series.
## **Screenshots/Recordings**
### **Before**
### **After**
## **Pre-merge author checklist**
- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I've included tests if applicable
- [ ] I've documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I've applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
## **Pre-merge reviewer checklist**
- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Medium Risk**
> Touches OHLCV fetch/pagination and iframe messaging; mistakes could
show wrong history or mishandle series switches, but changes stay behind
Advanced Charts and include thorough tests.
>
> **Overview**
> Adds **host-backed pagination** so users can scroll the token-details
candlestick chart further into the past without letting the sandboxed
chart iframe perform network requests (blocked by CSP).
>
> **Data layer:** `useOHLCVChart` now pages via `fetchOHLCVPage` (cursor
+ `hasNext` from the Price API) and exposes a stable `fetchOlderBars`
that advances the cursor, short-circuits when history is exhausted, and
drops stale pages if the asset/interval/currency series changes
mid-flight. `useAdvancedChartData` passes this through to
`AdvancedChartSection` and `AdvancedChartIframe`.
>
> **Iframe bridge:** Full `SET_OHLCV_DATA` payloads include
`rnBackedPagination: { enabled: true }`. When the engine sends
`FETCH_OLDER_BARS_REQUEST`, the host invokes `fetchOlderBars` and
replies with `FETCH_OLDER_BARS_RESPONSE` (echoing `requestId` /
`seriesGeneration`, or `noData` on error/missing callback).
>
> Tests cover the new postMessage contract, cursor paging, and wiring
mocks across section/data hooks.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
f79ea21. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
---------
Co-authored-by: MetaMask Bot <metamaskbot@users.noreply.github.com>
0 commit comments