-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8605106
commit e1b952e
Showing
11 changed files
with
267 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
ui/components/app/assets/nfts/nfts-items/collection-image.component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
|
||
import { useSelector } from 'react-redux'; | ||
|
||
import Box from '../../../../ui/box'; | ||
|
||
import { getIpfsGateway, getOpenSeaEnabled } from '../../../../../selectors'; | ||
import { getAssetImageURL } from '../../../../../helpers/utils/util'; | ||
|
||
export const CollectionImageComponent = ({ | ||
collectionImage, | ||
collectionName, | ||
}: { | ||
collectionImage: string; | ||
collectionName: string; | ||
}) => { | ||
const ipfsGateway = useSelector(getIpfsGateway); | ||
const openSeaEnabled = useSelector(getOpenSeaEnabled); | ||
const [nftImageURL, setAssetImageUrl] = useState<string>(''); | ||
|
||
useEffect(() => { | ||
const getAssetImageUrl = async () => { | ||
const assetImageUrl = await getAssetImageURL( | ||
collectionImage, | ||
ipfsGateway, | ||
); | ||
setAssetImageUrl(assetImageUrl); | ||
}; | ||
|
||
getAssetImageUrl(); | ||
}, []); | ||
|
||
const renderCollectionImage = () => { | ||
if (collectionImage?.startsWith('ipfs') && !ipfsGateway) { | ||
return ( | ||
<div className="nfts-items__collection-image-alt"> | ||
{collectionName?.[0]?.toUpperCase() ?? null} | ||
</div> | ||
); | ||
} | ||
if (!openSeaEnabled && !collectionImage?.startsWith('ipfs')) { | ||
return ( | ||
<div className="nfts-items__collection-image-alt"> | ||
{collectionName?.[0]?.toUpperCase() ?? null} | ||
</div> | ||
); | ||
} | ||
|
||
if (collectionImage) { | ||
return ( | ||
<img | ||
alt={collectionName} | ||
src={nftImageURL} | ||
className="nfts-items__collection-image" | ||
/> | ||
); | ||
} | ||
return ( | ||
<div className="nfts-items__collection-image-alt"> | ||
{collectionName?.[0]?.toUpperCase() ?? null} | ||
</div> | ||
); | ||
}; | ||
|
||
return <Box>{renderCollectionImage()}</Box>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.