Skip to content

feat: add @metamask/superstruct as a dependency#27096

Merged
matallui merged 10 commits into
mainfrom
feat/superstruct
Mar 6, 2026
Merged

feat: add @metamask/superstruct as a dependency#27096
matallui merged 10 commits into
mainfrom
feat/superstruct

Conversation

@matallui

@matallui matallui commented Mar 5, 2026

Copy link
Copy Markdown
Contributor

Description

  • Add @metamask/superstruct (^3.2.1) as a direct dependency. This package provides runtime type validation utilities used across the MetaMask ecosystem.
  • Remove @metamask/abi-utils from devDependencies — it was duplicated, already present in dependencies.
  • Use superstruct for parsing Predict feeCollection feature flag

Changelog

CHANGELOG entry: null

Related issues

Fixes:

Manual testing steps

Feature: superstruct dependency

  Scenario: app builds with new dependency
    Given the dependency is added to package.json

    When the app is built
    Then it should build successfully without errors

Screenshots/Recordings

N/A — dependency-only change.

Before

N/A

After

N/A

Pre-merge author checklist

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.

Note

Low Risk
Low risk dependency and validation change; main behavioral impact is that invalid predictFeeCollection remote flag payloads now reliably fall back to DEFAULT_FEE_COLLECTION_FLAG instead of being used unchecked.

Overview
Adds @metamask/superstruct as a direct dependency (and removes duplicate @metamask/abi-utils from devDependencies).

Introduces a small Predict schema layer (parse helper, HexSchema, and PredictFeeCollectionSchema with defaults) and updates PredictController.resolveFeatureFlags() to validate/normalize the feeCollection remote feature flag, falling back to DEFAULT_FEE_COLLECTION_FLAG on invalid input. Includes unit tests covering schema validation, defaulting, and parse fallback behavior.

Written by Cursor Bugbot for commit b94d17c. This will update automatically on new commits. Configure here.

@github-actions

github-actions Bot commented Mar 5, 2026

Copy link
Copy Markdown
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.

@metamaskbot metamaskbot added the team-predict Predict team label Mar 5, 2026
@matallui matallui marked this pull request as ready for review March 5, 2026 21:28
weitingsun
weitingsun previously approved these changes Mar 5, 2026
Replace hardcoded DEFAULT_FEE_COLLECTION_FLAG with a superstruct schema
that provides default values via `defaulted()`, enabling runtime
validation of the remote feature flag while preserving the same defaults.
@matallui matallui requested a review from a team as a code owner March 5, 2026 22:11
@github-actions github-actions Bot added size-S and removed size-XS labels Mar 5, 2026
Comment thread app/components/UI/Predict/controllers/PredictController.ts
Comment thread app/components/UI/Predict/schemas/flags.ts Outdated
@github-actions github-actions Bot added size-M and removed size-S labels Mar 5, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread app/components/UI/Predict/controllers/PredictController.ts
caieu
caieu previously approved these changes Mar 6, 2026

@caieu caieu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@github-actions

github-actions Bot commented Mar 6, 2026

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokePredictions, SmokeWalletPlatform
  • Selected Performance tags: @PerformancePredict
  • Risk Level: medium
  • AI Confidence: 85%
click to see 🤖 AI reasoning details

E2E Test Selection:
The changes are focused on the Predict feature, specifically adding schema-based validation for the PredictFeeCollection feature flag in PredictController.ts. The changes include:

  1. PredictController.ts: Modified to use a new parse() function with PredictFeeCollectionSchema for validating the feeCollection feature flag. This is a defensive improvement that adds runtime validation.

  2. New schemas module: Added schema definitions using @metamask/superstruct for validating hex strings and fee collection configuration with proper defaults.

  3. Type changes: The PredictFeeCollection type is now inferred from the schema rather than being a manually defined interface.

  4. package.json: Added @metamask/superstruct as a production dependency.

The PredictController is a Phase 6 controller (business logic/features), which means it has more isolated impact. The changes don't affect:

  • Controller initialization order
  • Messenger configuration
  • Redux state synchronization
  • Other controllers or features

SmokePredictions is required because it directly tests Polymarket prediction market integration including fee-related functionality. SmokeWalletPlatform is required because Predictions is a section inside the Trending tab, and changes to Predictions views/controllers affect Trending functionality.

SmokeConfirmations is NOT required here because the changes are to the controller's feature flag parsing logic, not to the transaction/confirmation flow itself. The fee collection configuration is used internally by the Predict feature.

Performance Test Selection:
The changes modify PredictController.ts which handles the Predict feature's core logic including fee collection configuration. While the changes are primarily about adding schema validation (which should have minimal performance impact), the @PerformancePredict tag should be run to ensure the new parse() function and schema validation don't introduce any performance regression in prediction market list loading, market details, deposit flows, or balance display. The addition of a new dependency (@metamask/superstruct) and runtime validation could theoretically impact performance.

View GitHub Actions results

@caieu caieu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sonarqubecloud

sonarqubecloud Bot commented Mar 6, 2026

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Mar 6, 2026

Copy link
Copy Markdown
Contributor

⚠️ E2E Fixture Validation — Structural changes detected

Category Count
New keys 68
Missing keys 11
Type mismatches 0
Value mismatches 6 (informational)

The committed fixture schema is out of date. To update, comment:

@metamaskbot update-mobile-fixture

View full details | Download diff report

@matallui matallui added this pull request to the merge queue Mar 6, 2026
Merged via the queue into main with commit e87f934 Mar 6, 2026
91 checks passed
@matallui matallui deleted the feat/superstruct branch March 6, 2026 16:26
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 6, 2026
@metamaskbot metamaskbot added the release-7.70.0 Issue or pull request that will be included in release 7.70.0 label Mar 6, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.70.0 Issue or pull request that will be included in release 7.70.0 size-M team-predict Predict team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants