1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 09:57:02 +01:00

UX Multichain: Added background color of test networks (#20032)

* added background color to token list item

* updated badge color for nft-item

* updated nft-item tests
This commit is contained in:
Nidhi Kumari 2023-07-17 22:13:26 +05:30 committed by GitHub
parent ce771bee66
commit 8e361b391a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 68 additions and 58 deletions

View File

@ -41,6 +41,7 @@ import {
getOriginOfCurrentTab, getOriginOfCurrentTab,
getSelectedIdentity, getSelectedIdentity,
getShowProductTour, getShowProductTour,
getTestNetworkBackgroundColor,
///: BEGIN:ONLY_INCLUDE_IN(build-mmi) ///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
getSelectedAddress, getSelectedAddress,
///: END:ONLY_INCLUDE_IN ///: END:ONLY_INCLUDE_IN
@ -89,8 +90,8 @@ export const AppHeader = ({ location }) => {
// Used for network icon / dropdown // Used for network icon / dropdown
const currentNetwork = useSelector(getCurrentNetwork); const currentNetwork = useSelector(getCurrentNetwork);
const testNetworkBackgroundColor = useSelector(getTestNetworkBackgroundColor);
// Used to get the environment and connection status
const popupStatus = getEnvironmentType() === ENVIRONMENT_TYPE_POPUP; const popupStatus = getEnvironmentType() === ENVIRONMENT_TYPE_POPUP;
const showStatus = const showStatus =
getEnvironmentType() === ENVIRONMENT_TYPE_POPUP && getEnvironmentType() === ENVIRONMENT_TYPE_POPUP &&
@ -206,6 +207,9 @@ export const AppHeader = ({ location }) => {
<Box className="multichain-app-header__contents__container"> <Box className="multichain-app-header__contents__container">
<Tooltip title={currentNetwork?.nickname} position="right"> <Tooltip title={currentNetwork?.nickname} position="right">
<PickerNetwork <PickerNetwork
avatarNetworkProps={{
backgroundColor: testNetworkBackgroundColor,
}}
className="multichain-app-header__contents--avatar-network" className="multichain-app-header__contents--avatar-network"
ref={menuRef} ref={menuRef}
as="button" as="button"
@ -225,6 +229,9 @@ export const AppHeader = ({ location }) => {
) : ( ) : (
<div> <div>
<PickerNetwork <PickerNetwork
avatarNetworkProps={{
backgroundColor: testNetworkBackgroundColor,
}}
margin={2} margin={2}
label={currentNetwork?.nickname} label={currentNetwork?.nickname}
src={currentNetwork?.rpcPrefs?.imageUrl} src={currentNetwork?.rpcPrefs?.imageUrl}
@ -411,6 +418,9 @@ export const AppHeader = ({ location }) => {
> >
<div> <div>
<PickerNetwork <PickerNetwork
avatarNetworkProps={{
backgroundColor: testNetworkBackgroundColor,
}}
label={currentNetwork?.nickname} label={currentNetwork?.nickname}
src={currentNetwork?.rpcPrefs?.imageUrl} src={currentNetwork?.rpcPrefs?.imageUrl}
onClick={(e) => { onClick={(e) => {

View File

@ -1,6 +1,7 @@
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import classnames from 'classnames'; import classnames from 'classnames';
import { useSelector } from 'react-redux';
import NftDefaultImage from '../../app/nft-default-image/nft-default-image'; import NftDefaultImage from '../../app/nft-default-image/nft-default-image';
import { import {
AvatarNetwork, AvatarNetwork,
@ -14,6 +15,7 @@ import {
JustifyContent, JustifyContent,
Size, Size,
} from '../../../helpers/constants/design-system'; } from '../../../helpers/constants/design-system';
import { getTestNetworkBackgroundColor } from '../../../selectors';
export const NftItem = ({ export const NftItem = ({
alt, alt,
@ -25,6 +27,7 @@ export const NftItem = ({
onClick, onClick,
clickable = false, clickable = false,
}) => { }) => {
const testNetworkBackgroundColor = useSelector(getTestNetworkBackgroundColor);
return ( return (
<Box <Box
className="nft-item__container" className="nft-item__container"
@ -42,6 +45,7 @@ export const NftItem = ({
badge={ badge={
<AvatarNetwork <AvatarNetwork
className="nft-item__network-badge" className="nft-item__network-badge"
backgroundColor={testNetworkBackgroundColor}
data-testid="nft-network-badge" data-testid="nft-network-badge"
size={Size.SM} size={Size.SM}
name={networkName} name={networkName}

View File

@ -1,28 +1,27 @@
import React from 'react'; import React from 'react';
import { render, fireEvent } from '@testing-library/react'; import configureStore from 'redux-mock-store';
import { fireEvent } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect'; import '@testing-library/jest-dom/extend-expect';
import mockState from '../../../../test/data/mock-state.json';
import { renderWithProvider } from '../../../../test/lib/render-helpers';
import { NftItem } from '.'; import { NftItem } from '.';
describe('NftItem component', () => { describe('NftItem component', () => {
const mockOnClick = jest.fn(); const store = configureStore()(mockState);
describe('render', () => {
afterEach(() => { const props = {
jest.clearAllMocks(); alt: 'Test Alt',
}); backgroundColor: 'red',
name: 'Test NFT',
src: 'test-src',
networkName: 'Test Network',
networkSrc: 'test-network-src',
tokenId: '1',
onClick: jest.fn(),
};
it('renders correctly with an image source', () => { it('renders correctly with an image source', () => {
const { getByTestId } = render( const { getByTestId } = renderWithProvider(<NftItem {...props} />, store);
<NftItem
alt="Test Alt"
backgroundColor="red"
name="Test NFT"
src="test-src"
networkName="Test Network"
networkSrc="test-network-src"
tokenId="1"
onClick={mockOnClick}
/>,
);
expect(getByTestId('nft-item')).toBeInTheDocument(); expect(getByTestId('nft-item')).toBeInTheDocument();
expect(getByTestId('nft-network-badge')).toBeInTheDocument(); expect(getByTestId('nft-network-badge')).toBeInTheDocument();
@ -31,40 +30,20 @@ describe('NftItem component', () => {
}); });
it('renders correctly with default image when no image source is provided', () => { it('renders correctly with default image when no image source is provided', () => {
const { getByTestId, queryByTestId } = render( const { getByTestId, queryByTestId } = renderWithProvider(
<NftItem <NftItem {...props} src="" />,
alt="Test Alt" store,
backgroundColor="red"
name="Test NFT"
src=""
networkName="Test Network"
networkSrc="test-network-src"
tokenId="1"
onClick={mockOnClick}
/>,
); );
expect(getByTestId('nft-item')).toBeInTheDocument();
expect(getByTestId('nft-network-badge')).toBeInTheDocument();
expect(queryByTestId('nft-image')).not.toBeInTheDocument(); expect(queryByTestId('nft-image')).not.toBeInTheDocument();
expect(getByTestId('nft-default-image')).toBeInTheDocument(); expect(getByTestId('nft-default-image')).toBeInTheDocument();
}); });
it('calls onClick when the NFT image is clicked', () => { it('calls onClick when the NFT image is clicked', () => {
const { getByTestId } = render( const { getByTestId } = renderWithProvider(<NftItem {...props} />, store);
<NftItem
alt="Test Alt"
backgroundColor="red"
name="Test NFT"
src="test-src"
networkName="Test Network"
networkSrc="test-network-src"
tokenId="1"
onClick={mockOnClick}
/>,
);
fireEvent.click(getByTestId('nft-image')); fireEvent.click(getByTestId('nft-image'));
expect(mockOnClick).toHaveBeenCalled(); expect(props.onClick).toHaveBeenCalled();
});
}); });
}); });

View File

@ -25,6 +25,7 @@ import {
getCurrentChainId, getCurrentChainId,
getCurrentNetwork, getCurrentNetwork,
getNativeCurrencyImage, getNativeCurrencyImage,
getTestNetworkBackgroundColor,
} from '../../../selectors'; } from '../../../selectors';
import Tooltip from '../../ui/tooltip'; import Tooltip from '../../ui/tooltip';
import { useI18nContext } from '../../../hooks/useI18nContext'; import { useI18nContext } from '../../../hooks/useI18nContext';
@ -50,6 +51,8 @@ export const TokenListItem = ({
// Used for badge icon // Used for badge icon
const currentNetwork = useSelector(getCurrentNetwork); const currentNetwork = useSelector(getCurrentNetwork);
const testNetworkBackgroundColor = useSelector(getTestNetworkBackgroundColor);
return ( return (
<Box <Box
className={classnames('multichain-token-list-item', className)} className={classnames('multichain-token-list-item', className)}
@ -86,6 +89,7 @@ export const TokenListItem = ({
size={Size.XS} size={Size.XS}
name={currentNetwork?.nickname} name={currentNetwork?.nickname}
src={currentNetwork?.rpcPrefs?.imageUrl} src={currentNetwork?.rpcPrefs?.imageUrl}
backgroundColor={testNetworkBackgroundColor}
borderColor={ borderColor={
primaryTokenImage primaryTokenImage
? BorderColor.borderMuted ? BorderColor.borderMuted

View File

@ -92,6 +92,7 @@ import {
getValueFromWeiHex, getValueFromWeiHex,
hexToDecimal, hexToDecimal,
} from '../../shared/modules/conversion.utils'; } from '../../shared/modules/conversion.utils';
import { BackgroundColor } from '../helpers/constants/design-system';
///: BEGIN:ONLY_INCLUDE_IN(snaps) ///: BEGIN:ONLY_INCLUDE_IN(snaps)
import { SNAPS_VIEW_ROUTE } from '../helpers/constants/routes'; import { SNAPS_VIEW_ROUTE } from '../helpers/constants/routes';
import { getPermissionSubjects } from './permissions'; import { getPermissionSubjects } from './permissions';
@ -603,6 +604,18 @@ export function getShowTestNetworks(state) {
return Boolean(showTestNetworks); return Boolean(showTestNetworks);
} }
export function getTestNetworkBackgroundColor(state) {
const currentNetwork = state.metamask.providerConfig.ticker;
switch (true) {
case currentNetwork?.includes(GOERLI_DISPLAY_NAME):
return BackgroundColor.goerli;
case currentNetwork?.includes(SEPOLIA_DISPLAY_NAME):
return BackgroundColor.sepolia;
default:
return undefined;
}
}
export function getDisabledRpcMethodPreferences(state) { export function getDisabledRpcMethodPreferences(state) {
return state.metamask.disabledRpcMethodPreferences; return state.metamask.disabledRpcMethodPreferences;
} }