Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@ import Address from './address';
import { CHAIN_IDS } from '@metamask/transaction-controller';
import { NameType } from '../../../../../../../UI/Name/Name.types';

jest.mock(
'../../../../../../../../selectors/featureFlagController/multichainAccounts',
() => ({
selectMultichainAccountsState2Enabled: () => false,
}),
);

const mockInitialState = {
engine: {
backgroundState: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('Recipient', () => {
const createMockRecipient = (
overrides: Partial<RecipientType> = {},
): RecipientType => ({
accountName: 'John Doe',
accountGroupName: 'John Doe',
address: '0x1234567890123456789012345678901234567890',
...overrides,
});
Expand All @@ -23,7 +23,7 @@ describe('Recipient', () => {

it('renders recipient name correctly', () => {
const mockRecipient = createMockRecipient({
accountName: 'Alice Smith',
accountGroupName: 'Alice Smith',
});

const { getByText } = renderWithProvider(
Expand Down Expand Up @@ -111,7 +111,7 @@ describe('Recipient', () => {
expect(getByText('0x12345...67890')).toBeOnTheScreen();
});

it('renders contact name when BIP44 is true and account group name is not provided', () => {
it('renders contact name when account group name is not provided', () => {
const mockRecipient = createMockRecipient({
accountGroupName: undefined,
contactName: 'Contact Name',
Expand All @@ -120,7 +120,6 @@ describe('Recipient', () => {
const { getByText } = renderWithProvider(
<Recipient
recipient={mockRecipient}
isBIP44
accountAvatarType={AvatarAccountType.JazzIcon}
onPress={mockOnPress}
/>,
Expand All @@ -129,8 +128,26 @@ describe('Recipient', () => {
expect(getByText('Contact Name')).toBeOnTheScreen();
});

it('renders account group name when provided', () => {
const mockRecipient = createMockRecipient({
accountGroupName: 'My Wallet',
contactName: 'Contact Name',
});

const { getByText } = renderWithProvider(
<Recipient
recipient={mockRecipient}
accountAvatarType={AvatarAccountType.JazzIcon}
onPress={mockOnPress}
/>,
);

expect(getByText('My Wallet')).toBeOnTheScreen();
});

it('renders BTC account type label when account type is BTC', () => {
const mockRecipient = createMockRecipient({
accountGroupName: 'BTC Wallet',
accountType: BtcAccountType.P2wpkh,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,13 @@ export interface RecipientType {
interface RecipientProps {
recipient: RecipientType;
isSelected?: boolean;
isBIP44?: boolean;
accountAvatarType: AvatarAccountType;
onPress?: (recipient: RecipientType) => void;
}

export function Recipient({
recipient,
isSelected,
isBIP44,
accountAvatarType,
onPress,
}: RecipientProps) {
Expand Down Expand Up @@ -107,9 +105,7 @@ export function Recipient({
fontWeight={FontWeight.Medium}
numberOfLines={1}
>
{isBIP44
? recipient.accountGroupName || recipient.contactName
: recipient.accountName || recipient.contactName}
{recipient.accountGroupName || recipient.contactName}
</Text>
<Box twClassName="flex-row items-center">
<Text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ import {
import PersonalSign from './personal-sign';
import { MAINNET_DISPLAY_NAME } from '../../../../../../core/Engine/constants';

jest.mock(
'../../../../../../selectors/featureFlagController/multichainAccounts',
() => ({
selectMultichainAccountsState2Enabled: () => false,
}),
);

jest.mock('../../../../../../core/Engine', () => ({
getTotalEvmFiatAccountBalance: () => ({ tokenFiat: 10 }),
context: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ jest.mock('../../context/send-context/send-context', () => ({
useSendContext: jest.fn(),
}));

jest.mock('../../hooks/send/useSendScope', () => ({
useSendScope: jest.fn(),
}));

jest.mock('../../../../../../locales/i18n', () => ({
strings: jest.fn((key: string) => {
const map: Record<string, string> = {
Expand All @@ -27,7 +23,6 @@ jest.mock('../../../../../../locales/i18n', () => ({
}),
}));

// Mock child Recipient to keep tests deterministic and focused on grouping logic
jest.mock('../UI/recipient', () => ({
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Recipient: ({ recipient, isSelected, onPress }: any) => {
Expand All @@ -54,7 +49,6 @@ jest.mock('../UI/recipient', () => ({
},
}));

const { useSendScope } = jest.requireMock('../../hooks/send/useSendScope');
const { useSendContext } = jest.requireMock(
'../../context/send-context/send-context',
);
Expand All @@ -80,13 +74,11 @@ describe('RecipientList - BIP44 grouping', () => {
},
{
address: '0x4444444444444444444444444444444444444444',
// no walletName to trigger Unknown Wallet grouping
},
];

beforeEach(() => {
jest.clearAllMocks();
useSendScope.mockReturnValue({ isBIP44: true });
useSendContext.mockReturnValue({
to: '0x2222222222222222222222222222222222222222',
});
Expand All @@ -97,7 +89,6 @@ describe('RecipientList - BIP44 grouping', () => {
<RecipientList data={data} onRecipientSelected={onRecipientSelected} />,
);

// Group headers
expect(getByText('Wallet A')).toBeOnTheScreen();
expect(getByText('Wallet B')).toBeOnTheScreen();
expect(getByText('Unknown Wallet')).toBeOnTheScreen();
Expand Down Expand Up @@ -146,89 +137,35 @@ describe('RecipientList - BIP44 grouping', () => {
);
expect(onRecipientSelected).not.toHaveBeenCalled();
});
});

describe('RecipientList - non-BIP44 (flat list)', () => {
const onRecipientSelected = jest.fn();

const flatData: RecipientType[] = [
{
address: '0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
accountName: 'Account 1',
},
{
address: '0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
accountName: 'Account 2',
},
];

beforeEach(() => {
jest.clearAllMocks();
useSendScope.mockReturnValue({ isBIP44: false });
useSendContext.mockReturnValue({
to: '0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
});
});

it('renders accounts header and no wallet group headers', () => {
const { getByText, queryByText } = renderWithProvider(
it('renders empty state when data is empty and emptyMessage provided', () => {
const { getByText } = renderWithProvider(
<RecipientList
data={flatData}
data={[]}
onRecipientSelected={onRecipientSelected}
emptyMessage="No recipients"
/>,
);

expect(getByText('Your Accounts')).toBeOnTheScreen();
expect(queryByText('Wallet A')).toBeNull();
expect(queryByText('Wallet B')).toBeNull();
expect(queryByText('Unknown Wallet')).toBeNull();
expect(getByText('No recipients')).toBeOnTheScreen();
});

it('marks selection and calls onRecipientSelected on press', () => {
const { getByTestId } = renderWithProvider(
<RecipientList
data={flatData}
onRecipientSelected={onRecipientSelected}
/>,
);

expect(
getByTestId('selected-0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'),
).toBeOnTheScreen();
fireEvent.press(
getByTestId('recipient-0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'),
);
expect(onRecipientSelected).toHaveBeenCalledWith(
expect.objectContaining({
it('renders contacts header for contact lists', () => {
const contactData: RecipientType[] = [
{
address: '0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
}),
);
});
contactName: 'Alice',
},
];

it('does not call onRecipientSelected when disabled', () => {
const { getByTestId } = renderWithProvider(
<RecipientList
data={flatData}
onRecipientSelected={onRecipientSelected}
disabled
/>,
);

fireEvent.press(
getByTestId('recipient-0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'),
);
expect(onRecipientSelected).not.toHaveBeenCalled();
});

it('renders empty state when data is empty and emptyMessage provided', () => {
const { getByText } = renderWithProvider(
<RecipientList
data={[]}
data={contactData}
onRecipientSelected={onRecipientSelected}
emptyMessage="No recipients"
isContactList
/>,
);

expect(getByText('No recipients')).toBeOnTheScreen();
expect(getByText('Contacts')).toBeOnTheScreen();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
import { useAccountAvatarType } from '../../hooks/useAccountAvatarType';
import { useSendContext } from '../../context/send-context/send-context';
import { Recipient, type RecipientType } from '../UI/recipient';
import { useSendScope } from '../../hooks/send/useSendScope';
import { AvatarAccountType } from '../../../../../component-library/components/Avatars/Avatar/variants/AvatarAccount';
import { strings } from '../../../../../../locales/i18n';

Expand All @@ -31,7 +30,6 @@ export function RecipientList({
}: RecipientListProps) {
const accountAvatarType = useAccountAvatarType();
const { to } = useSendContext();
const { isBIP44 } = useSendScope();

if (data.length === 0 && emptyMessage) {
return (
Expand All @@ -41,7 +39,7 @@ export function RecipientList({
);
}

if (isContactList || !isBIP44) {
if (isContactList) {
return (
<Box twClassName="flex-1">
<Text
Expand All @@ -50,14 +48,13 @@ export function RecipientList({
color={TextColor.TextAlternative}
fontWeight={FontWeight.Medium}
>
{strings(isContactList ? 'send.contacts' : 'send.accounts')}
{strings('send.contacts')}
</Text>
<FlatRecipientList
data={data}
onRecipientSelected={onRecipientSelected}
accountAvatarType={accountAvatarType}
to={to}
isBIP44={isBIP44}
disabled={disabled}
/>
</Box>
Expand All @@ -71,7 +68,6 @@ export function RecipientList({
onRecipientSelected={onRecipientSelected}
accountAvatarType={accountAvatarType}
to={to}
isBIP44={isBIP44}
disabled={disabled}
/>
</Box>
Expand All @@ -83,14 +79,12 @@ function FlatRecipientList({
onRecipientSelected,
accountAvatarType,
to,
isBIP44,
disabled,
}: {
data: RecipientType[];
onRecipientSelected: (recipient: RecipientType) => void;
accountAvatarType: AvatarAccountType;
to?: string;
isBIP44?: boolean;
disabled?: boolean;
}) {
return (
Expand All @@ -101,7 +95,6 @@ function FlatRecipientList({
recipient={recipient}
accountAvatarType={accountAvatarType}
isSelected={to === recipient.address}
isBIP44={isBIP44}
onPress={disabled ? undefined : onRecipientSelected}
/>
))}
Expand All @@ -114,14 +107,12 @@ function BIP44RecipientList({
onRecipientSelected,
accountAvatarType,
to,
isBIP44,
disabled,
}: {
data: RecipientType[];
onRecipientSelected: (recipient: RecipientType) => void;
accountAvatarType: AvatarAccountType;
to?: string;
isBIP44?: boolean;
disabled?: boolean;
}) {
const groupedData = useMemo(
Expand Down Expand Up @@ -158,7 +149,6 @@ function BIP44RecipientList({
recipient={recipient}
accountAvatarType={accountAvatarType}
isSelected={to === recipient.address}
isBIP44={isBIP44}
onPress={disabled ? undefined : onRecipientSelected}
/>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,6 @@ jest.mock('../../../../../../core/Engine', () => {
};
});

jest.mock(
'../../../../../../selectors/featureFlagController/multichainAccounts',
() => ({
selectMultichainAccountsState2Enabled: () => false,
}),
);

describe('AccountNetworkInfo', () => {
it('should render correctly', async () => {
const { getByText, getByTestId } = renderWithProvider(
Expand Down
Loading
Loading