mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Add alt text for NFT images (#17284)
This commit is contained in:
parent
8a6bf4d1c9
commit
47f6d46bb3
@ -20,6 +20,7 @@ import {
|
|||||||
} from '../../../helpers/constants/design-system';
|
} from '../../../helpers/constants/design-system';
|
||||||
import { useI18nContext } from '../../../hooks/useI18nContext';
|
import { useI18nContext } from '../../../hooks/useI18nContext';
|
||||||
import { getAssetImageURL, shortenAddress } from '../../../helpers/utils/util';
|
import { getAssetImageURL, shortenAddress } from '../../../helpers/utils/util';
|
||||||
|
import { getCollectibleImageAlt } from '../../../helpers/utils/collectibles';
|
||||||
import {
|
import {
|
||||||
getCurrentChainId,
|
getCurrentChainId,
|
||||||
getIpfsGateway,
|
getIpfsGateway,
|
||||||
@ -82,6 +83,7 @@ export default function CollectibleDetails({ collectible }) {
|
|||||||
imageOriginal ?? image,
|
imageOriginal ?? image,
|
||||||
ipfsGateway,
|
ipfsGateway,
|
||||||
);
|
);
|
||||||
|
const collectibleImageAlt = getCollectibleImageAlt(collectible);
|
||||||
const isDataURI = collectibleImageURL.startsWith('data:');
|
const isDataURI = collectibleImageURL.startsWith('data:');
|
||||||
|
|
||||||
const onRemove = () => {
|
const onRemove = () => {
|
||||||
@ -178,6 +180,7 @@ export default function CollectibleDetails({ collectible }) {
|
|||||||
<img
|
<img
|
||||||
className="collectible-details__image"
|
className="collectible-details__image"
|
||||||
src={collectibleImageURL}
|
src={collectibleImageURL}
|
||||||
|
alt={collectibleImageAlt}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<CollectibleDefaultImage name={name} tokenId={tokenId} />
|
<CollectibleDefaultImage name={name} tokenId={tokenId} />
|
||||||
|
@ -25,6 +25,7 @@ import {
|
|||||||
} from '../../../selectors';
|
} from '../../../selectors';
|
||||||
import { ASSET_ROUTE } from '../../../helpers/constants/routes';
|
import { ASSET_ROUTE } from '../../../helpers/constants/routes';
|
||||||
import { getAssetImageURL } from '../../../helpers/utils/util';
|
import { getAssetImageURL } from '../../../helpers/utils/util';
|
||||||
|
import { getCollectibleImageAlt } from '../../../helpers/utils/collectibles';
|
||||||
import { updateCollectibleDropDownState } from '../../../store/actions';
|
import { updateCollectibleDropDownState } from '../../../store/actions';
|
||||||
import { usePrevious } from '../../../hooks/usePrevious';
|
import { usePrevious } from '../../../hooks/usePrevious';
|
||||||
import { getCollectiblesDropdownState } from '../../../ducks/metamask/metamask';
|
import { getCollectiblesDropdownState } from '../../../ducks/metamask/metamask';
|
||||||
@ -90,6 +91,7 @@ export default function CollectiblesItems({
|
|||||||
if (collectionImage) {
|
if (collectionImage) {
|
||||||
return (
|
return (
|
||||||
<img
|
<img
|
||||||
|
alt={collectionName}
|
||||||
src={collectionImage}
|
src={collectionImage}
|
||||||
className="collectibles-items__collection-image"
|
className="collectibles-items__collection-image"
|
||||||
/>
|
/>
|
||||||
@ -175,6 +177,7 @@ export default function CollectiblesItems({
|
|||||||
const { image, address, tokenId, backgroundColor, name } =
|
const { image, address, tokenId, backgroundColor, name } =
|
||||||
collectible;
|
collectible;
|
||||||
const collectibleImage = getAssetImageURL(image, ipfsGateway);
|
const collectibleImage = getAssetImageURL(image, ipfsGateway);
|
||||||
|
const collectibleImageAlt = getCollectibleImageAlt(collectible);
|
||||||
const handleImageClick = () =>
|
const handleImageClick = () =>
|
||||||
history.push(`${ASSET_ROUTE}/${address}/${tokenId}`);
|
history.push(`${ASSET_ROUTE}/${address}/${tokenId}`);
|
||||||
|
|
||||||
@ -200,6 +203,7 @@ export default function CollectiblesItems({
|
|||||||
<img
|
<img
|
||||||
className="collectibles-items__item-image"
|
className="collectibles-items__item-image"
|
||||||
src={collectibleImage}
|
src={collectibleImage}
|
||||||
|
alt={collectibleImageAlt}
|
||||||
/>
|
/>
|
||||||
</button>
|
</button>
|
||||||
) : (
|
) : (
|
||||||
|
3
ui/helpers/utils/collectibles.js
Normal file
3
ui/helpers/utils/collectibles.js
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
export const getCollectibleImageAlt = ({ name, tokenId, description }) => {
|
||||||
|
return description ?? `${name} ${tokenId}`;
|
||||||
|
};
|
31
ui/helpers/utils/collectibles.test.js
Normal file
31
ui/helpers/utils/collectibles.test.js
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
import { getCollectibleImageAlt } from './collectibles';
|
||||||
|
|
||||||
|
describe('Collectibles Utils', () => {
|
||||||
|
describe('getCollectibleImageAlt', () => {
|
||||||
|
it('returns the description attribute when it is available', () => {
|
||||||
|
expect(
|
||||||
|
getCollectibleImageAlt({
|
||||||
|
name: 'Cool NFT',
|
||||||
|
tokenId: '555',
|
||||||
|
description: 'This is a really cool NFT',
|
||||||
|
}),
|
||||||
|
).toBe('This is a really cool NFT');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns the formatted name and tokenId attributes when a description is not present', () => {
|
||||||
|
expect(
|
||||||
|
getCollectibleImageAlt({
|
||||||
|
name: 'Cool NFT',
|
||||||
|
tokenId: '555',
|
||||||
|
description: null,
|
||||||
|
}),
|
||||||
|
).toBe('Cool NFT 555');
|
||||||
|
expect(
|
||||||
|
getCollectibleImageAlt({
|
||||||
|
name: 'Cool NFT',
|
||||||
|
tokenId: '555',
|
||||||
|
}),
|
||||||
|
).toBe('Cool NFT 555');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user