feat(perps): normalize Mobile Perps leverage analytics to previous_leverage - #34813
Conversation
Co-authored-by: Cursor <cursoragent@cursor.com>
|
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. |
🧪 Flaky unit test detectionRun history flaky detectionHistorical failure rate is a hint, not proof — review each suggestion in context. See the flaky-test-detection skill for the full pattern reference and manual audit workflow. Failures / runs sampled per window:
AI-detected flaky patterns
|
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsE2E Test Selection: Performance Test Selection: |
|



Description
Lite and Pro Perps leverage-change events now emit Segment
previous_leverageinstead of the unknown camelCasepreviousLeverage. Both forms sharePERPS_ANALYTICS_PREVIOUS_LEVERAGEbecause@metamask/perps-controllerdoes not export that key yet.Acceptance criteria:
previous_leverageand no longer emitpreviousLeverage— PASSChangelog
CHANGELOG entry: null
Related issues
Fixes: https://consensyssoftware.atlassian.net/browse/TAT-3743
Manual testing steps
Covered by recipe source assertions and unit tests; no visual UI change.
Screenshots/Recordings
Hidden analytics property rename. Proof is recipe state assertions plus unit tests; no user-visible UI change.
Validation Recipe
recipe.json (5 steps — prove previous_leverage on Lite and Pro emitters)
{ "$schema": "https://farmslot.io/schemas/recipe-v1.schema.json", "title": "TAT-3743 normalize Perps leverage analytics to previous_leverage", "description": "Prove Lite and Pro leverage-change emitters use the Segment previous_leverage property via the shared mobile constant, and no longer emit camelCase previousLeverage.", "workflow": { "entry": "assert-constant-file", "nodes": { "assert-constant-file": { "action": "assert_file", "path": "app/components/UI/Perps/constants/perpsAnalytics.ts", "contains": "previous_leverage", "intent": "Confirm the shared analytics constant file declares the Segment previous_leverage key", "proves": ["ac3-shared-constant"], "next": "scan-emitters" }, "scan-emitters": { "action": "command", "cmd": "node -e \"var fs=require('fs'); var files=['app/components/UI/Perps/Views/PerpsOrderView/PerpsOrderView.tsx','app/components/UI/Perps/Views/PerpsProMarketView/components/PerpsProOrderForm/usePerpsProOrderForm.ts']; var errors=[]; files.forEach(function(f){ var s=fs.readFileSync(f,'utf8'); if (s.indexOf('previousLeverage') !== -1) errors.push(f+': still emits previousLeverage'); if (s.indexOf('PERPS_ANALYTICS_PREVIOUS_LEVERAGE') === -1) errors.push(f+': missing PERPS_ANALYTICS_PREVIOUS_LEVERAGE'); }); if (errors.length){ console.error(errors.join('\\n')); process.exit(1);} console.log('lite-and-pro-emitters-use-previous_leverage');\"", "intent": "Scan Lite and Pro leverage-change emitters for the shared previous_leverage constant and absence of camelCase", "next": "assert-scan-exit" }, "assert-scan-exit": { "action": "assert_exit_code", "source": "scan-emitters", "expected": 0, "intent": "Confirm the emitter scan completed successfully", "next": "assert-scan-output" }, "assert-scan-output": { "action": "assert_output", "source": "scan-emitters", "stream": "stdout", "contains": "lite-and-pro-emitters-use-previous_leverage", "intent": "Confirm both leverage forms passed the previous_leverage contract", "proves": ["ac1-lite-pro-previous-leverage", "ac3-shared-constant"], "next": "done" }, "done": { "action": "end", "status": "pass" } } }, "proofTargets": [ { "id": "ac1-lite-pro-previous-leverage", "claim": "Lite PerpsOrderView and Pro usePerpsProOrderForm leverage-change payloads emit previous_leverage and do not emit previousLeverage." }, { "id": "ac3-shared-constant", "claim": "Both emitters use the shared PERPS_ANALYTICS_PREVIOUS_LEVERAGE constant whose value is previous_leverage." } ] }Validation Logs
Command:
MM_HARNESS_BIN=/Users/deeeed/dev/metamask/metamask-harness/bin/mm-harness unset RECIPE_LIBRARY_PATHFull output (5/5 passed)
Pre-merge author checklist
Performance checks (if applicable)
trace()for usage andaddTokenfor an exampleN/A for performance checks: analytics property rename only; no UI or hot-path change. Labels to apply at publish:
team-perps,type-feature.Pre-merge reviewer checklist
Note
Low Risk
Analytics payload rename only; no trading, auth, or UI behavior changes.
Overview
Lite and Pro Perps leverage-change
PERPS_UI_INTERACTIONevents now send the Segment fieldprevious_leverageinstead of the camelCasepreviousLeverage.A shared mobile constant
PERPS_ANALYTICS_PREVIOUS_LEVERAGE('previous_leverage') is used inPerpsOrderViewandusePerpsProOrderFormuntil@metamask/perps-controllerexports the key. Unit tests on both flows assert the property name and thatpreviousLeverageis not present.Reviewed by Cursor Bugbot for commit 2d08480. Bugbot is set up for automated code reviews on this repo. Configure here.