Skip to content

Commit

Permalink
fix: don't break page on missing mediaUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-haynes committed Mar 8, 2022
1 parent 4127d5d commit 8d704c2
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions packages/frontend/src/components/wallet/NFTBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,25 +154,27 @@ const NFTBox = ({ tokenDetails }) => {
<div className='tokens'>
{ownedTokensMetadata.map(({ token_id, metadata: { mediaUrl, title } }, index) => {
const videoProps = index === 0 ? { autoPlay: true } : {};
const isVideo = !!mediaUrl && mediaUrl.match(/\.webm$/i);
return (
<div className='nft' key={token_id}
onClick={() => dispatch(redirectTo(`/nft-detail/${contractName}/${token_id}`))}>
{
mediaUrl.match(/\.webm$/i)
? <video muted={true} loop controls { ...videoProps }>
{isVideo && (
<video muted={true} loop controls { ...videoProps }>
<source src={mediaUrl} type="video/webm" onError={(e) => {
e.target.onerror = null;
e.target.parentElement.setAttribute('poster', FailedToLoad);
}}/>
</video>
: <img src={mediaUrl}
alt='NFT'
onError={(e) => {
e.target.onerror = null;
e.target.src = FailedToLoad;
}}
/>
}
)}
{!isVideo && (
<img src={mediaUrl}
alt='NFT'
onError={(e) => {
e.target.onerror = null;
e.target.src = FailedToLoad;
}}
/>
)}
<b className='title'>{title}</b>
</div>
);
Expand Down

0 comments on commit 8d704c2

Please sign in to comment.