Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistevam committed Jul 25, 2024
1 parent 9a93288 commit 552754a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 28 deletions.
12 changes: 6 additions & 6 deletions ui/components/app/alert-system/alert-modal/alert-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -267,21 +267,21 @@ function ActionButton({
action?: { key: string; label: string };
onClose: (request: { recursive?: boolean } | void) => void;
metrics: {
trackAlertsMetrics: ({
trackAlertMetrics: ({
alertKey,
action,
}: UseAlertSystemMetricsProps) => void;
alertKey: string;
};
}) {
const { processAction } = useAlertActionHandler();
const { trackAlertsMetrics, alertKey } = metrics;
const { trackAlertMetrics, alertKey } = metrics;

const handleClick = useCallback(() => {
if (!action) {
return;
}
trackAlertsMetrics({
trackAlertMetrics({
alertKey,
action: AlertsActionMetrics.AlertActionClicked,
});
Expand Down Expand Up @@ -322,7 +322,7 @@ export function AlertModal({
enableProvider = true,
}: AlertModalProps) {
const { isAlertConfirmed, setAlertConfirmed, alerts } = useAlerts(ownerId);
const { trackAlertsMetrics } = useAlertSystemMetrics();
const { trackAlertMetrics } = useAlertSystemMetrics();

const handleClose = useCallback(
(...args) => {
Expand All @@ -344,7 +344,7 @@ export function AlertModal({
}, [isConfirmed, selectedAlert.key]);

useEffect(() => {
trackAlertsMetrics({
trackAlertMetrics({
alertKey,
action: AlertsActionMetrics.AlertVisualized,
});
Expand Down Expand Up @@ -407,7 +407,7 @@ export function AlertModal({
action={action}
onClose={handleClose}
metrics={{
trackAlertsMetrics,
trackAlertMetrics,
alertKey: selectedAlert.key,
}}
/>
Expand Down
26 changes: 10 additions & 16 deletions ui/components/app/alert-system/useAlertSystemMetrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function useUpdateAlertMetrics() {
const { alerts, isAlertConfirmed } = useAlerts(ownerId);
const { updateTransactionEventFragment } = useTransactionEventFragment();

const trackAlertMetrics = useCallback(() => {
const updateAlertMetrics = useCallback(() => {
const isValidType = REDESIGN_TRANSACTION_TYPES.includes(
currentConfirmation?.type as TransactionType,
);
Expand All @@ -51,10 +51,10 @@ export function useUpdateAlertMetrics() {
);

const properties = {
alert_triggered_count: alerts.length,
alert_triggered: getAlertsName(alerts),
alert_resolved_count: confirmedAlerts.length,
alert_triggered_count: alerts.length,
alert_resolved: getAlertsName(confirmedAlerts),
alert_resolved_count: confirmedAlerts.length,
};

updateTransactionEventFragment({ properties }, ownerId);
Expand All @@ -66,7 +66,7 @@ export function useUpdateAlertMetrics() {
updateTransactionEventFragment,
]);

return trackAlertMetrics;
return { updateAlertMetrics };
}

export function useAlertSystemMetrics() {
Expand All @@ -88,12 +88,12 @@ export function useAlertSystemMetrics() {
useEffect(() => {
if (isValidType && alerts.length > 0) {
const properties = {
alert_triggered_count: alerts.length,
alert_triggered: getAlertsName(alerts),
alert_resolved_count: confirmedAlerts.length,
alert_triggered_count: alerts.length,
alert_resolved: getAlertsName(confirmedAlerts),
alert_visualized_count: alertVisualized.length,
alert_resolved_count: confirmedAlerts.length,
alert_visualized: alertVisualized,
alert_visualized_count: alertVisualized.length,
alert_key_clicked: alertKeyClicked,
alert_action_clicked: alertActionClicked,
};
Expand All @@ -109,14 +109,8 @@ export function useAlertSystemMetrics() {
alertVisualized,
]);

const trackAlertsMetrics = useCallback(
({
alertKey,
action,
}: {
alertKey: string;
action: AlertsActionMetrics;
}) => {
const trackAlertMetrics = useCallback(
({ alertKey, action }: UseAlertSystemMetricsProps) => {
if (!alertKey || !action || !isValidType) {
return;
}
Expand All @@ -140,7 +134,7 @@ export function useAlertSystemMetrics() {
);

return {
trackAlertsMetrics,
trackAlertMetrics,
};
}

Expand Down
4 changes: 2 additions & 2 deletions ui/components/app/confirm/info/row/alert-row/alert-row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const ConfirmInfoAlertRow = ({
variant,
...rowProperties
}: ConfirmInfoAlertRowProps) => {
const { trackAlertsMetrics } = useAlertSystemMetrics();
const { trackAlertMetrics } = useAlertSystemMetrics();
const { getFieldAlerts } = useAlerts(ownerId);
const fieldAlerts = getFieldAlerts(alertKey);
const hasFieldAlert = fieldAlerts.length > 0;
Expand All @@ -61,7 +61,7 @@ export const ConfirmInfoAlertRow = ({

const handleInlineAlertClick = () => {
setAlertModalVisible(true);
trackAlertsMetrics({
trackAlertMetrics({
alertKey: selectedAlertKey,
action: AlertsActionMetrics.InlineAlertClicked,
});
Expand Down
7 changes: 3 additions & 4 deletions ui/pages/confirmations/components/confirm/footer/footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const ConfirmButton = ({
};

const Footer = () => {
const trackAlertMetrics = useUpdateAlertMetrics();
const { updateAlertMetrics } = useUpdateAlertMetrics();
const dispatch = useDispatch();
const t = useI18nContext();
const confirm = useSelector(confirmSelector);
Expand All @@ -103,8 +103,6 @@ const Footer = () => {
const { currentConfirmation, isScrollToBottomNeeded } = confirm;
const { from } = getConfirmationSender(currentConfirmation);

trackAlertMetrics();

///: BEGIN:ONLY_INCLUDE_IF(build-mmi)
const { mmiOnSignCallback, mmiSubmitDisabled } = useMMIConfirmations();
///: END:ONLY_INCLUDE_IF
Expand All @@ -120,6 +118,7 @@ const Footer = () => {
if (!currentConfirmation) {
return;
}
updateAlertMetrics();

dispatch(
rejectPendingApproval(
Expand All @@ -133,7 +132,7 @@ const Footer = () => {
if (!currentConfirmation) {
return;
}
trackAlertMetrics();
updateAlertMetrics();

const isTransactionConfirmation = REDESIGN_TRANSACTION_TYPES.find(
(type) => type === currentConfirmation?.type,
Expand Down
3 changes: 3 additions & 0 deletions ui/pages/confirmations/hooks/setConfirmationAlerts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ import {
updateAlerts,
} from '../../../ducks/confirm-alerts/confirm-alerts';
import { currentConfirmationSelector } from '../../../selectors';
import { useUpdateAlertMetrics } from '../../../components/app/alert-system/useAlertSystemMetrics';
import useConfirmationAlerts from './useConfirmationAlerts';

const setConfirmationAlerts = () => {
const dispatch = useDispatch();
const currentConfirmation = useSelector(currentConfirmationSelector);
const alerts = useConfirmationAlerts();
const ownerId = currentConfirmation?.id as string;
const { updateAlertMetrics } = useUpdateAlertMetrics();
updateAlertMetrics();

useEffect(() => {
dispatch(updateAlerts(ownerId, alerts));
Expand Down

0 comments on commit 552754a

Please sign in to comment.