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
1 change: 1 addition & 0 deletions .storybook/storybook.requires.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
import { MultichainAddressRowProps } from './MultichainAddressRow.types';
import { ProviderConfig } from '../../../../selectors/networkController';

export const SAMPLE_MULTICHAIN_ADDRESS_ROW_PROPS: MultichainAddressRowProps = {
network: {
nickname: 'Ethereum Mainnet',
chainId: '0x1',
ticker: 'ETH',
type: 'mainnet',
rpcPrefs: {},
} as ProviderConfig,
chainId: 'eip155:1',
networkName: 'Ethereum Mainnet',
address: '0x1234567890123456789012345678901234567890',
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
/* eslint-disable react-native/no-inline-styles */
import React from 'react';
import { View } from 'react-native';
import { CaipChainId } from '@metamask/utils';
import { mockTheme } from '../../../../util/theme';
import { default as MultichainAddressRowComponent } from './MultichainAddressRow';
import { ProviderConfig } from '../../../../selectors/networkController';
import { SAMPLE_MULTICHAIN_ADDRESS_ROW_PROPS } from './MultichainAddressRow.constants';

const MultichainAddressRowMeta = {
title: 'Component Library / MultichainAccounts',
component: MultichainAddressRowComponent,
argTypes: {
chainId: {
control: { type: 'text' },
defaultValue: SAMPLE_MULTICHAIN_ADDRESS_ROW_PROPS.chainId,
},
networkName: {
control: { type: 'text' },
defaultValue: SAMPLE_MULTICHAIN_ADDRESS_ROW_PROPS.network.nickname,
defaultValue: SAMPLE_MULTICHAIN_ADDRESS_ROW_PROPS.networkName,
},
address: {
control: { type: 'text' },
Expand All @@ -23,7 +27,11 @@ const MultichainAddressRowMeta = {
export default MultichainAddressRowMeta;

export const MultichainAddressRow = {
render: (args: { networkName: string; address: string }) => (
render: (args: {
chainId: CaipChainId;
networkName: string;
address: string;
}) => (
<View
style={{
alignItems: 'center',
Expand All @@ -33,18 +41,16 @@ export const MultichainAddressRow = {
}}
>
<MultichainAddressRowComponent
network={{
...SAMPLE_MULTICHAIN_ADDRESS_ROW_PROPS.network,
nickname: args.networkName,
}}
chainId={args.chainId}
networkName={args.networkName}
address={args.address}
/>
</View>
),
};

export const WithLongNetworkName = {
render: (args: { address: string }) => (
render: (args: { chainId: CaipChainId; address: string }) => (
<View
style={{
alignItems: 'center',
Expand All @@ -54,10 +60,8 @@ export const WithLongNetworkName = {
}}
>
<MultichainAddressRowComponent
network={{
...SAMPLE_MULTICHAIN_ADDRESS_ROW_PROPS.network,
nickname: 'Very Long Network Name That Might Wrap',
}}
chainId={args.chainId || '0x1'}
networkName="Very Long Network Name That Might Wrap"
address={args.address}
/>
</View>
Expand All @@ -75,15 +79,8 @@ export const WithCustomNetwork = {
}}
>
<MultichainAddressRowComponent
network={
{
nickname: 'Polygon Mainnet',
chainId: '0x89',
ticker: 'MATIC',
type: 'rpc',
rpcPrefs: {},
} as ProviderConfig
}
chainId="eip155:137"
networkName="Polygon Mainnet"
address="0xabcdefabcdefabcdefabcdefabcdefabcdefabcd"
/>
</View>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,15 @@ describe('MultichainAddressRow', () => {
expect(component).toBeTruthy();
});

it('should handle network without rpcPrefs', () => {
const propsWithoutRpcPrefs = {
it('should handle unknown chainId', () => {
const propsWithUnknownChainId = {
...SAMPLE_MULTICHAIN_ADDRESS_ROW_PROPS,
network: {
...SAMPLE_MULTICHAIN_ADDRESS_ROW_PROPS.network,
rpcPrefs: {},
},
chainId: 'eip155:999999' as const,
networkName: 'Unknown Network',
};

const { getByTestId } = render(
<MultichainAddressRow {...propsWithoutRpcPrefs} />,
<MultichainAddressRow {...propsWithUnknownChainId} />,
);
const networkIcon = getByTestId(
MULTICHAIN_ADDRESS_ROW_NETWORK_ICON_TEST_ID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import {
import useCopyClipboard from '../../../../components/Views/Notifications/Details/hooks/useCopyClipboard';

const MultichainAddressRow = ({
network,
chainId,
networkName,
address,
style,
testID = MULTICHAIN_ADDRESS_ROW_TEST_ID,
Expand All @@ -36,10 +37,7 @@ const MultichainAddressRow = ({
const { styles } = useStyles(styleSheet, { style });
const copyToClipboard = useCopyClipboard();

const networkImageSource = getNetworkImageSource({
chainId: network.chainId,
networkType: network.type,
});
const networkImageSource = getNetworkImageSource({ chainId });
const truncatedAddress = formatAddress(address, 'short');

const handleCopyClick = useCallback(() => {
Expand All @@ -56,7 +54,7 @@ const MultichainAddressRow = ({
<Avatar
variant={AvatarVariant.Network}
size={AvatarSize.Md}
name={network.nickname}
name={networkName}
imageSource={networkImageSource}
testID={MULTICHAIN_ADDRESS_ROW_NETWORK_ICON_TEST_ID}
/>
Expand All @@ -67,7 +65,7 @@ const MultichainAddressRow = ({
color={TextColor.Default}
testID={MULTICHAIN_ADDRESS_ROW_NETWORK_NAME_TEST_ID}
>
{network.nickname}
{networkName}
</Text>
<Text
variant={TextVariant.BodySM}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { StyleProp, ViewStyle } from 'react-native';
import { ProviderConfig } from '../../../../selectors/networkController';
import { CaipChainId } from '@metamask/utils';

export interface MultichainAddressRowProps {
/**
* Network provider configuration containing nickname, chainId, and other network details
* Chain ID to identify the network
*/
network: ProviderConfig;
chainId: CaipChainId;
/**
* Network name to display
*/
networkName: string;
/**
* Address string to display (will be truncated)
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Test IDs
export const MULTICHAIN_ADDRESS_ROWS_LIST_TEST_ID =
'multichain-address-rows-list';
export const MULTICHAIN_ADDRESS_ROWS_LIST_SEARCH_TEST_ID =
'multichain-address-rows-list-search';
export const MULTICHAIN_ADDRESS_ROWS_LIST_EMPTY_MESSAGE_TEST_ID =
'multichain-address-rows-list-empty-message';
Loading
Loading