mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-23 10:30:04 +01:00
14d85b1332
A few inconsistencies in JSDoc formatting have been fixed throughout the project. Many issues remain; these were just the few things that were easy to fix with a regular expression. The changes include: * Using lower-case for primitive types, but capitalizing non-primitive types * Separating the parameter identifier and the description with a dash * Omitting a dash between the return type and the return description * Ensuring the parameter type is first and the identifier is second (in a few places it was backwards) * Using square brackets to denote when a parameter is optional, rather than putting "(optional)" in the parameter description * Including a type and identifier with every parameter * Fixing inconsistent spacing, except where it's used for alignment * Remove incorrectly formatted `@deprecated` tags that reference non- existent properties * Remove lone comment block without accompanying function Additionally, one parameter was renamed for clarity.
38 lines
1.6 KiB
JavaScript
38 lines
1.6 KiB
JavaScript
import { useContext, useCallback } from 'react'
|
|
import { MetaMetricsContext } from '../contexts/metametrics'
|
|
import { MetaMetricsContext as NewMetaMetricsContext } from '../contexts/metametrics.new'
|
|
import { useEqualityCheck } from './useEqualityCheck'
|
|
|
|
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 {Object} config - configuration object for the event to track
|
|
* @param {string} config.event - event name to track
|
|
* @param {string} config.category - category to associate event to
|
|
* @param {boolean} [config.isOptIn] - happened during opt in/out workflow
|
|
* @param {Object} [config.properties] - object of custom values to track, snake_case
|
|
* @param {number} [config.revenue] - amount of currency that event creates in revenue for MetaMask
|
|
* @param {string} [config.currency] - ISO 4127 format currency for events with revenue, defaults to US dollars
|
|
* @param {number} [config.value] - Abstract "value" that this event has for MetaMask.
|
|
* @return {() => undefined} function to execute the tracking event
|
|
*/
|
|
export function useNewMetricEvent(config) {
|
|
const memoizedConfig = useEqualityCheck(config)
|
|
const metricsEvent = useContext(NewMetaMetricsContext)
|
|
return useCallback(() => metricsEvent(memoizedConfig), [
|
|
metricsEvent,
|
|
memoizedConfig,
|
|
])
|
|
}
|