@@ -2,11 +2,12 @@ import { useEffect, useState } from 'react'
22import { TrustedBy } from '../components/trustedByLogos'
33import { NftUpCta } from '../components/nftUpCta'
44import fs from 'fs'
5- import { calculateStats } from '../lib/statsUtils'
5+ import { calculateStats , calculateMarketStats } from '../lib/statsUtils'
66import Img from '../components/cloudflareImage'
77import { API } from '../lib/api'
88import Loading from '../components/loading'
99import bytes from 'bytes'
10+ import { NFT_PORT_ENDPOINT , NFT_PORT_API_KEY } from '../lib/constants'
1011
1112/**
1213 *
@@ -47,6 +48,8 @@ export function getStaticProps() {
4748export default function Stats ( { logos } ) {
4849 /** @type [any, any] */
4950 const [ stats , setStats ] = useState ( { } )
51+ /** @type [any, any] */
52+ const [ marketStats , setMarketStats ] = useState ( { } )
5053 const [ statsLoading , setStatsLoading ] = useState ( false )
5154
5255 useEffect ( ( ) => {
@@ -55,6 +58,29 @@ export default function Stats({ logos }) {
5558
5659 async function fetchStats ( ) {
5760 setStatsLoading ( true )
61+ try {
62+ const nftPortStats = await fetch ( NFT_PORT_ENDPOINT , {
63+ method : 'GET' ,
64+ headers : {
65+ 'Content-Type' : 'application/json' ,
66+ Authorization : NFT_PORT_API_KEY ,
67+ } ,
68+ redirect : 'follow' ,
69+ } )
70+ const data = await nftPortStats . json ( )
71+ setMarketStats ( await calculateMarketStats ( data . report ) )
72+ } catch ( e ) {
73+ const fakeData = {
74+ totalNfts : 91100000 ,
75+ totalMarketValueUSD : 26800000000 ,
76+ totalMarketValue : 0 ,
77+ totalMissing : 1150000 ,
78+ missingPercentage : 22.3 ,
79+ missingMarketValueUSD : 874700000 ,
80+ missingMarketValue : 0 ,
81+ }
82+ setMarketStats ( fakeData )
83+ }
5884 try {
5985 const stats = await fetch ( `${ API } /stats` , {
6086 method : 'GET' ,
@@ -110,6 +136,20 @@ export default function Stats({ logos }) {
110136 )
111137 }
112138
139+ /**
140+ * @param {Object } props
141+ * @param {string } [props.title]
142+ * @param {any } [props.children]
143+ */
144+ const MarketStatCard = ( { title, children } ) => {
145+ return (
146+ < div className = "market-stats-card bg-white text-center border border-black h-full box-content flex flex-col justify-center p-4" >
147+ < div > { children } </ div >
148+ < div className = "text-lg" > { title } </ div >
149+ </ div >
150+ )
151+ }
152+
113153 const StatCards = ( ) => {
114154 const figureClass = `chicagoflf text-[clamp(22px,_4.2rem,_6vw)] my-5`
115155 const statImageClass = `w-full border-b border-black object-cover aspect-[5/2]`
@@ -140,9 +180,11 @@ export default function Stats({ logos }) {
140180 </ figure >
141181 < p
142182 className = { `chicagoflf ${
143- stats . growthRate > 0
144- ? `text-forest before:content-['+']`
145- : 'text-red'
183+ stats . growthRate >= 0
184+ ? `text-forest ${
185+ stats . growthRate > 0 ? "before:content-['+']" : ''
186+ } `
187+ : `text-red before:content-['-']`
146188 } `}
147189 >
148190 { stats . growthRate || 0 } %
@@ -172,9 +214,11 @@ export default function Stats({ logos }) {
172214 </ figure >
173215 < p
174216 className = { `chicagoflf ${
175- stats . deals_total > 0
176- ? `text-forest before:content-['+']`
177- : 'text-red'
217+ stats . deals_total >= 0
218+ ? `text-forest ${
219+ stats . deals_total > 0 ? "before:content-['+']" : ''
220+ } `
221+ : `text-red before:content-['-']`
178222 } `}
179223 >
180224 { stats . dealsSizeGrowthRate || 0 } %
@@ -189,10 +233,78 @@ export default function Stats({ logos }) {
189233 )
190234 }
191235
236+ const MarketStatCards = ( ) => {
237+ return (
238+ < div className = "max-w-7xl mx-auto py-4 px-6 sm:px-16" >
239+ < div className = "mb-16 pl-8 grid gap-x-4 gap-y-[8vw] md:grid-cols-2 xl:grid-cols-4" >
240+ < MarketStatCard title = "Total Count of NFTS" >
241+ < figure className = "chicagoflf text-[clamp(2rem,2.6rem,3.3rem)] text-navy" >
242+ { statsLoading && < Loading /> }
243+ { new Intl . NumberFormat ( 'en-GB' , {
244+ notation : 'compact' ,
245+ compactDisplay : 'short' ,
246+ maximumFractionDigits : 1 ,
247+ } ) . format ( marketStats . totalNfts || 0 ) }
248+ </ figure >
249+ </ MarketStatCard >
250+ < MarketStatCard title = "Total market value of NFTs" >
251+ < figure className = "chicagoflf text-[clamp(2rem,2.6rem,3.3rem)] text-forest" >
252+ { statsLoading && < Loading /> }
253+ { marketStats . totalMarketValueUSD > 0 ? '$' : 'Ξ' }
254+ { new Intl . NumberFormat ( 'en-GB' , {
255+ notation : 'compact' ,
256+ compactDisplay : 'short' ,
257+ maximumFractionDigits : 1 ,
258+ } ) . format (
259+ marketStats . missingMarketValueUSD > 0
260+ ? marketStats . totalMarketValueUSD
261+ : marketStats . totalMarketValue || 0
262+ ) }
263+ </ figure >
264+ </ MarketStatCard >
265+ < MarketStatCard title = "Market value of missing NFTs" >
266+ < figure className = "chicagoflf text-[clamp(2rem,2.6rem,3.3rem)] text-red" >
267+ { statsLoading && < Loading /> }
268+ { marketStats . missingMarketValueUSD > 0 ? '$' : 'Ξ' }
269+ { new Intl . NumberFormat ( 'en-GB' , {
270+ notation : 'compact' ,
271+ compactDisplay : 'short' ,
272+ maximumFractionDigits : 1 ,
273+ } ) . format (
274+ marketStats . missingMarketValueUSD > 0
275+ ? marketStats . missingMarketValueUSD
276+ : marketStats . missingMarketValue || 0
277+ ) }
278+ </ figure >
279+ </ MarketStatCard >
280+ < MarketStatCard title = "Percentage of NFTs deemed missing" >
281+ < figure className = "chicagoflf text-[clamp(2rem,2.6rem,3.3rem)] text-yellow" >
282+ { statsLoading && < Loading /> }
283+ { marketStats . missingPercentage ?? 0 } %
284+ </ figure >
285+ </ MarketStatCard >
286+ </ div >
287+ </ div >
288+ )
289+ }
290+
192291 return (
193292 < main className = "bg-nsgreen" >
194293 < Marquee />
195294 < StatCards />
295+ < div className = "bg-nspeach" >
296+ < div className = "relative w-screen flex items-center justify-center" >
297+ < div className = "text-center" >
298+ < p className = "chicagoflf p-4 m-0 mt-5 text-[clamp(14px,_2rem,_6vw)]" >
299+ NFT Market By the Numbers
300+ </ p >
301+ < p className = "chicagoflf p-4 m-0 mt-5 text-[clamp(12px,_1.6rem,_6vw)]" >
302+ The Price of Missing NFTS
303+ </ p >
304+ </ div >
305+ </ div >
306+ < MarketStatCards />
307+ </ div >
196308 < div className = "bg-nsblue" >
197309 < div className = "stats-trusted-wrapper max-w-7xl mx-auto py-4 px-6 sm:px-16" >
198310 < div >
0 commit comments