-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into release/7.34.1
- Loading branch information
Showing
13 changed files
with
213 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
app/components/UI/Stake/utils/metaMetrics/tooltipMetaMetricsUtils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { MetricsEventBuilder } from '../../../../../core/Analytics/MetricsEventBuilder'; | ||
import { MetaMetricsEvents } from '../../../../hooks/useMetrics'; | ||
|
||
export const getTooltipMetricProperties = ( | ||
location: string, | ||
tooltipName: string, | ||
) => ({ | ||
selected_provider: 'consensys', | ||
text: 'Tooltip Opened', | ||
location, | ||
tooltip_name: tooltipName, | ||
}); | ||
|
||
export const createTooltipOpenedEvent = ( | ||
location: string, | ||
tooltipName: string, | ||
) => { | ||
const createEventBuilder = MetricsEventBuilder.createEventBuilder; | ||
|
||
return createEventBuilder(MetaMetricsEvents.TOOLTIP_OPENED) | ||
.addProperties(getTooltipMetricProperties(location, tooltipName)) | ||
.build(); | ||
}; |
56 changes: 56 additions & 0 deletions
56
app/components/UI/Stake/utils/metaMetrics/withMetaMetrics.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { | ||
IMetaMetricsEvent, | ||
JsonMap, | ||
} from '../../../../../core/Analytics/MetaMetrics.types'; | ||
import { MetricsEventBuilder } from '../../../../../core/Analytics/MetricsEventBuilder'; | ||
import { MetaMetrics } from '../../../../../core/Analytics'; | ||
|
||
interface WithMetaMetricsEvent { | ||
event: IMetaMetricsEvent; | ||
properties?: JsonMap; | ||
} | ||
|
||
const createEventBuilder = MetricsEventBuilder.createEventBuilder; | ||
|
||
const shouldAddProperties = (properties?: JsonMap): properties is JsonMap => { | ||
if (!properties) return false; | ||
return Object.keys(properties).length > 0; | ||
}; | ||
|
||
const buildEvent = (e: WithMetaMetricsEvent) => { | ||
const eventBuilder = createEventBuilder(e.event); | ||
|
||
if (shouldAddProperties(e?.properties)) { | ||
eventBuilder.addProperties(e.properties); | ||
} | ||
|
||
return eventBuilder.build(); | ||
}; | ||
|
||
export const withMetaMetrics = <T extends (...args: unknown[]) => unknown>( | ||
func: T, | ||
events: WithMetaMetricsEvent | WithMetaMetricsEvent[], | ||
) => { | ||
if (!Array.isArray(events)) { | ||
events = [events]; | ||
} | ||
|
||
const builtEvents = events.map((event) => buildEvent(event)); | ||
|
||
return (...args: Parameters<T>): ReturnType<T> | Promise<ReturnType<T>> => { | ||
const result = func(...args); | ||
|
||
if (result instanceof Promise) { | ||
return result.then((res) => { | ||
builtEvents.forEach((event) => | ||
MetaMetrics.getInstance().trackEvent(event), | ||
); | ||
return res; | ||
}) as Promise<ReturnType<T>>; | ||
} | ||
|
||
builtEvents.forEach((event) => MetaMetrics.getInstance().trackEvent(event)); | ||
|
||
return result as ReturnType<T>; | ||
}; | ||
}; |
Oops, something went wrong.