Skip to content

fix: derive mm_pay_* metrics from controller state for reliable Transaction Finalized tracking#28164

Merged
dan437 merged 4 commits intomainfrom
mm_pay_props
Apr 1, 2026
Merged

fix: derive mm_pay_* metrics from controller state for reliable Transaction Finalized tracking#28164
dan437 merged 4 commits intomainfrom
mm_pay_props

Conversation

@dan437
Copy link
Copy Markdown
Contributor

@dan437 dan437 commented Mar 31, 2026

Description

MM Pay analytics properties (mm_pay_*) on the Transaction Finalized event were intermittently missing for predict_deposit, perps_deposit and for predict_withdraw transactions.

The properties were set by a React hook (useTransactionPayMetrics) that dispatches to Redux via useEffect. When the confirmation screen unmounted before the effect fired, the data was lost.

This PR moves core mm_pay_* derivation into the getMetaMaskPayProperties metrics builder, reading directly from transactionMeta.metamaskPay and TransactionPayController.transactionData — controller state that persists regardless of UI lifecycle. The hook now only dispatches UI-specific properties (e.g., mm_pay_token_presented, mm_pay_quote_loaded).

Changelog

CHANGELOG entry: fix: derive mm_pay_* metrics from controller state for reliable Transaction Finalized tracking

Related issues

Fixes: https://consensyssoftware.atlassian.net/browse/CONF-1102

Manual testing steps

Feature: MM Pay predict withdraw analytics

  Scenario: Transaction Finalized event includes all mm_pay_* properties
    Given user has a Polymarket position to withdraw
    And user has tokens on a different chain (e.g., BNB on BSC)

    When user initiates a predict withdraw with MM Pay
    And user approves the transaction quickly
    Then the "Transaction Finalized" event for transaction_type "predict_withdraw" includes all mm_pay_* properties (mm_pay, mm_pay_use_case, mm_pay_token_selected, mm_pay_chain_selected, mm_pay_sending_value_usd, mm_pay_receiving_value_usd, mm_pay_metamask_fee_usd, mm_pay_strategy)

Screenshots/Recordings

Before

mm_pay_* properties intermittently missing on predict_withdraw Transaction Finalized events.

After

All core mm_pay_* properties reliably present, derived from controller state.

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

Medium Risk
Touches analytics metric composition for MetaMask Pay transactions and changes the source of truth for fee/value/strategy fields; mistakes could silently regress tracking correctness across pay flows.

Overview
Ensures Transaction Finalized analytics consistently include core mm_pay_* properties by deriving them in getMetaMaskPayProperties from transactionMeta.metamaskPay and TransactionPayController.transactionData, rather than relying on confirmation-screen lifecycle.

useTransactionPayMetrics is reduced to dispatching UI-only fields (e.g., mm_pay_token_presented, quote loaded/requested, token list size, highest-balance chain) and now explicitly avoids emitting builder-owned properties like token/chain selected, use case, fees, strategy, dust, and step counts.

Tests are updated accordingly: hook tests assert only UI-scoped metrics are dispatched, and metamask-pay builder tests now validate fee/value/strategy/use-case/step/dust derivation from controller state (including preference for paymentToken.symbol over token lookup).

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

@dan437 dan437 requested a review from a team as a code owner March 31, 2026 13:08
@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-confirmations Push issues to confirmations team label Mar 31, 2026
@github-actions github-actions bot added size-L risk-medium Moderate testing recommended · Possible bug introduction risk labels Mar 31, 2026
@github-actions github-actions bot added risk-medium Moderate testing recommended · Possible bug introduction risk and removed risk-medium Moderate testing recommended · Possible bug introduction risk labels Mar 31, 2026
@github-actions github-actions bot added risk-medium Moderate testing recommended · Possible bug introduction risk and removed risk-medium Moderate testing recommended · Possible bug introduction risk labels Mar 31, 2026
@github-actions github-actions bot added risk-medium Moderate testing recommended · Possible bug introduction risk and removed risk-medium Moderate testing recommended · Possible bug introduction risk labels Apr 1, 2026
Copy link
Copy Markdown

@cursor cursor bot left a comment

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.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

dan437 added 4 commits April 1, 2026 11:50
…action Finalized tracking

Signed-off-by: dan437 <80175477+dan437@users.noreply.github.com>
Signed-off-by: dan437 <80175477+dan437@users.noreply.github.com>
Signed-off-by: dan437 <80175477+dan437@users.noreply.github.com>
Signed-off-by: dan437 <80175477+dan437@users.noreply.github.com>
@github-actions github-actions bot added risk-medium Moderate testing recommended · Possible bug introduction risk and removed risk-medium Moderate testing recommended · Possible bug introduction risk labels Apr 1, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 1, 2026

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokePerps, SmokePredictions, SmokeConfirmations, SmokeWalletPlatform
  • Selected Performance tags: None (no tests recommended)
  • Risk Level: medium
  • AI Confidence: 88%
click to see 🤖 AI reasoning details

E2E Test Selection:
The changes are a refactoring of analytics/metrics property computation for MetaMask Pay transactions (perps and predictions flows).

Key changes:

  1. metamask-pay.ts: Renamed addFallbackProperties to addPayTypeProperties and changed the source of truth for mm_pay_* metrics from UI hook state (getUIMetrics) to TransactionPayController controller state. This affects perpsDeposit, perpsWithdraw, predictDeposit, predictWithdraw transaction types.
  2. useTransactionPayMetrics.ts: Removed duplicate property computation (mm_pay, mm_pay_token_selected, mm_pay_chain_selected, mm_pay_use_case, fees, strategy, step counts) from the UI hook since these are now handled by the controller-level builder. The hook now only provides UI-specific properties.

These are analytics-only changes with no functional transaction flow modifications. However, they affect the metrics emitted during Perps and Predictions transaction flows, which warrants running those smoke tests to verify the flows still work correctly end-to-end.

Tag selection rationale:

  • SmokePerps: Directly affected — perpsDeposit/perpsWithdraw transaction metrics refactored
  • SmokePredictions: Directly affected — predictDeposit/predictWithdraw transaction metrics refactored
  • SmokeConfirmations: Required dependency per tag descriptions (SmokePerps and SmokePredictions both require SmokeConfirmations since Add Funds/deposits are on-chain transactions)
  • SmokeWalletPlatform: Required dependency per SmokePerps tag description (Perps is a section inside Trending tab)

Performance Test Selection:
These changes are pure analytics/metrics refactoring — moving where mm_pay_* properties are computed (from UI hook to controller state). There are no UI rendering changes, no component modifications, no state management performance impacts, no data loading changes, and no app initialization changes. Performance tests are not warranted.

View GitHub Actions results

@dan437 dan437 enabled auto-merge April 1, 2026 09:58
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 1, 2026

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 1, 2026

E2E Fixture Validation — Schema is up to date
17 value mismatches detected (expected — fixture represents an existing user).
View details

@dan437 dan437 added this pull request to the merge queue Apr 1, 2026
Merged via the queue into main with commit 8f6aed0 Apr 1, 2026
179 of 181 checks passed
@dan437 dan437 deleted the mm_pay_props branch April 1, 2026 11:05
@github-actions github-actions bot locked and limited conversation to collaborators Apr 1, 2026
@weitingsun weitingsun added release-7.73.0 Issue or pull request that will be included in release 7.73.0 and removed release-101.2.0 labels Apr 1, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.73.0 Issue or pull request that will be included in release 7.73.0 risk-medium Moderate testing recommended · Possible bug introduction risk size-L team-confirmations Push issues to confirmations team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants