mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-25 03:20:23 +01:00
76a2a9bb8b
* @metamask/eslint-config@5.0.0 * Update eslintrc and prettierrc * yarn lint:fix
41 lines
1.4 KiB
JavaScript
41 lines
1.4 KiB
JavaScript
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,
|
|
]);
|
|
}
|