Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions shared/constants/metametrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,8 @@ export enum MetaMetricsEventName {
BlockExplorerLinkClicked = 'Block Explorer Clicked',
AccountRemoved = 'Account Removed',
AccountRemoveFailed = 'Account Remove Failed',
AccountPinned = 'Account Pinned',
AccountHidden = 'Account Hidden',
TestNetworksDisplayed = 'Test Networks Displayed',
AddNetworkButtonClick = 'Add Network Button Clicked',
CustomNetworkAdded = 'Custom Network Added',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const mockState = {
},
},
},
pinnedAccountList: [],
hiddenAccountList: [],
},
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useMemo, useRef } from 'react';
import React, { useContext, useMemo, useRef } from 'react';
import { useHistory } from 'react-router-dom';
import { useDispatch, useSelector } from 'react-redux';
import {
Expand Down Expand Up @@ -28,6 +28,15 @@ import {
setAccountGroupHidden,
} from '../../../store/actions';
import { getAccountTree } from '../../../selectors/multichain-accounts/account-tree';
import {
getPinnedAccountsList,
getHiddenAccountsList,
} from '../../../selectors/selectors';
import { MetaMetricsContext } from '../../../contexts/metametrics';
import {
MetaMetricsEventCategory,
MetaMetricsEventName,
} from '../../../../shared/constants/metametrics';
import { MultichainAccountMenuProps } from './multichain-account-menu.types';

export const MultichainAccountMenu = ({
Expand All @@ -42,6 +51,9 @@ export const MultichainAccountMenu = ({
const dispatch = useDispatch();
const popoverRef = useRef<HTMLDivElement>(null);
const accountTree = useSelector(getAccountTree);
const trackEvent = useContext(MetaMetricsContext);
const pinnedAccountsList = useSelector(getPinnedAccountsList);
const hiddenAccountsList = useSelector(getHiddenAccountsList);

// Get the account group metadata to check pinned/hidden state
const accountGroupMetadata = useMemo(() => {
Expand Down Expand Up @@ -89,25 +101,63 @@ export const MultichainAccountMenu = ({
mouseEvent.stopPropagation();
mouseEvent.preventDefault();

const willBePinned = !isPinned;

// If account is hidden, unhide it first before pinning
if (isHidden) {
await dispatch(setAccountGroupHidden(accountGroupId, false));
}

await dispatch(setAccountGroupPinned(accountGroupId, !isPinned));
await dispatch(setAccountGroupPinned(accountGroupId, willBePinned));

// Calculate the count after the action
const pinnedCountAfter = willBePinned
? pinnedAccountsList.length + 1
: pinnedAccountsList.length - 1;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Account Group Pinning: Count Mismatch

The pinnedCountAfter calculation assumes only one address is added or removed, but account groups can contain multiple addresses across different chains. When pinning or unpinning a group with N addresses, the count changes by N, not 1. The calculation uses stale list values captured at render time and doesn't account for the actual number of addresses in the account group being modified.

Fix in Cursor Fix in Web


// Track the event
trackEvent({
event: MetaMetricsEventName.AccountPinned,
category: MetaMetricsEventCategory.Accounts,
properties: {
pinned: willBePinned,
// eslint-disable-next-line @typescript-eslint/naming-convention
pinned_count_after: pinnedCountAfter,
},
});

onToggle?.();
};

const handleAccountHideClick = async (mouseEvent: React.MouseEvent) => {
mouseEvent.stopPropagation();
mouseEvent.preventDefault();

const willBeHidden = !isHidden;

// If account is pinned, unpin it first before hiding
if (isPinned) {
await dispatch(setAccountGroupPinned(accountGroupId, false));
}

await dispatch(setAccountGroupHidden(accountGroupId, !isHidden));
await dispatch(setAccountGroupHidden(accountGroupId, willBeHidden));

// Calculate the count after the action
const hiddenCountAfter = willBeHidden
? hiddenAccountsList.length + 1
: hiddenAccountsList.length - 1;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Hidden Count Mismatch for Account Groups

The hiddenCountAfter calculation assumes only one address is added or removed, but account groups can contain multiple addresses across different chains. When hiding or unhiding a group with N addresses, the count changes by N, not 1. The calculation uses stale list values captured at render time and doesn't account for the actual number of addresses in the account group being modified.

Fix in Cursor Fix in Web


// Track the event
trackEvent({
event: MetaMetricsEventName.AccountHidden,
category: MetaMetricsEventCategory.Accounts,
properties: {
hidden: willBeHidden,
// eslint-disable-next-line @typescript-eslint/naming-convention
hidden_count_after: hiddenCountAfter,
},
});

onToggle?.();
};

Expand Down Expand Up @@ -164,6 +214,9 @@ export const MultichainAccountMenu = ({
isHidden,
dispatch,
onToggle,
pinnedAccountsList,
hiddenAccountsList,
trackEvent,
]);

return (
Expand Down
Loading