A Metamask fork with Infura removed and default networks editable
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
ciphermask/ui/app/hooks/useMetricEvent.js

40 lines
1.4 KiB

import { useContext, useCallback } from 'react';
import { MetaMetricsContext } from '../contexts/metametrics';
import { MetaMetricsContext as NewMetaMetricsContext } from '../contexts/metametrics.new';
import { useEqualityCheck } from './useEqualityCheck';
// Type imports
/**
* @typedef {import('../contexts/metametrics.new').UIMetricsEventPayload} UIMetricsEventPayload
* @typedef {import('../../../shared/constants/metametrics').MetaMetricsEventOptions} MetaMetricsEventOptions
*/
export function useMetricEvent(config = {}, overrides = {}) {
const metricsEvent = useContext(MetaMetricsContext);
const trackEvent = useCallback(() => metricsEvent(config, overrides), [
config,
metricsEvent,
overrides,
]);
return trackEvent;
}
/**
* track a metametrics event using segment
* e.g metricsEvent({ event: 'Unlocked MetaMask', category: 'Navigation' })
*
* @param {UIMetricsEventPayload} payload - payload of the event to track
* @param {MetaMetricsEventOptions} options - options for handling/routing event
* @return {() => Promise<void>} function to execute the tracking event
*/
export function useNewMetricEvent(payload, options) {
const memoizedPayload = useEqualityCheck(payload);
const memoizedOptions = useEqualityCheck(options);
const metricsEvent = useContext(NewMetaMetricsContext);
return useCallback(() => metricsEvent(memoizedPayload, memoizedOptions), [
metricsEvent,
memoizedPayload,
memoizedOptions,
]);
}