mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Remove the useSegmentContext function from metametrics.new.js (#14013)
This commit is contained in:
parent
05fc865cbf
commit
30ef26101a
@ -10,15 +10,14 @@ import React, {
|
|||||||
useRef,
|
useRef,
|
||||||
useCallback,
|
useCallback,
|
||||||
} from 'react';
|
} from 'react';
|
||||||
import { useSelector } from 'react-redux';
|
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { matchPath, useLocation, useRouteMatch } from 'react-router-dom';
|
import { matchPath, useLocation } from 'react-router-dom';
|
||||||
import { captureException, captureMessage } from '@sentry/browser';
|
import { captureException, captureMessage } from '@sentry/browser';
|
||||||
|
|
||||||
import { omit } from 'lodash';
|
import { omit } from 'lodash';
|
||||||
import { getEnvironmentType } from '../../app/scripts/lib/util';
|
import { getEnvironmentType } from '../../app/scripts/lib/util';
|
||||||
import { PATH_NAME_MAP } from '../helpers/constants/routes';
|
import { PATH_NAME_MAP } from '../helpers/constants/routes';
|
||||||
import { txDataSelector } from '../selectors';
|
import { useSegmentContext } from '../hooks/useSegmentContext';
|
||||||
|
|
||||||
import { trackMetaMetricsEvent, trackMetaMetricsPage } from '../store/actions';
|
import { trackMetaMetricsEvent, trackMetaMetricsPage } from '../store/actions';
|
||||||
|
|
||||||
@ -54,44 +53,6 @@ export const MetaMetricsContext = createContext(() => {
|
|||||||
|
|
||||||
const PATHS_TO_CHECK = Object.keys(PATH_NAME_MAP);
|
const PATHS_TO_CHECK = Object.keys(PATH_NAME_MAP);
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the current page if it matches out route map, as well as the origin
|
|
||||||
* if there is a confirmation that was triggered by a dapp
|
|
||||||
*
|
|
||||||
* @returns {{
|
|
||||||
* page?: MetaMetricsPageObject
|
|
||||||
* referrer?: MetaMetricsReferrerObject
|
|
||||||
* }}
|
|
||||||
*/
|
|
||||||
function useSegmentContext() {
|
|
||||||
const match = useRouteMatch({
|
|
||||||
path: PATHS_TO_CHECK,
|
|
||||||
exact: true,
|
|
||||||
strict: true,
|
|
||||||
});
|
|
||||||
const txData = useSelector(txDataSelector) || {};
|
|
||||||
const confirmTransactionOrigin = txData.origin;
|
|
||||||
|
|
||||||
const referrer = confirmTransactionOrigin
|
|
||||||
? {
|
|
||||||
url: confirmTransactionOrigin,
|
|
||||||
}
|
|
||||||
: undefined;
|
|
||||||
|
|
||||||
const page = match
|
|
||||||
? {
|
|
||||||
path: match.path,
|
|
||||||
title: PATH_NAME_MAP[match.path],
|
|
||||||
url: match.path,
|
|
||||||
}
|
|
||||||
: undefined;
|
|
||||||
|
|
||||||
return {
|
|
||||||
page,
|
|
||||||
referrer,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function MetaMetricsProvider({ children }) {
|
export function MetaMetricsProvider({ children }) {
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const context = useSegmentContext();
|
const context = useSegmentContext();
|
||||||
|
@ -7,7 +7,7 @@ import {
|
|||||||
createEventFragment,
|
createEventFragment,
|
||||||
updateEventFragment,
|
updateEventFragment,
|
||||||
} from '../store/actions';
|
} from '../store/actions';
|
||||||
import { useMetaMetricsContext } from './useMetricEvent';
|
import { useSegmentContext } from './useSegmentContext';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves a fragment from memory or initializes new fragment if one does not
|
* Retrieves a fragment from memory or initializes new fragment if one does not
|
||||||
@ -59,7 +59,7 @@ export function useEventFragment(existingId, fragmentOptions = {}) {
|
|||||||
}
|
}
|
||||||
}, [fragment, fragmentOptions]);
|
}, [fragment, fragmentOptions]);
|
||||||
|
|
||||||
const context = useMetaMetricsContext();
|
const context = useSegmentContext();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* trackSuccess is used to close a fragment with the affirmative action. This
|
* trackSuccess is used to close a fragment with the affirmative action. This
|
||||||
|
@ -13,8 +13,8 @@ jest.mock('../store/actions', () => ({
|
|||||||
createEventFragment: jest.fn(),
|
createEventFragment: jest.fn(),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
jest.mock('./useMetricEvent', () => ({
|
jest.mock('./useSegmentContext', () => ({
|
||||||
useMetaMetricsContext: jest.fn(() => ({ page: '/' })),
|
useSegmentContext: jest.fn(() => ({ page: '/' })),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
jest.mock('react-redux', () => ({
|
jest.mock('react-redux', () => ({
|
||||||
|
@ -16,7 +16,7 @@ const PATHS_TO_CHECK = Object.keys(PATH_NAME_MAP);
|
|||||||
* referrer?: MetaMetricsReferrerObject
|
* referrer?: MetaMetricsReferrerObject
|
||||||
* }}
|
* }}
|
||||||
*/
|
*/
|
||||||
export function useMetaMetricsContext() {
|
export function useSegmentContext() {
|
||||||
const match = useRouteMatch({
|
const match = useRouteMatch({
|
||||||
path: PATHS_TO_CHECK,
|
path: PATHS_TO_CHECK,
|
||||||
exact: true,
|
exact: true,
|
Loading…
x
Reference in New Issue
Block a user