@@ -19,6 +19,7 @@ import {
19
19
Text ,
20
20
} from "tw-components" ;
21
21
import { NFTMediaWithEmptyState } from "tw-components/nft-media" ;
22
+ import { useChainSlug } from "hooks/chains/chainSlug" ;
22
23
23
24
const dummyMetadata : ( idx : number ) => NFT = ( idx ) => ( {
24
25
id : BigInt ( idx || 0 ) ,
@@ -34,6 +35,10 @@ const dummyMetadata: (idx: number) => NFT = (idx) => ({
34
35
supply : 1n ,
35
36
} ) ;
36
37
38
+ function isOnlyNumbers ( str : string ) {
39
+ return / ^ \d + $ / . test ( str ) ;
40
+ }
41
+
37
42
interface NFTCardsProps {
38
43
nfts : NFT [ ] | WalletNFT [ ] ;
39
44
trackingCategory : TrackedLinkProps [ "category" ] ;
@@ -58,50 +63,60 @@ export const NFTCards: React.FC<NFTCardsProps> = ({
58
63
} ) . map ( ( _ , idx ) => dummyMetadata ( idx ) ) ;
59
64
} , [ nfts . length , isMobile , allNfts ] ) ;
60
65
66
+ const chainSlug = useChainSlug ( chainId || 1 ) ;
67
+
61
68
return (
62
69
< SimpleGrid
63
70
gap = { { base : 3 , md : 6 } }
64
71
columns = { allNfts ? { base : 2 , md : 4 } : { base : 2 , md : 3 } }
65
72
>
66
- { ( isLoading ? dummyData : nfts ) . map ( ( token ) => (
67
- < GridItem
68
- key = { `${ chainId } -${ ( token as WalletNFT ) ?. contractAddress || contractAddress
69
- } -${ ( token as WalletNFT ) . tokenId || token . metadata . id } }`}
70
- as = { TrackedLink }
71
- category = { trackingCategory }
72
- href = { `/${ chainId } /${ ( token as WalletNFT ) ?. contractAddress || contractAddress
73
- } /nfts/${ ( token as WalletNFT ) . tokenId || token . metadata . id } `}
74
- _hover = { { opacity : 0.75 , textDecoration : "none" } }
75
- >
76
- < Card p = { 0 } h = "full" >
77
- < AspectRatio w = "100%" ratio = { 1 } overflow = "hidden" rounded = "xl" >
78
- < Skeleton isLoaded = { ! isLoading } >
79
- < NFTMediaWithEmptyState
80
- // @ts -expect-error types are not up to date
81
- metadata = { token . metadata }
82
- requireInteraction
83
- width = "100%"
84
- height = "100%"
85
- />
86
- </ Skeleton >
87
- </ AspectRatio >
88
- < Flex p = { 4 } pb = { 3 } gap = { 3 } direction = "column" >
89
- < Skeleton w = { ! isLoading ? "100%" : "50%" } isLoaded = { ! isLoading } >
90
- < Heading size = "label.md" > { token . metadata . name } </ Heading >
91
- </ Skeleton >
92
- < SkeletonText isLoaded = { ! isLoading } >
93
- < Text noOfLines = { 3 } >
94
- { token . metadata . description ? (
95
- token . metadata . description
96
- ) : (
97
- < i > No description</ i >
98
- ) }
99
- </ Text >
100
- </ SkeletonText >
101
- </ Flex >
102
- </ Card >
103
- </ GridItem >
104
- ) ) }
73
+ { ( isLoading ? dummyData : nfts ) . map ( ( token ) => {
74
+ const tokenId = ( token as WalletNFT ) ?. tokenId || ( token as NFT ) . id ;
75
+ const ctrAddress =
76
+ ( token as WalletNFT ) ?. contractAddress || contractAddress ;
77
+
78
+ if ( ! tokenId || ! isOnlyNumbers ( tokenId . toString ( ) ) ) {
79
+ return null ;
80
+ }
81
+
82
+ return (
83
+ < GridItem
84
+ key = { `${ chainId } -${ ctrAddress } -${ tokenId } ` }
85
+ as = { TrackedLink }
86
+ category = { trackingCategory }
87
+ href = { `/${ chainSlug } /${ ctrAddress } /nfts/${ tokenId . toString ( ) } ` }
88
+ _hover = { { opacity : 0.75 , textDecoration : "none" } }
89
+ >
90
+ < Card p = { 0 } h = "full" >
91
+ < AspectRatio w = "100%" ratio = { 1 } overflow = "hidden" rounded = "xl" >
92
+ < Skeleton isLoaded = { ! isLoading } >
93
+ < NFTMediaWithEmptyState
94
+ // @ts -expect-error types are not up to date
95
+ metadata = { token . metadata }
96
+ requireInteraction
97
+ width = "100%"
98
+ height = "100%"
99
+ />
100
+ </ Skeleton >
101
+ </ AspectRatio >
102
+ < Flex p = { 4 } pb = { 3 } gap = { 3 } direction = "column" >
103
+ < Skeleton w = { ! isLoading ? "100%" : "50%" } isLoaded = { ! isLoading } >
104
+ < Heading size = "label.md" > { token . metadata . name } </ Heading >
105
+ </ Skeleton >
106
+ < SkeletonText isLoaded = { ! isLoading } >
107
+ < Text noOfLines = { 3 } >
108
+ { token . metadata . description ? (
109
+ token . metadata . description
110
+ ) : (
111
+ < i > No description</ i >
112
+ ) }
113
+ </ Text >
114
+ </ SkeletonText >
115
+ </ Flex >
116
+ </ Card >
117
+ </ GridItem >
118
+ ) ;
119
+ } ) }
105
120
</ SimpleGrid >
106
121
) ;
107
122
} ;
0 commit comments