mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
NFT image & faulty metadata fixes (#1779)
* safeguard against faults in metadata.tags * properly handle image strings in tokenURI * keep image ratios * render test for faulty tags * tweak fallback in popover
This commit is contained in:
parent
ee4e5c3b4d
commit
482af1be0c
@ -82,10 +82,13 @@ export function generateNftCreateData(
|
||||
|
||||
export function decodeTokenURI(tokenURI: string): NftMetadata {
|
||||
if (!tokenURI) return undefined
|
||||
|
||||
try {
|
||||
const nftMeta = JSON.parse(
|
||||
Buffer.from(tokenURI.replace(tokenUriPrefix, ''), 'base64').toString()
|
||||
) as NftMetadata
|
||||
const nftMeta = tokenURI.includes('data:application/json')
|
||||
? (JSON.parse(
|
||||
Buffer.from(tokenURI.replace(tokenUriPrefix, ''), 'base64').toString()
|
||||
) as NftMetadata)
|
||||
: ({ image: tokenURI } as NftMetadata)
|
||||
|
||||
return nftMeta
|
||||
} catch (error) {
|
||||
|
@ -69,11 +69,13 @@ export default function AssetList({
|
||||
|
||||
const styleClasses = `${styles.assetList} ${className || ''}`
|
||||
|
||||
return assetsWithPrices && !loading ? (
|
||||
return loading ? (
|
||||
<LoaderArea />
|
||||
) : (
|
||||
<>
|
||||
<div className={styleClasses}>
|
||||
{assetsWithPrices.length > 0 ? (
|
||||
assetsWithPrices.map((assetWithPrice) => (
|
||||
{assetsWithPrices?.length > 0 ? (
|
||||
assetsWithPrices?.map((assetWithPrice) => (
|
||||
<AssetTeaser
|
||||
asset={assetWithPrice}
|
||||
key={assetWithPrice.id}
|
||||
@ -95,7 +97,5 @@ export default function AssetList({
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
) : (
|
||||
<LoaderArea />
|
||||
)
|
||||
}
|
||||
|
@ -24,4 +24,9 @@ describe('Tags', () => {
|
||||
it('renders WithoutLinks', () => {
|
||||
render(<Tags {...argsWithoutLinks} />)
|
||||
})
|
||||
|
||||
it('renders with faulty tags', () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
render(<Tags items={'tags' as any} />)
|
||||
})
|
||||
})
|
||||
|
@ -30,6 +30,9 @@ export default function Tags({
|
||||
className,
|
||||
noLinks
|
||||
}: TagsProps): ReactElement {
|
||||
// safeguard against faults in the metadata
|
||||
if (!(items instanceof Array)) return null
|
||||
|
||||
max = max || items.length
|
||||
const remainder = items.length - max
|
||||
// filter out empty array items, and restrict to `max`
|
||||
|
@ -7,7 +7,7 @@
|
||||
.wrapper img {
|
||||
margin: 0;
|
||||
width: 128px;
|
||||
height: 128px;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.info {
|
||||
|
@ -14,11 +14,13 @@ const openSeaTestNetworks = [4]
|
||||
|
||||
export default function NftTooltip({
|
||||
nft,
|
||||
nftImage,
|
||||
address,
|
||||
chainId,
|
||||
isBlockscoutExplorer
|
||||
}: {
|
||||
nft: NftMetadata
|
||||
nftImage: string
|
||||
address: string
|
||||
chainId: number
|
||||
isBlockscoutExplorer: boolean
|
||||
@ -39,7 +41,7 @@ export default function NftTooltip({
|
||||
|
||||
return (
|
||||
<div className={styles.wrapper}>
|
||||
{nft && <img src={nft.image_data || nft.image} alt={nft?.name} />}
|
||||
{nftImage && <img src={nftImage} alt={nft?.name} />}
|
||||
<div className={styles.info}>
|
||||
{nft && <h5>{nft.name}</h5>}
|
||||
{address && (
|
||||
|
@ -4,14 +4,19 @@
|
||||
border-right: 1px solid var(--border-color);
|
||||
width: calc(var(--spacer) * 2);
|
||||
height: calc(var(--spacer) * 2);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.nftImage img,
|
||||
.nftImage > svg:first-of-type {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.nftImage img {
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.nftImage > svg:first-of-type {
|
||||
transform: scale(0.7);
|
||||
}
|
||||
|
@ -48,6 +48,7 @@ export default function Nft({
|
||||
content={
|
||||
<NftTooltip
|
||||
nft={nftMetadata}
|
||||
nftImage={nftImage}
|
||||
address={asset?.nftAddress}
|
||||
chainId={asset?.chainId}
|
||||
isBlockscoutExplorer={isBlockscoutExplorer}
|
||||
|
@ -31,11 +31,17 @@ export default function RelatedAssets(): ReactElement {
|
||||
setIsLoading(true)
|
||||
|
||||
try {
|
||||
const tagQuery = generateBaseQuery(
|
||||
generateQuery(chainIds, asset.nftAddress, 4, asset.metadata.tags)
|
||||
)
|
||||
const tagResults = (await queryMetadata(tagQuery, newCancelToken()))
|
||||
?.results
|
||||
let tagResults: Asset[] = []
|
||||
|
||||
// safeguard against faults in the metadata
|
||||
if (asset.metadata.tags instanceof Array) {
|
||||
const tagQuery = generateBaseQuery(
|
||||
generateQuery(chainIds, asset.nftAddress, 4, asset.metadata.tags)
|
||||
)
|
||||
|
||||
tagResults = (await queryMetadata(tagQuery, newCancelToken()))
|
||||
?.results
|
||||
}
|
||||
|
||||
if (tagResults.length === 4) {
|
||||
setRelatedAssets(tagResults)
|
||||
|
Loading…
Reference in New Issue
Block a user