Skip to content

Conversation

@michalconsensys
Copy link
Contributor

@michalconsensys michalconsensys commented Dec 18, 2025

Description

This PR adds client-side validation for Take Profit (TP) and Stop Loss (SL) price inputs in the Perps trading feature. When users enter prices with more than 5 significant figures, a non-blocking warning is displayed informing them that the decimal precision may be reduced after submitting.

Why this change?

The HyperLiquid API enforces a maximum of 5 significant figures for price values. The formatHyperLiquidPrice function in the provider layer already rounds prices exceeding this limit, but users were unaware their input would be modified. This led to a confusing UX where the submitted price differed from what was entered.

What's included?

  1. Validation utilities: Added countSignificantFigures and hasExceededSignificantFigures functions that match HyperLiquid's rounding behavior
  2. Non-blocking warning: Display a warning message when price precision will be reduced (does not block form submission)
  3. Improved price display: Changed TP/SL price display on PositionCard from PRICE_RANGES_MINIMAL_VIEW to PRICE_RANGES_UNIVERSAL to show full decimal precision
  4. Comprehensive tests: Added 34 unit tests covering significant figures counting and validation

Changelog

CHANGELOG entry: Added a warning message when Take Profit or Stop Loss prices exceed 5 significant figures, informing users that decimal precision may be reduced after submitting.

Related issues

Fixes: https://consensyssoftware.atlassian.net/browse/TAT-2063

Manual testing steps

Feature: TP/SL Price Precision Warning

  Scenario: User enters TP price with excessive precision
    Given user has an open Perps position
    And user navigates to the TP/SL settings view

    When user enters a Take Profit price with more than 5 significant figures (e.g., "123.456")
    Then a warning message "Decimal precision may be reduced after submitting." is displayed in yellow/orange text
    And the "Set" button remains enabled

Screenshots/Recordings

Before

No visible change

After

Simulator Screenshot - iPhone 17 Pro - 2025-12-18 at 17 29 42

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

Adds non-blocking TP/SL price precision warnings (5 significant figures), updates TP/SL display formatting, and introduces validation utilities with tests.

  • Perps UI:
    • Show non-blocking precision warnings in PerpsTPSLView for TP/SL when price exceeds 5 significant figures (takeProfitPrecisionWarning, stopLossPrecisionWarning).
    • Improve TP/SL price display in PerpsPositionCard by switching to PRICE_RANGES_UNIVERSAL.
  • Validation/Logic:
    • Add countSignificantFigures and hasExceededSignificantFigures in utils/tpslValidation.ts; integrate into usePerpsTPSLForm.
    • Extend DECIMAL_PRECISION_CONFIG with MAX_SIGNIFICANT_FIGURES: 5.
  • Localization:
    • Add perps.tpsl.price_precision_warning string.
  • Tests:
    • Add comprehensive unit tests for significant-figure counting/limits and related validation behaviors in tpslValidation.test.ts.

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

@github-actions
Copy link
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.

@michalconsensys michalconsensys added the DO-NOT-MERGE Pull requests that should not be merged label Dec 18, 2025
@michalconsensys
Copy link
Contributor Author

Do not merge, this approach needs to be confirmed

@michalconsensys michalconsensys marked this pull request as ready for review December 18, 2025 16:52
@michalconsensys michalconsensys requested a review from a team as a code owner December 18, 2025 16:52
@github-actions
Copy link
Contributor

🔍 Smart E2E Test Selection

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

The changes are entirely contained within the Perps (Perpetuals trading) feature module:

  1. tpslValidation.ts: Added two new utility functions (countSignificantFigures and hasExceededSignificantFigures) for validating price precision against HyperLiquid's 5 significant figure limit.

  2. usePerpsTPSLForm.ts: Added precision warning logic that uses the new validation functions to show non-blocking warnings when users enter prices that exceed the significant figure limit.

  3. PerpsTPSLView.tsx: Added UI elements to display the precision warnings (non-blocking, warning-level messages).

  4. PerpsPositionCard.tsx: Changed price formatting from PRICE_RANGES_MINIMAL_VIEW to PRICE_RANGES_UNIVERSAL for TP/SL prices.

  5. perpsConfig.ts: Added a new constant MAX_SIGNIFICANT_FIGURES: 5 for the validation.

  6. tpslValidation.test.ts: Added comprehensive unit tests for the new validation functions.

  7. en.json: Added a single localization string for the precision warning message.

All changes are self-contained within app/components/UI/Perps/ and only affect the Perpetuals trading feature. The importers analysis confirms no other parts of the app depend on these changes. The changes are additive (new warnings) and don't modify existing critical logic - they add non-blocking validation warnings to improve UX. The risk is low because:

  • Changes are isolated to one feature
  • New functionality is additive (warnings don't block user actions)
  • Comprehensive unit tests are included
  • No changes to core wallet functionality, navigation, or other features

View GitHub Actions results

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

DO-NOT-MERGE Pull requests that should not be merged quality-sprint-dec-2025 size-M team-perps Perps team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants