Skip to content

Commit

Permalink
Trigger and terminate custom spans when clicking on account list item…
Browse files Browse the repository at this point in the history
… or account overview tab
  • Loading branch information
MajorLift committed Oct 30, 2024
1 parent 5a1b6ec commit b30323f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
19 changes: 19 additions & 0 deletions ui/components/multichain/account-list-menu/account-list-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import {
getOriginOfCurrentTab,
getSelectedInternalAccount,
getUpdatedAndSortedAccounts,
getDefaultHomeActiveTabName,
} from '../../../selectors';
import { setSelectedAccount } from '../../../store/actions';
import {
Expand Down Expand Up @@ -234,6 +235,7 @@ export const AccountListMenu = ({
),
[updatedAccountsList, allowedAccountTypes],
);
const defaultHomeActiveTabName = useSelector(getDefaultHomeActiveTabName);
///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps)
const addSnapAccountEnabled = useSelector(getIsAddSnapAccountEnabled);
///: END:ONLY_INCLUDE_IF
Expand Down Expand Up @@ -303,6 +305,22 @@ export const AccountListMenu = ({
}
}

const handleTraceFromTabName = (tabName: string) => {
switch (tabName) {
case 'nfts':
endTrace({ name: TraceName.AccountOverviewNftsTab });
trace({ name: TraceName.AccountOverviewNftsTab });
break;
case 'activity':
endTrace({ name: TraceName.AccountOverviewActivityTab });
trace({ name: TraceName.AccountOverviewActivityTab });
break;
default:
endTrace({ name: TraceName.AccountOverviewAssetListTab });
trace({ name: TraceName.AccountOverviewAssetListTab });
}
};

const onAccountListItemItemClicked = useCallback(
(account) => {
return () => {
Expand All @@ -314,6 +332,7 @@ export const AccountListMenu = ({
location: 'Main Menu',
},
});
handleTraceFromTabName(defaultHomeActiveTabName);
dispatch(setSelectedAccount(account.address));
};
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useCallback, useContext, useEffect, useMemo } from 'react';
import React, { useCallback, useContext, useMemo } from 'react';
import { useHistory } from 'react-router-dom';
import { endTraces, trace, TraceName } from '../../../../shared/lib/trace';
import { useI18nContext } from '../../../hooks/useI18nContext';
import { ASSET_ROUTE } from '../../../helpers/constants/routes';
import {
Expand Down Expand Up @@ -37,7 +38,6 @@ import {
///: BEGIN:ONLY_INCLUDE_IF(build-mmi)
import InstitutionalHomeFooter from '../../../pages/home/institutional/institutional-home-footer';
///: END:ONLY_INCLUDE_IF
import { endTrace, trace, TraceName } from '../../../../shared/lib/trace';
import { AccountOverviewCommonProps } from './common';

export type AccountOverviewTabsProps = AccountOverviewCommonProps & {
Expand All @@ -62,10 +62,6 @@ export const AccountOverviewTabs = ({
const t = useI18nContext();
const trackEvent = useContext(MetaMetricsContext);

useEffect(() => {
endTrace({ name: TraceName.AccountOverviewTab });
}, []);

const tabProps = useMemo(
() => ({
activeClassName: 'account-overview__tab--active',
Expand All @@ -85,13 +81,32 @@ export const AccountOverviewTabs = ({
}
};

const handleTraceFromTabName = (tabName: string) => {
endTraces(
{ name: TraceName.AccountOverviewAssetListTab },
{ name: TraceName.AccountOverviewNftsTab },
{ name: TraceName.AccountOverviewActivityTab },
);
switch (tabName) {
case 'nfts':
trace({ name: TraceName.AccountOverviewNftsTab });
break;
case 'activity':
trace({ name: TraceName.AccountOverviewActivityTab });
break;
default:
trace({ name: TraceName.AccountOverviewAssetListTab });
}
};

const handleTabClick = useCallback(
(tabName: string) => {
onTabClick(tabName);
trackEvent({
category: MetaMetricsEventCategory.Home,
event: getEventFromTabName(tabName),
});
handleTraceFromTabName(tabName);
},
[onTabClick],
);
Expand Down

0 comments on commit b30323f

Please sign in to comment.