Skip to content

feat(perps): prepare migration to perpscontroller to core#24549

Merged
abretonc7s merged 6 commits intomainfrom
feat/perps/migrations-controller
Jan 16, 2026
Merged

feat(perps): prepare migration to perpscontroller to core#24549
abretonc7s merged 6 commits intomainfrom
feat/perps/migrations-controller

Conversation

@abretonc7s
Copy link
Copy Markdown
Contributor

@abretonc7s abretonc7s commented Jan 15, 2026

Description

This PR removes all i18n dependencies (strings() calls) from core-bound Perps files to prepare for migration to @metamask/perps-controller in the core monorepo.

Why?

Core monorepo packages must be i18n-agnostic. Previously, several Perps files used strings() for translated error messages and time formatting, which created a dependency on the mobile i18n system.

What changed?

  • Error handling: Validation errors now return standardized error codes (PERPS_ERROR_CODES.ORDER_SIZE_MIN) instead of translated strings
  • Time formatting: Provider returns raw estimatedMinutes: number instead of formatted strings; UI hooks handle formatting
  • Translation layer: The translatePerpsError.ts and perpsErrorHandler.ts files handle translating error codes to user-facing messages
  • No behavior change: End users see the same error messages and time displays; they're just translated/formatted at a different layer

Files modified:

  • perpsErrorCodes.ts - Added 6 new validation error codes
  • HyperLiquidProvider.ts - Removed all 17 strings() calls (15 error messages + 2 time formatting)
  • translatePerpsError.ts - Added mappings for new error codes
  • perpsErrorHandler.ts - Added mappings for new error codes
  • HyperLiquidProvider.test.ts - Updated test expectations to use error codes and raw time values
  • usePerpsWithdrawQuote.ts - Added time formatting logic (moved from provider)
  • usePerpsOrderValidation.ts - Added translatePerpsError for protocol validation errors
  • controllers/types/index.ts - Added estimatedMinutes?: number to AssetRoute.constraints

New error codes added:

  • ORDER_SIZE_POSITIVE - Order size must be positive
  • ORDER_PRICE_REQUIRED - Price is required for validation
  • ORDER_SIZE_MIN - Order value below minimum
  • ORDER_LEVERAGE_INVALID - Leverage outside valid range
  • ORDER_LEVERAGE_BELOW_POSITION - Leverage below existing position requirement
  • ORDER_MAX_VALUE_EXCEEDED - Order value exceeds maximum

Changelog

CHANGELOG entry: null

Related issues

Part of: PerpsController migration to core monorepo (Stages 1 & 2 complete)

Manual testing steps

Feature: Perps validation error messages

  Scenario: User sees validation error when placing invalid order
    Given user has Perps enabled and is on the order screen

    When user enters an order size of 0
    Then user sees "Order size must be positive" error message

    When user enters a limit order without a price
    Then user sees "Limit price is required" error message

    When user enters an order below minimum value ($10)
    Then user sees "Minimum order value" error message

Feature: Withdrawal time estimate display

  Scenario: User sees estimated withdrawal time
    Given user is on the Perps withdrawal screen

    When user enters a valid withdrawal amount
    Then user sees "5 minutes" as estimated processing time

Screenshots/Recordings

N/A - No visual changes. Error messages and time displays appear identically to before.

Before

  • Error messages returned via strings() calls in HyperLiquidProvider
  • Time formatting done in provider with strings('time.minutes_format_plural', ...)

After

  • Error messages returned as error codes from HyperLiquidProvider, translated at UI layer
  • Time returned as raw estimatedMinutes: number, formatted in usePerpsWithdrawQuote hook

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

Decouples i18n from core-bound Perps logic and prepares for controller extraction.

  • Standardizes validation and provider errors to PERPS_ERROR_CODES (adds many new codes) and replaces strings() usage; translatePerpsError handles UI translation
  • Introduces shared util/errorUtils.ensureError and updates imports across views/hooks/services
  • Provider returns raw route constraints with estimatedMinutes (adds to AssetRoute.constraints); UI (usePerpsWithdrawQuote) formats time
  • Updates HyperLiquidProvider, validation utils, and order calculations to emit error codes; adjusts tests to expect codes/minutes
  • Adds docs outlining connection architecture and migration plan

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

@abretonc7s abretonc7s requested a review from a team as a code owner January 15, 2026 12:36
@github-actions
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-perps Perps team label Jan 15, 2026
@github-actions
Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokePerps
  • Risk Level: medium
  • AI Confidence: 90%
click to see 🤖 AI reasoning details

This PR is a focused refactoring of the Perps (Perpetuals trading) feature with the following changes:

  1. Error handling refactoring: Extracted ensureError utility to a shared location (app/util/errorUtils.ts) and consolidated error handling in translatePerpsError.ts. The old perpsErrorHandler.ts was deleted.

  2. Error codes expansion: Added new validation error codes (withdraw, deposit, order) to perpsErrorCodes.ts and updated the translation mappings. Error messages are now returned as codes from the provider layer and translated at the UI layer.

  3. API change: Changed estimatedTime (formatted string) to estimatedMinutes (raw number) in withdrawal route constraints, with UI-side formatting.

  4. Import path updates: ~25+ files updated to use new import paths for ensureError, handlePerpsError, and PERPS_ERROR_CODES.

  5. Documentation: Added architecture and migration documentation.

  6. Tests: Added/updated unit tests for error utilities.

All changes are exclusively within the Perps feature (app/components/UI/Perps/) and the new shared error utility. While the PerpsController is marked as critical, the actual changes to it are minimal (just an import path change). The refactoring doesn't change the fundamental behavior but reorganizes error handling code.

The SmokePerps tag is the only relevant tag since:

  • All code changes are within the Perps feature
  • No other wallet features are affected
  • The new app/util/errorUtils.ts is only used by Perps code currently
  • This is a code quality/refactoring change, not a feature change

Risk is medium because:

  • The changes touch error handling across many Perps files
  • Error messages and validation flows could be affected
  • The API change for estimatedMinutes affects withdrawal UI
  • However, the changes are well-tested with unit tests

View GitHub Actions results

@abretonc7s abretonc7s added the skip-sonar-cloud Only used for bypassing sonar cloud when failures are not relevant to the changes. label Jan 15, 2026
@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
73.4% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@abretonc7s abretonc7s added this pull request to the merge queue Jan 16, 2026
Merged via the queue into main with commit 44a8bc0 Jan 16, 2026
90 of 92 checks passed
@abretonc7s abretonc7s deleted the feat/perps/migrations-controller branch January 16, 2026 03:28
@github-actions github-actions bot locked and limited conversation to collaborators Jan 16, 2026
@metamaskbot metamaskbot added the release-7.63.0 Issue or pull request that will be included in release 7.63.0 label Jan 16, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.63.0 Issue or pull request that will be included in release 7.63.0 size-XL skip-sonar-cloud Only used for bypassing sonar cloud when failures are not relevant to the changes. team-perps Perps team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants