chore: create advanced charts core package - #9762
Draft
sahar-fehri wants to merge 8 commits into
Draft
Conversation
Contributor
Author
|
@metamaskbot publish-preview |
Contributor
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
Contributor
Author
|
@metamaskbot publish-preview |
Contributor
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
Contributor
Author
|
@metamaskbot publish-preview |
Contributor
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
Contributor
Author
|
@metamaskbot publish-preview |
Contributor
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
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.
Explanation
This PR introduces a new package,
@metamask/advanced-chart-core— the platform-agnostic TradingView Advanced Charts WebView engine, extracted out of MetaMask mobile so it can be shared by both mobile and the browser extension from a single implementation.Current state / why this needs to change. The Advanced Charts engine (the TypeScript that runs inside the chart WebView/iframe: bootstrap, RN bridge, datafeed, OHLCV ingestion, indicators, overlays such as trade markers / position lines / social leaderboard, theming, pagination, etc.) currently lives only in mobile at
app/components/UI/Charts/AdvancedChart/webview/src. As the extension adds its own Token Details Page (TDP) chart, keeping a second copy would mean maintaining the same non-trivial engine twice and inevitably drifting between platforms.What this PR does. It lifts that engine into a standalone, platform-agnostic core package with no React Native / mobile-specific dependencies, wired into the
coremonorepo's build, lint, test, and release tooling. The engine communicates with its host over a message contract (RN bridge today), so the same compiled artifact can be embedded by any client WebView. The near-term consumer is the extension TDP integration (separate repo); mobile has already validated consuming this package and rendering identically to its in-tree copy.Copy-paste / behavior-equivalence framing
The engine source in this package is a behavior-preserving, verbatim copy of mobile's
AdvancedChart/webview/src. The ~40 engine source*.tsfiles were copied over at identical relative paths, and the only edits applied were to satisfy thecoremonorepo's lint/build conventions — not runtime behavior. Concretely, the changes are limited to things like:new-cap, documentation rules),.jsimport extensions on relative specifiers (ESM/ts-bridgeoutput),===/!==strict-equality and single-sided null checks,??in place of||,prefer-template,curly,consistent-return,interface→type, destructuring, and similar cosmetic rewrites.This is documented in detail in
PORT_EQUIVALENCE_REPORT.md, which performed an AST-normalized comparison of every source file (parse with the TypeScript compiler API → re-emit with comments stripped/whitespace canonicalized → strip.jssuffixes → diff → exhaustively classify the residual). Its verdict: behavior-preserving, with 0 unclassified hunks and 0 changes that alter behavior. Every semantics-sensitive rewrite (e.g.||→??,== null→ strict form) was individually reviewed against the operand's actual type and shown to be equivalent over the values it can hold. Equivalence was further corroborated by (a) the ported test suite and (b) building both production IIFE bundles and confirming an identical module graph (the ~13 KB size delta is retained JSDoc + longer identifiers, not extra logic).The ~37 test files were ported alongside the source. As expected, the test files were themselves re-styled to satisfy core lint (e.g.
__reset*ForTests→_reset*ForTests, identifier renames), but they assert the same behaviors (same inputs → same outputs, same DOM / TradingView-widget interactions).What's included
src/): ~40*.tsfiles acrosscore/,widget/,features/,interaction/,messages/,overlays/, andpagination/, plus the thin IIFE entrysrc/index.ts.src/**/__tests__/): ~37 ported test files.ts-bridge:build/build:allscripts,package.jsonmain/types/exports(import→.mjs/.d.mts,require→.cjs/.d.cts), and"sideEffects": falsefor tree-shaking.tsconfig.json/tsconfig.build.json, added to the roottsconfig.json/tsconfig.build.jsonproject references so it participates in the monorepo build graph..github/CODEOWNERS,codeowners.ts, andteams.jsonentries.README.md,CHANGELOG.md,LICENSE((MIT OR Apache-2.0)withLICENSE.MIT/LICENSE.APACHE2), and a rootREADME.mdtable entry.no-restricted-globals: offoverride forpackages/advanced-chart-core/src/**/*.tsonly, because this engine legitimately references browser globals (window,document,requestAnimationFrame) inside the WebView. ATODOis left to introduce a platform transport seam so these globals are injected rather than referenced directly.jest.config.jsextends the shared base config and setstestEnvironment: 'jsdom'(upstream in mobile these were per-file@jest-environment jsdomdocblocks) and resets the node-orientedcustomExportConditionsso jsdom resolves browser export conditions.References
packages/advanced-chart-core/README.mdpackages/advanced-chart-core/PORT_EQUIVALENCE_REPORT.mdmetamask-mobile→app/components/UI/Charts/AdvancedChart/webview/srcTesting
Verified via the monorepo's standard package checks:
yarn workspace @metamask/advanced-chart-core run test) — 37 suites / 536 tests passing per the equivalence report, with high per-module line coverage.ts-bridge(dual CJS + ESM) and participates in the root build graph.constraints,knip, and README/changelog content checks.webview/srccopy; bundle-level checks show an identical module graph vs. the mobile origin.Follow-ups / out of scope
webview/src— prepared on a mobile branch, to land once downstreams cut over to the package.0.0.0, unpublished).Checklist