Skip to content

Commit

Permalink
fix: Prevent SrpViewSrpText from firing more than once (#30658)
Browse files Browse the repository at this point in the history
## **Description**

Ensures that the `SrpViewSrpText` event doesn't get reported more than
once despite rerouting triggered by other events.

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/30658?quickstart=1)

## **Related issues**

Fixes:

## **Manual testing steps**

1. Go to Settings -> Security -> Reveal Seed Phrase
2. Complete quiz and enter your password
3. Ensure that the event is only tracked once.

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **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/main/.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/main/.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
darkwing authored Mar 8, 2025
1 parent 435e553 commit cdd1a02
Showing 1 changed file with 32 additions and 29 deletions.
61 changes: 32 additions & 29 deletions ui/pages/keychains/reveal-seed.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import qrCode from 'qrcode-generator';
import React, { useContext, useEffect, useState } from 'react';
import React, { useContext, useEffect, useState, useCallback } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { useHistory } from 'react-router-dom';
import { getErrorMessage } from '../../../shared/modules/error';
Expand Down Expand Up @@ -56,6 +56,26 @@ export default function RevealSeedPage() {
const [error, setError] = useState(null);
const mostRecentOverviewPage = useSelector(getMostRecentOverviewPage);
const [isShowingHoldModal, setIsShowingHoldModal] = useState(false);
const [srpViewEventTracked, setSrpViewEventTracked] = useState(false);

const onClickCopy = useCallback(() => {
trackEvent({
category: MetaMetricsEventCategory.Keys,
event: MetaMetricsEventName.KeyExportCopied,
properties: {
key_type: MetaMetricsEventKeyType.Srp,
copy_method: 'clipboard',
},
});
trackEvent({
category: MetaMetricsEventCategory.Keys,
event: MetaMetricsEventName.SrpCopiedToClipboard,
properties: {
key_type: MetaMetricsEventKeyType.Srp,
copy_method: 'clipboard',
},
});
}, [trackEvent]);

useEffect(() => {
const passwordBox = document.getElementById('password-box');
Expand Down Expand Up @@ -146,13 +166,16 @@ export default function RevealSeedPage() {

const renderRevealSeedContent = () => {
// default for SRP_VIEW_SRP_TEXT event because this is the first thing shown after rendering
trackEvent({
category: MetaMetricsEventCategory.Keys,
event: MetaMetricsEventName.SrpViewSrpText,
properties: {
key_type: MetaMetricsEventKeyType.Srp,
},
});
if (!srpViewEventTracked) {
trackEvent({
category: MetaMetricsEventCategory.Keys,
event: MetaMetricsEventName.SrpViewSrpText,
properties: {
key_type: MetaMetricsEventKeyType.Srp,
},
});
setSrpViewEventTracked(true);
}

return (
<div>
Expand Down Expand Up @@ -185,27 +208,7 @@ export default function RevealSeedPage() {
tabKey="text-seed"
>
<Label marginTop={4}>{t('yourPrivateSeedPhrase')}</Label>
<ExportTextContainer
text={seedWords}
onClickCopy={() => {
trackEvent({
category: MetaMetricsEventCategory.Keys,
event: MetaMetricsEventName.KeyExportCopied,
properties: {
key_type: MetaMetricsEventKeyType.Srp,
copy_method: 'clipboard',
},
});
trackEvent({
category: MetaMetricsEventCategory.Keys,
event: MetaMetricsEventName.SrpCopiedToClipboard,
properties: {
key_type: MetaMetricsEventKeyType.Srp,
copy_method: 'clipboard',
},
});
}}
/>
<ExportTextContainer text={seedWords} onClickCopy={onClickCopy} />
</Tab>
<Tab
name={t('revealSeedWordsQR')}
Expand Down

0 comments on commit cdd1a02

Please sign in to comment.