Skip to content

Commit d265500

Browse files
committed
Memoize dependency with unstable reference
1 parent 6e752a2 commit d265500

File tree

1 file changed

+29
-22
lines changed

1 file changed

+29
-22
lines changed

ui/pages/confirmations/hooks/useConfirmationAlertMetrics.ts

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useCallback, useEffect, useState } from 'react';
1+
import { useCallback, useEffect, useMemo, useState } from 'react';
22
import { validate as isUuid } from 'uuid';
33

44
import useAlerts from '../../../hooks/useAlerts';
@@ -55,7 +55,31 @@ function getAlertName(alertKey: string): string {
5555
export function useConfirmationAlertMetrics() {
5656
const { currentConfirmation } = useConfirmContext();
5757
const ownerId = currentConfirmation?.id ?? '';
58+
5859
const { alerts, isAlertConfirmed } = useAlerts(ownerId);
60+
const alertsProperties = useMemo(() => {
61+
return alerts.length > 0
62+
? {
63+
// TODO: Fix in https://github.com/MetaMask/metamask-extension/issues/31860
64+
// eslint-disable-next-line @typescript-eslint/naming-convention
65+
alert_triggered_count: alerts.length,
66+
// TODO: Fix in https://github.com/MetaMask/metamask-extension/issues/31860
67+
// eslint-disable-next-line @typescript-eslint/naming-convention
68+
alert_triggered: getAlertNames(alerts),
69+
// TODO: Fix in https://github.com/MetaMask/metamask-extension/issues/31860
70+
// eslint-disable-next-line @typescript-eslint/naming-convention
71+
alert_resolved_count: alerts.filter((alert) =>
72+
isAlertConfirmed(alert.key),
73+
).length,
74+
// TODO: Fix in https://github.com/MetaMask/metamask-extension/issues/31860
75+
// eslint-disable-next-line @typescript-eslint/naming-convention
76+
alert_resolved: getAlertNames(
77+
alerts.filter((alert) => isAlertConfirmed(alert.key)),
78+
),
79+
}
80+
: undefined;
81+
}, [alerts, isAlertConfirmed]);
82+
5983
const { updateSignatureEventFragment } = useSignatureEventFragment();
6084
const { updateTransactionEventFragment } = useTransactionEventFragment();
6185

@@ -75,28 +99,11 @@ export function useConfirmationAlertMetrics() {
7599
alert_action_clicked: [],
76100
});
77101

78-
const properties =
79-
alerts.length > 0
80-
? {
81-
// TODO: Fix in https://github.com/MetaMask/metamask-extension/issues/31860
82-
// eslint-disable-next-line @typescript-eslint/naming-convention
83-
alert_triggered_count: alerts.length,
84-
// TODO: Fix in https://github.com/MetaMask/metamask-extension/issues/31860
85-
// eslint-disable-next-line @typescript-eslint/naming-convention
86-
alert_triggered: getAlertNames(alerts),
87-
// TODO: Fix in https://github.com/MetaMask/metamask-extension/issues/31860
88-
// eslint-disable-next-line @typescript-eslint/naming-convention
89-
alert_resolved_count: alerts.filter((alert) =>
90-
isAlertConfirmed(alert.key),
91-
).length,
92-
// TODO: Fix in https://github.com/MetaMask/metamask-extension/issues/31860
93-
// eslint-disable-next-line @typescript-eslint/naming-convention
94-
alert_resolved: getAlertNames(
95-
alerts.filter((alert) => isAlertConfirmed(alert.key)),
96-
),
97-
...metricsProperties,
98-
}
102+
const properties = useMemo(() => {
103+
return alertsProperties
104+
? { ...alertsProperties, ...metricsProperties }
99105
: undefined;
106+
}, [alertsProperties, metricsProperties]);
100107

101108
const trackAlertRender = useCallback((alertKey: string) => {
102109
setMetricsProperties((prevState) => {

0 commit comments

Comments
 (0)