Repository navigation
feat: instrument advanced chart interactions and empty state - #47772
Conversation
|
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. |
Builds ready [34eb5b8]
⚡ Performance Benchmarks (Total: 🟢 8 pass · 🟡 3 warn · 🔴 2 fail)
Bundle Size Diffs [🚨 Warning! Bundle size has increased!]
|
Builds ready [f9b7f7c]
⚡ Performance Benchmarks (Total: 🟢 4 pass · 🟡 5 warn · 🔴 4 fail)
Bundle Size Diffs [🚨 Warning! Bundle size has increased!]
|
Please fix this high issue. @sahar-fehri |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort 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.
Reviewed by Cursor Bugbot for commit 5f90c98. Configure here.
Builds ready [5f90c98]
⚡ Performance Benchmarks (Total: 🟢 8 pass · 🟡 1 warn · 🔴 4 fail)
Bundle Size Diffs [🚨 Warning! Bundle size has increased!]
|
Builds ready [680f256]
⚡ Performance Benchmarks (Total: 🟢 10 pass · 🟡 0 warn · 🔴 3 fail)
Bundle Size Diffs [🚨 Warning! Bundle size has increased!]
|
|




Description
The advanced chart on the token details page had no analytics, so we had no
visibility into how people use it: which chart type they pick, which timeframes
and granularities they switch to, which indicators they turn on, or how often
the chart renders with no data. Mobile already emits these events, so the
extension was the gap in the pair.
This adds
Chart InteractedandChart Empty Displayed, matching mobile'sproperty contract so both platforms report into the same Segment schema.
A new
useChartAnalyticshook is the single place that builds both events. Itowns the two properties every
Chart Interactedcall shares (chart_typeandindicators_active) so call sites pass only what is specific to theirinteraction, and it encodes the one mobile quirk in one spot:
indicators_activeis omitted on
timeframe_changed(coherent here too, since the range pills onlyrender in line mode, where indicators are hidden).
A few details worth a reviewer's attention:
already posting
CHART_INTERACTEDmessages for these gestures and the iframewas discarding them. The message handler now forwards
interaction_typeup.They arrive pre-debounced by the engine, so there is no throttling on our side.
sanitises the URL via
toTradingViewUrland opens it). This PR adds atradingview_clickedevent alongside that existing open — the same couplingmobile uses — rather than moving the tab-open to the host.
Chart Empty Displayedfires on genuinely empty data, not on errors. Thecondition is a completed candle fetch that returned zero bars, guarded to fire
once per empty episode. Load timeouts and OHLCV failures are deliberately
excluded, and it is scoped to candle mode, where the OHLCV series is what is on
screen.
Coverage is all 9
interaction_typevalues in the schema:zoom,pan,tooltip,chart_type_changed,timeframe_changed,granularity_changed,indicator_toggled,indicator_selector_opened, andtradingview_clicked.One intentional divergence from mobile: its ticket specifies that indicator
toggles fire on a Done button tap. The extension's indicator bar has no Done
button — the pills apply immediately — so this emits one
indicator_toggledperclick, in both the on and off direction, reporting the post-toggle indicator set.
Note
This stacks on
feat/advanced-charts-themingand targets that branch, notmain.Important
The matching
Consensys/segment-schemachange isConsensys/segment-schema#807,
which marks both events dual-platform (adds
metamask-extension-globals) andextends the
chart_granularityenum with4hand1w. Until it merges, thoseschema entries remain mobile-only, so the missing extension globals and the
extra granularity values are expected here and are not a bug in this PR.
Security note
The iframe validates the URL from a
CHART_TRADINGVIEW_CLICKEDmessage beforeopening it (
toTradingViewUrl): https only, and a hostname that istradingview.comor a subdomain of it, otherwise it falls back to theTradingView homepage. The origin check on the incoming message only proves which
frame sent it, not where the URL points, so it is not sufficient on its own.
Lookalike hosts, non-https schemes, and unparseable URLs are covered by tests.
Changelog
CHANGELOG entry: null
Manual testing steps
Chart Interactedevent withinteraction_type: chart_type_changedand the newly selectedchart_type.timeframe_changedevent (noindicators_active).granularity_changedevent with the lowercased interval.indicator_toggledevent each time with the correctindicator_actionand post-toggleindicators_active.indicator_selector_openedevent (and none when closing it).zoom,pan, andtooltipevents.tradingview_clicked.Chart Empty Displayedevent, and confirm it does NOT fire on a chart that errored or is still loading.Pre-merge author checklist
Pre-merge reviewer checklist
Note
Low Risk
Changes are additive analytics and UI callback guards on the token chart; TradingView tab opening still uses existing host sanitization with new tests for malicious URLs.
Overview
Adds MetaMetrics coverage for the token-details advanced chart, aligning with mobile’s Segment schema via new
Chart InteractedandChart Empty Displayedevent names inmetametrics.A new
useChartAnalyticshook centralizes event payloads (chart_type,indicators_active, interaction-specific fields).useAdvancedChartInteractionswraps chart toolbar and preference updates so each user action both mutates state and fires the matching interaction event; it also emitsChart Empty Displayedonce per candle-mode episode when OHLCV finishes with zero bars (not on load errors or line mode).The chart iframe now propagates engine
CHART_INTERACTEDmessages (zoom/pan/tooltip) and invokes an analytics callback when the TradingView attribution link is opened (existing URL sanitization andopenTabbehavior unchanged). Interval pills and related handlers skip redundant callbacks when the same interval is clicked again, avoiding duplicate analytics and re-renders. The moving-average dropdown reportsindicator_selector_openedonly on open. Tests cover forwarding, URL sanitization, and the full interaction matrix.Reviewed by Cursor Bugbot for commit 680f256. Bugbot is set up for automated code reviews on this repo. Configure here.