Skip to content

Commit

Permalink
removed prop ipfsEnabled and used with selector
Browse files Browse the repository at this point in the history
  • Loading branch information
NidhiKJha committed Jul 31, 2023
1 parent 41a5b4c commit c15d839
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@ exports[`NFT Default Image should match snapshot with all provided props 1`] = `
class="mm-box nft-default mm-box--display-flex mm-box--rounded-lg"
data-testid="nft-default-image"
tabindex="0"
>
<button
class="mm-box mm-text mm-button-base mm-button-base--block nft-default__button mm-button-link mm-button-link--size-auto mm-text--body-md-medium mm-box--padding-right-0 mm-box--padding-left-0 mm-box--display-inline-flex mm-box--justify-content-center mm-box--align-items-center mm-box--color-primary-default mm-box--background-color-transparent"
>
Show
</button>
</div>
/>
</div>
`;

Expand All @@ -22,13 +16,7 @@ exports[`NFT Default Image should match snapshot with missing clickable prop 1`]
class="mm-box nft-default mm-box--display-flex mm-box--rounded-lg"
data-testid="nft-default-image"
tabindex="0"
>
<button
class="mm-box mm-text mm-button-base mm-button-base--block nft-default__button mm-button-link mm-button-link--size-auto mm-text--body-md-medium mm-box--padding-right-0 mm-box--padding-left-0 mm-box--display-inline-flex mm-box--justify-content-center mm-box--align-items-center mm-box--color-primary-default mm-box--background-color-transparent"
>
Show
</button>
</div>
/>
</div>
`;

Expand All @@ -38,12 +26,6 @@ exports[`NFT Default Image should render with no props 1`] = `
class="mm-box nft-default mm-box--display-flex mm-box--rounded-lg"
data-testid="nft-default-image"
tabindex="0"
>
<button
class="mm-box mm-text mm-button-base mm-button-base--block nft-default__button mm-button-link mm-button-link--size-auto mm-text--body-md-medium mm-box--padding-right-0 mm-box--padding-left-0 mm-box--display-inline-flex mm-box--justify-content-center mm-box--align-items-center mm-box--color-primary-default mm-box--background-color-transparent"
>
Show
</button>
</div>
/>
</div>
`;
14 changes: 4 additions & 10 deletions ui/components/app/nft-default-image/nft-default-image.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { useDispatch } from 'react-redux';
import { useDispatch, useSelector } from 'react-redux';
import {
Display,
AlignItems,
Expand All @@ -11,14 +11,12 @@ import {
import { useI18nContext } from '../../../hooks/useI18nContext';
import { ButtonLink, Box } from '../../component-library';
import { showIpfsModal } from '../../../store/actions';
import { getIpfsGateway } from '../../../selectors';

export default function NftDefaultImage({
className,
isIpfsEnabled,
clickable,
}) {
export default function NftDefaultImage({ className, clickable }) {
const t = useI18nContext();
const dispatch = useDispatch();
const isIpfsEnabled = useSelector(getIpfsGateway);

return (
<Box
Expand Down Expand Up @@ -53,10 +51,6 @@ NftDefaultImage.propTypes = {
* Controls the css class for the cursor hover
*/
clickable: PropTypes.bool,
/**
* Check if ipfs is Enabled or not based on Ipfs Value
*/
isIpfsEnabled: PropTypes.bool,
/**
* An additional className to apply to the NFT default image
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@ export default {
clickable: {
control: 'boolean',
},
isIpfsEnabled: {
control: 'boolean',
},
},
args: {
clickable: true,
isIpfsEnabled: false,
},
};

Expand Down
1 change: 0 additions & 1 deletion ui/components/app/nft-details/nft-details.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ export default function NftDetails({ nft }) {
tokenId={tokenId}
networkName={currentChain.nickname}
networkSrc={currentChain.rpcPrefs?.imageUrl}
isIpfsEnabled={Boolean(ipfsGateway)}
/>
</Box>
<Box
Expand Down
1 change: 0 additions & 1 deletion ui/components/app/nfts-items/nfts-items.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ export default function NftsItems({
networkName={currentChain.nickname}
networkSrc={currentChain.rpcPrefs?.imageUrl}
onClick={handleImageClick}
isIpfsEnabled={Boolean(ipfsGateway)}
clickable
/>
</Box>
Expand Down
9 changes: 5 additions & 4 deletions ui/components/multichain/nft-item/nft-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ import {
Display,
JustifyContent,
} from '../../../helpers/constants/design-system';
import { getTestNetworkBackgroundColor } from '../../../selectors';
import {
getIpfsGateway,
getTestNetworkBackgroundColor,
} from '../../../selectors';

export const NftItem = ({
alt,
Expand All @@ -25,10 +28,10 @@ export const NftItem = ({
networkSrc,
tokenId,
onClick,
isIpfsEnabled,
clickable,
}) => {
const testNetworkBackgroundColor = useSelector(getTestNetworkBackgroundColor);
const isIpfsEnabled = useSelector(getIpfsGateway);
return (
<Box
className="nft-item__container"
Expand Down Expand Up @@ -76,7 +79,6 @@ export const NftItem = ({
name={name}
tokenId={tokenId}
clickable={clickable}
isIpfsEnabled={isIpfsEnabled}
/>
)}
</BadgeWrapper>
Expand All @@ -93,5 +95,4 @@ NftItem.propTypes = {
tokenId: PropTypes.string.isRequired,
onClick: PropTypes.func,
clickable: PropTypes.bool,
isIpfsEnabled: PropTypes.bool,
};
21 changes: 16 additions & 5 deletions ui/components/multichain/nft-item/nft-item.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
import React from 'react';
import configureStore from 'redux-mock-store';
import { fireEvent } from '@testing-library/react';
import configureStore from '../../../store/store';
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 '.';

const store = configureStore({
metamask: {
...mockState.metamask,
},
});

const noIpsStore = configureStore({
metamask: {
...mockState.metamask,
ipfsGateway: '',
},
});

describe('NftItem component', () => {
const store = configureStore()(mockState);
jest.mock('../../../store/actions.ts', () => ({
getTokenStandardAndDetails: jest.fn().mockResolvedValue(),
}));
Expand All @@ -21,7 +33,6 @@ describe('NftItem component', () => {
networkSrc: 'test-network-src',
tokenId: '1',
onClick: jest.fn(),
isIpfsEnabled: true,
};

it('renders correctly with an image source', () => {
Expand All @@ -35,8 +46,8 @@ describe('NftItem component', () => {

it('renders correctly with default image when no image source is provided', () => {
const { getByTestId, queryByTestId } = renderWithProvider(
<NftItem {...props} isIpfsEnabled={false} />,
store,
<NftItem {...props} />,
noIpsStore,
);

expect(queryByTestId('nft-image')).not.toBeInTheDocument();
Expand Down

1 comment on commit c15d839

@Ameralameri
Copy link

Choose a reason for hiding this comment

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

How to working

Please sign in to comment.