From 30ef26101a2c5feb46035a7d861f3bf64d482800 Mon Sep 17 00:00:00 2001 From: VSaric <92527393+VSaric@users.noreply.github.com> Date: Fri, 25 Mar 2022 15:26:09 +0100 Subject: [PATCH] Remove the useSegmentContext function from metametrics.new.js (#14013) --- ui/contexts/metametrics.new.js | 43 +------------------ ui/hooks/useEventFragment.js | 4 +- ui/hooks/useEventFragment.test.js | 4 +- ...useMetricEvent.js => useSegmentContext.js} | 2 +- 4 files changed, 7 insertions(+), 46 deletions(-) rename ui/hooks/{useMetricEvent.js => useSegmentContext.js} (96%) diff --git a/ui/contexts/metametrics.new.js b/ui/contexts/metametrics.new.js index 6b179b010..fc63dafda 100644 --- a/ui/contexts/metametrics.new.js +++ b/ui/contexts/metametrics.new.js @@ -10,15 +10,14 @@ import React, { useRef, useCallback, } from 'react'; -import { useSelector } from 'react-redux'; 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 { omit } from 'lodash'; import { getEnvironmentType } from '../../app/scripts/lib/util'; import { PATH_NAME_MAP } from '../helpers/constants/routes'; -import { txDataSelector } from '../selectors'; +import { useSegmentContext } from '../hooks/useSegmentContext'; import { trackMetaMetricsEvent, trackMetaMetricsPage } from '../store/actions'; @@ -54,44 +53,6 @@ export const MetaMetricsContext = createContext(() => { 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 }) { const location = useLocation(); const context = useSegmentContext(); diff --git a/ui/hooks/useEventFragment.js b/ui/hooks/useEventFragment.js index 2e8d9ec0d..2447756ca 100644 --- a/ui/hooks/useEventFragment.js +++ b/ui/hooks/useEventFragment.js @@ -7,7 +7,7 @@ import { createEventFragment, updateEventFragment, } from '../store/actions'; -import { useMetaMetricsContext } from './useMetricEvent'; +import { useSegmentContext } from './useSegmentContext'; /** * Retrieves a fragment from memory or initializes new fragment if one does not @@ -59,7 +59,7 @@ export function useEventFragment(existingId, fragmentOptions = {}) { } }, [fragment, fragmentOptions]); - const context = useMetaMetricsContext(); + const context = useSegmentContext(); /** * trackSuccess is used to close a fragment with the affirmative action. This diff --git a/ui/hooks/useEventFragment.test.js b/ui/hooks/useEventFragment.test.js index f40febd82..2bef8c690 100644 --- a/ui/hooks/useEventFragment.test.js +++ b/ui/hooks/useEventFragment.test.js @@ -13,8 +13,8 @@ jest.mock('../store/actions', () => ({ createEventFragment: jest.fn(), })); -jest.mock('./useMetricEvent', () => ({ - useMetaMetricsContext: jest.fn(() => ({ page: '/' })), +jest.mock('./useSegmentContext', () => ({ + useSegmentContext: jest.fn(() => ({ page: '/' })), })); jest.mock('react-redux', () => ({ diff --git a/ui/hooks/useMetricEvent.js b/ui/hooks/useSegmentContext.js similarity index 96% rename from ui/hooks/useMetricEvent.js rename to ui/hooks/useSegmentContext.js index 30057ed8c..4b6ad6def 100644 --- a/ui/hooks/useMetricEvent.js +++ b/ui/hooks/useSegmentContext.js @@ -16,7 +16,7 @@ const PATHS_TO_CHECK = Object.keys(PATH_NAME_MAP); * referrer?: MetaMetricsReferrerObject * }} */ -export function useMetaMetricsContext() { +export function useSegmentContext() { const match = useRouteMatch({ path: PATHS_TO_CHECK, exact: true,