## **Description**
Foundation PR (1/5) for the Token Details Page (TDP) advanced charts
work. This splits the original MetaMask#47737 into five reviewable, stacked PRs:
1. **MetaMask#47749 (this PR)** — background/state foundation
2. MetaMask#47751 — chart UI
3. MetaMask#47753 — host-backed OHLCV pagination
4. MetaMask#47771 — chart theming (line/candle colors driven by design tokens)
5. MetaMask#47772 — chart analytics/instrumentation (interaction + empty-state
events)
This PR contains **no user-facing UI on its own**; the advanced chart is
rendered in the UI PR (MetaMask#47751) and stays behind the `AdvancedCharts`
remote feature flag. Landing it first keeps the CODEOWNER-reviewed
surface (background controller wiring, fixtures, privacy/state-logs)
small and isolated.
What it includes:
- **Chart-type preference** on `PreferencesController` (plus
`shared/types/preferences.ts` and `shared/lib/selectors/preferences.ts`
selector) so the TDP can persist the user's candle/line choice.
- **OHLCV service wiring** into the background: the
`@metamask/core-backend` OHLCV service and its messenger are registered
via `app/scripts/messenger-client-init/*` and `metamask-controller.js`.
- **Fixtures & state snapshots** (`default-fixture.json`,
`onboarding-fixture.json`, metrics state snapshots, `state-logs.json`)
updated to reflect the new controller state.
Base branch: `main`.
## **Changelog**
CHANGELOG entry: null
<!--
## **Related issues**
Fixes:
-->
## **Manual testing steps**
Since this PR adds no visible UI, testing is a no-regression smoke
check:
1. Build and run the extension.
2. Complete onboarding / unlock an existing wallet.
3. Confirm the wallet loads normally (home, asset list, settings) with
no errors in the background or UI console.
4. Open a token details page and confirm the existing (legacy) price
chart still renders as before.
<!--
## **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 persisted preferences, background service initialization, and
LavaMoat policies; new OHLCV service may open backend connectivity when
later UI/flags enable it, but this PR alone adds no visible surface.
>
> **Overview**
> Adds **background/state foundation** for Token Details Page advanced
charts (no user-facing UI in this PR).
>
> **Chart preferences** — `PreferencesController` and `Preferences`
types now persist `tdpChartType`, `tdpChartInterval`, and
`tdpChartIndicators`, with shared defaults in
`shared/constants/preferences` and new selectors (`getTdpChartType`,
`getTdpChartInterval`, `getTdpChartIndicators`) so controller defaults
and UI fallbacks stay aligned. Controller tests, fixtures, metrics
snapshots, and state-logs schemas are updated for the new fields.
>
> **OHLCV streaming** — Registers `@metamask/core-backend`
`OHLCVService` in the background via `OHLCVServiceInit`, a restricted
`getOHLCVServiceMessenger` (core allow-lists), and `metamask-controller`
/ messenger factory wiring. LavaMoat webpack policies grant
`AbortController` and `async-mutex` to `core-backend` for this
dependency path.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
7f6d7d4. 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>
Description
The Token Details Page line chart is always drawn in green. This PR adds
optional directional colouring for that line chart only: the line is green when
the selected range is up and red when it is down, so the chart agrees with the
percent-change figure in the header.
It introduces no new colours — it reuses the existing design-system tokens:
the same green (
--color-success-default) the line already used, and the samered (
--color-error-default) the percent-change header already uses. Thedirection is computed at the range level (range open vs. latest price), not from
the hovered point, so the colour stays stable as the pointer moves.
The behaviour is gated behind a new remote feature flag
(
tokenDetailsAdvancedChartsTheming/ LaunchDarklytoken-details-advanced-charts-theming).When the flag is off, the line is always green exactly as before. Candlestick
mode is unchanged — it already renders green/red candles.
Manual testing steps
tokenDetailsAdvancedChartsThemingflag (via.manifest-overrides.jsonremote flag overrides).Changelog
CHANGELOG entry: null
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Low Risk
UI-only chart styling gated by a remote feature flag; default behavior unchanged when the flag is off.
Overview
Adds optional directional line coloring on the Token Details advanced line chart: when remote flag
tokenDetailsAdvancedChartsThemingis on, the line uses--color-success-defaultfor an up range and--color-error-defaultfor a down range, based on range open vs live/current price (not hover). With the flag off, behavior stays always green.Wires the flag through
TOKEN_DETAILS_ADVANCED_CHARTS_THEMING_FLAG,getIsAdvancedChartsThemingEnabled, and the known flag registry.AdvancedChartSectionpasseslineColorVarintoAssetChartBody, which resolves that CSS variable for Chart.jsborderColor. Candle mode is unchanged.Tests cover flag on/off, up/down/unknown range, hover stability, and chart border color resolution.
Reviewed by Cursor Bugbot for commit 1064da1. Bugbot is set up for automated code reviews on this repo. Configure here.