Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add simulation metrics to "Transaction Submitted" and "Transact…
…ion Finalized" events (#28240) ## **Description** This PR adds simulation metrics to the `Transaction Submitted` and `Transaction Finalized` events. Please refer to **Solution B)** below for details. ---- The challenge here is that there are two separate transaction fragment buckets: `transaction-added-<id>` and `transaction-submitted-<id>`. `transaction-added-<id>` fragments are associated with the events: - Transaction Added - Transaction Approved - Transaction Rejected `transaction-submitted-<id>` fragments are associated with the events: - Transaction Submitted - Transaction Finalized Simulation metrics were added to "Transaction Approved" and "Transaction Rejected" events using updateEventFragment. When they were added here through the useTransactionEventFragment hook, the `transaction-submitted-<id>` fragment had not yet been created. The `transaction-submitted-<id>` fragment is created after a user clicks the Confirm button on a transaction which invokes metrics#handleTransactionSubmitted and calls createTransactionEventFragment To solve this, I proposed two solutions (TLDR; went with Solution B): #### Solution A) - Create a single transaction fragment ID to handle all related transaction events. Here, the fragment would specify the props: ``` initialEvent: "Transaction Added" successEvent:"Transaction Finalized" failureEvent: "Transaction Rejected" ``` - Add new method to MetaMetricsController to call trackEvent with specified eventName utilizing fragment props. This would support calling "Transaction Approved" and "Transaction Submitted" ad-hoc style. #### Solution B) - Allow a premature fragment to exist for `transaction-submitted-<id>` fragment. Prior to this PR fragments only exist once they are created. - From useTransactionEventFragment hook - Adds a premature `transaction-submitted-<id>` fragment - Calls "updateEventFragment(`transaction-submitted-${transactionId}`, params)" to store simulation metric props - When handleTransactionSubmitted event is invoked, creating the fragment now merges the premature fragment with the newly created fragment - When a premature fragment is found as an abandoned fragment, we delete it from the store #### Solution C) - store unlinked props in new store state: fragmentsUnlinkedProps on updateEventFragment - fragmentsUnlinkedProps can be applied to newly created fragments on createEventFragment - deleted abandoned fragmentsUnlinkedProps would need more investigation I went with solution B due to time constraints. ## **Related issues** Fixes: MetaMask/MetaMask-planning#3507 ## **Manual testing steps** 1. Turn on "Participate in MetaMetrics" setting 2. Confirm or Reject a Send transaction 3. Observe simulation props are added to `Transaction Submitted` and `Transaction Finalized` events ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> no UI/UX changes ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [ ] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **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.
- Loading branch information