Commit 65b52ff2 authored by tom goriunov's avatar tom goriunov Committed by GitHub

NFT marketplaces: make `collection_url` and `instance_url ` optional (#2797)

Fixes #2614
parent e80d35ab
...@@ -2,8 +2,19 @@ import type { NftMarketplaceItem } from 'types/views/nft'; ...@@ -2,8 +2,19 @@ import type { NftMarketplaceItem } from 'types/views/nft';
import { getEnvValue, parseEnvJson } from 'configs/app/utils'; import { getEnvValue, parseEnvJson } from 'configs/app/utils';
const marketplaces = (() => {
const marketplaces = parseEnvJson<Array<NftMarketplaceItem>>(getEnvValue('NEXT_PUBLIC_VIEWS_NFT_MARKETPLACES')) || [];
const isValid = marketplaces.every(marketplace => marketplace.collection_url || marketplace.instance_url);
if (!isValid) {
return [];
}
return marketplaces;
})();
const config = Object.freeze({ const config = Object.freeze({
marketplaces: parseEnvJson<Array<NftMarketplaceItem>>(getEnvValue('NEXT_PUBLIC_VIEWS_NFT_MARKETPLACES')) || [], marketplaces,
verifiedFetch: { verifiedFetch: {
isEnabled: getEnvValue('NEXT_PUBLIC_HELIA_VERIFIED_FETCH_ENABLED') === 'false' ? false : true, isEnabled: getEnvValue('NEXT_PUBLIC_HELIA_VERIFIED_FETCH_ENABLED') === 'false' ? false : true,
}, },
......
...@@ -626,8 +626,8 @@ const contractCodeIdeSchema: yup.ObjectSchema<ContractCodeIde> = yup ...@@ -626,8 +626,8 @@ const contractCodeIdeSchema: yup.ObjectSchema<ContractCodeIde> = yup
const nftMarketplaceSchema: yup.ObjectSchema<NftMarketplaceItem> = yup const nftMarketplaceSchema: yup.ObjectSchema<NftMarketplaceItem> = yup
.object({ .object({
name: yup.string().required(), name: yup.string().required(),
collection_url: yup.string().test(urlTest).required(), collection_url: yup.string().test(urlTest),
instance_url: yup.string().test(urlTest).required(), instance_url: yup.string().test(urlTest),
logo_url: yup.string().test(urlTest).required(), logo_url: yup.string().test(urlTest).required(),
}); });
......
...@@ -305,8 +305,8 @@ Settings for meta tags, OG tags and SEO ...@@ -305,8 +305,8 @@ Settings for meta tags, OG tags and SEO
| Variable | Type| Description | Compulsoriness | Default value | Example value | | Variable | Type| Description | Compulsoriness | Default value | Example value |
| --- | --- | --- | --- | --- | --- | | --- | --- | --- | --- | --- | --- |
| name | `string` | Displayed name of the marketplace | Required | - | `OpenSea` | | name | `string` | Displayed name of the marketplace | Required | - | `OpenSea` |
| collection_url | `string` | URL template for NFT collection | Required | - | `https://opensea.io/assets/ethereum/{hash}` | | collection_url | `string` | URL template for NFT collection | - | - | `https://opensea.io/assets/ethereum/{hash}` |
| instance_url | `string` | URL template for NFT instance | Required | - | `https://opensea.io/assets/ethereum/{hash}/{id}` | | instance_url | `string` | URL template for NFT instance | - | - | `https://opensea.io/assets/ethereum/{hash}/{id}` |
| logo_url | `string` | URL of marketplace logo | Required | - | `https://opensea.io/static/images/logos/opensea-logo.svg` | | logo_url | `string` | URL of marketplace logo | Required | - | `https://opensea.io/static/images/logos/opensea-logo.svg` |
*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. *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.
......
export interface NftMarketplaceItem { export interface NftMarketplaceItem {
name: string; name: string;
collection_url: string; collection_url?: string;
instance_url: string; instance_url?: string;
logo_url: string; logo_url: string;
} }
...@@ -24,6 +24,26 @@ const TokenNftMarketplaces = ({ hash, id, isLoading, appActionData, source }: Pr ...@@ -24,6 +24,26 @@ const TokenNftMarketplaces = ({ hash, id, isLoading, appActionData, source }: Pr
return null; return null;
} }
const items = config.UI.views.nft.marketplaces
.map((item) => {
const hrefTemplate = id ? item.instance_url : item.collection_url;
if (!hrefTemplate) {
return null;
}
const href = hrefTemplate.replace('{id}', id || '').replace('{hash}', hash || '');
return {
href,
logo_url: item.logo_url,
name: item.name,
};
})
.filter(Boolean);
if (items.length === 0) {
return null;
}
return ( return (
<> <>
<DetailedInfo.ItemLabel <DetailedInfo.ItemLabel
...@@ -36,14 +56,10 @@ const TokenNftMarketplaces = ({ hash, id, isLoading, appActionData, source }: Pr ...@@ -36,14 +56,10 @@ const TokenNftMarketplaces = ({ hash, id, isLoading, appActionData, source }: Pr
py={ appActionData ? '1px' : '6px' } py={ appActionData ? '1px' : '6px' }
> >
<Skeleton loading={ isLoading } display="flex" columnGap={ 3 } flexWrap="wrap" alignItems="center"> <Skeleton loading={ isLoading } display="flex" columnGap={ 3 } flexWrap="wrap" alignItems="center">
{ config.UI.views.nft.marketplaces.map((item) => { { items.map((item) => {
const hrefTemplate = id ? item.instance_url : item.collection_url;
const href = hrefTemplate.replace('{id}', id || '').replace('{hash}', hash || '');
return ( return (
<Tooltip content={ `View on ${ item.name }` } key={ item.name }> <Tooltip content={ `View on ${ item.name }` } key={ item.name }>
<Link href={ href } target="_blank"> <Link href={ item.href } target="_blank">
<Image <Image
src={ item.logo_url } src={ item.logo_url }
alt={ `${ item.name } marketplace logo` } alt={ `${ item.name } marketplace logo` }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment