Skip to content
This repository was archived by the owner on Jan 9, 2026. It is now read-only.

Commit 65b52ff

Browse files
authored
NFT marketplaces: make collection_url and instance_url optional (blockscout#2797)
Fixes blockscout#2614
1 parent e80d35a commit 65b52ff

File tree

5 files changed

+40
-13
lines changed

5 files changed

+40
-13
lines changed

configs/app/ui/views/nft.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,19 @@ import type { NftMarketplaceItem } from 'types/views/nft';
22

33
import { getEnvValue, parseEnvJson } from 'configs/app/utils';
44

5+
const marketplaces = (() => {
6+
const marketplaces = parseEnvJson<Array<NftMarketplaceItem>>(getEnvValue('NEXT_PUBLIC_VIEWS_NFT_MARKETPLACES')) || [];
7+
const isValid = marketplaces.every(marketplace => marketplace.collection_url || marketplace.instance_url);
8+
9+
if (!isValid) {
10+
return [];
11+
}
12+
13+
return marketplaces;
14+
})();
15+
516
const config = Object.freeze({
6-
marketplaces: parseEnvJson<Array<NftMarketplaceItem>>(getEnvValue('NEXT_PUBLIC_VIEWS_NFT_MARKETPLACES')) || [],
17+
marketplaces,
718
verifiedFetch: {
819
isEnabled: getEnvValue('NEXT_PUBLIC_HELIA_VERIFIED_FETCH_ENABLED') === 'false' ? false : true,
920
},

deploy/tools/envs-validator/schema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,8 +626,8 @@ const contractCodeIdeSchema: yup.ObjectSchema<ContractCodeIde> = yup
626626
const nftMarketplaceSchema: yup.ObjectSchema<NftMarketplaceItem> = yup
627627
.object({
628628
name: yup.string().required(),
629-
collection_url: yup.string().test(urlTest).required(),
630-
instance_url: yup.string().test(urlTest).required(),
629+
collection_url: yup.string().test(urlTest),
630+
instance_url: yup.string().test(urlTest),
631631
logo_url: yup.string().test(urlTest).required(),
632632
});
633633

docs/ENVS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,8 @@ Settings for meta tags, OG tags and SEO
305305
| Variable | Type| Description | Compulsoriness | Default value | Example value |
306306
| --- | --- | --- | --- | --- | --- |
307307
| name | `string` | Displayed name of the marketplace | Required | - | `OpenSea` |
308-
| collection_url | `string` | URL template for NFT collection | Required | - | `https://opensea.io/assets/ethereum/{hash}` |
309-
| instance_url | `string` | URL template for NFT instance | Required | - | `https://opensea.io/assets/ethereum/{hash}/{id}` |
308+
| collection_url | `string` | URL template for NFT collection | - | - | `https://opensea.io/assets/ethereum/{hash}` |
309+
| instance_url | `string` | URL template for NFT instance | - | - | `https://opensea.io/assets/ethereum/{hash}/{id}` |
310310
| logo_url | `string` | URL of marketplace logo | Required | - | `https://opensea.io/static/images/logos/opensea-logo.svg` |
311311

312312
*Note* URL templates should contain placeholders of NFT hash (`{hash}`) and NFT id (`{id}`). This placeholders will be substituted with particular values for every collection or instance.

types/views/nft.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export interface NftMarketplaceItem {
22
name: string;
3-
collection_url: string;
4-
instance_url: string;
3+
collection_url?: string;
4+
instance_url?: string;
55
logo_url: string;
66
}

ui/token/TokenNftMarketplaces.tsx

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,26 @@ const TokenNftMarketplaces = ({ hash, id, isLoading, appActionData, source }: Pr
2424
return null;
2525
}
2626

27+
const items = config.UI.views.nft.marketplaces
28+
.map((item) => {
29+
const hrefTemplate = id ? item.instance_url : item.collection_url;
30+
if (!hrefTemplate) {
31+
return null;
32+
}
33+
const href = hrefTemplate.replace('{id}', id || '').replace('{hash}', hash || '');
34+
35+
return {
36+
href,
37+
logo_url: item.logo_url,
38+
name: item.name,
39+
};
40+
})
41+
.filter(Boolean);
42+
43+
if (items.length === 0) {
44+
return null;
45+
}
46+
2747
return (
2848
<>
2949
<DetailedInfo.ItemLabel
@@ -36,14 +56,10 @@ const TokenNftMarketplaces = ({ hash, id, isLoading, appActionData, source }: Pr
3656
py={ appActionData ? '1px' : '6px' }
3757
>
3858
<Skeleton loading={ isLoading } display="flex" columnGap={ 3 } flexWrap="wrap" alignItems="center">
39-
{ config.UI.views.nft.marketplaces.map((item) => {
40-
41-
const hrefTemplate = id ? item.instance_url : item.collection_url;
42-
const href = hrefTemplate.replace('{id}', id || '').replace('{hash}', hash || '');
43-
59+
{ items.map((item) => {
4460
return (
4561
<Tooltip content={ `View on ${ item.name }` } key={ item.name }>
46-
<Link href={ href } target="_blank">
62+
<Link href={ item.href } target="_blank">
4763
<Image
4864
src={ item.logo_url }
4965
alt={ `${ item.name } marketplace logo` }

0 commit comments

Comments
 (0)