feat(perps): track pay-token validation errors in analytics#29170
Conversation
Fire PERPS_ERROR events when blocking pay-token alerts or insufficient balance warnings are displayed on the order screen, enabling Mixpanel visibility into deposit failure causes in the trade-with-any-token flow.
Verify that PERPS_ERROR analytics events fire when blocking pay-token alerts appear on the order screen, and do not fire when alerts are absent or when Perps balance (not a custom token) is selected.
|
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. |
…ility BaseController.update() now expects Draft<State> from immer, which is incompatible with the plain state type used in test helpers. Cast via `any` to avoid excessively deep type instantiation with complex state.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #29170 +/- ##
==========================================
+ Coverage 82.26% 82.28% +0.02%
==========================================
Files 5127 5132 +5
Lines 135863 135937 +74
Branches 30586 30607 +21
==========================================
+ Hits 111766 111862 +96
+ Misses 16467 16454 -13
+ Partials 7630 7621 -9 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 1818fbf. Configure here.
AI PR Analysis🚫 Merge safe: false | 🟠 Risk: high
AI analysis did not complete. Manual review recommended. |
Add tests for the hasInsufficientPayTokenBalance warning useEffect and alertMessage fallback branches to meet the 80% new-code coverage gate.
abretonc7s
left a comment
There was a problem hiding this comment.
can we separate concerns and have those business effect in hooks?
Move the two inline useEffect + track() blocks into usePerpsPayTokenErrorTracking, which uses the declarative usePerpsEventTracking API consistent with the rest of the codebase.
Remove the usePerpsPayTokenErrorTracking wrapper hook and call usePerpsEventTracking directly in PerpsOrderView, consistent with existing Perps UI patterns.
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsE2E Test Selection: Key observations:
Tag selection rationale:
Performance Test Selection: |
|
✅ E2E Fixture Validation — Schema is up to date |
|




Description
In the "trade with any token" flow, the custom confirm button performs its own validation but was not tracking when standardized blocking alerts (e.g.
useInsufficientPayTokenBalanceAlert,useNoPayTokenQuotesAlert) fire. This meant validation errors like "insufficient funds" and "insufficient source token balance for relay deposit" — which account for the majority of deposit failures — were invisible in Mixpanel.This PR adds two
useEffecthooks inPerpsOrderViewContentBasethat firePERPS_ERRORanalytics events when:error_type: 'validation'with the alert's human-readable message.error_type: 'warning'with standardizedinsufficient_balancekey.Both events include
error_type,error_message/warning_message,screen_name, andscreen_typeproperties, following the existingPERPS_ERRORschema.Note: the UI integration (button disabling + alert message rendering) was already in place. This PR adds only the missing analytics tracking and corresponding unit tests.
Changelog
CHANGELOG entry: null
Related issues
Fixes: https://consensyssoftware.atlassian.net/browse/TAT-2720
Manual testing steps
Screenshots/Recordings
N/A — no UI changes; analytics-only.
Pre-merge author checklist
Performance checks (if applicable)
trace()for usage andaddTokenfor an exampleFor performance guidelines and tooling, see the Performance Guide.
Pre-merge reviewer checklist
Note
Low Risk
Low risk: adds analytics-only
PERPS_ERRORtracking inPerpsOrderViewplus unit tests; behavior changes are limited to when events fire and could affect metrics volume if conditions are mis-triggered.Overview
Adds declarative
usePerpsEventTrackinginstrumentation inPerpsOrderViewto emitMetaMetricsEvents.PERPS_ERRORwhen blocking pay-token alerts appear (tracked as validation with a robust message/title/key fallback) and when the insufficient pay-token balance check is true (tracked as warning with the standardizedinsufficient_balancekey).Extends
PerpsOrderView.test.tsxwith coverage ensuring events fire only for custom-token flows (not Perps balance), don’t fire when no blocking alerts exist, and validate the fallback message selection logic; introduces a mock foruseTransactionPayTokento support the warning-path tests.Reviewed by Cursor Bugbot for commit b96cf19. Bugbot is set up for automated code reviews on this repo. Configure here.