1- import ErrorComponent from '@/app/server-components/shared/ErrorComponent' ;
2- import { getLicensesTotalSupply } from '@/lib/api/blockchain' ;
3- import { LicenseItem } from '@/typedefs/general' ;
4- import { unstable_cache } from 'next/cache' ;
5- import List from '../server-components/Licenses/List' ;
6- import { BorderedCard } from '../server-components/shared/cards/BorderedCard' ;
7- import { CardHorizontal } from '../server-components/shared/cards/CardHorizontal' ;
1+ import ErrorComponent from '@/app/server-components/shared/ErrorComponent' ;
2+ import { getAllLicenseTokenIds } from '@/lib/api/blockchain' ;
3+ import { LicenseItem } from '@/typedefs/general' ;
4+ import { unstable_cache } from 'next/cache' ;
5+ import List from '../server-components/Licenses/List' ;
6+ import { BorderedCard } from '../server-components/shared/cards/BorderedCard' ;
7+ import { CardHorizontal } from '../server-components/shared/cards/CardHorizontal' ;
88
99export async function generateMetadata ( { searchParams } : { searchParams ?: Promise < { page ?: string } > } ) {
1010 const resolvedSearchParams = await searchParams ;
@@ -22,7 +22,7 @@ export async function generateMetadata({ searchParams }: { searchParams?: Promis
2222 } ;
2323}
2424
25- const getCachedSupply = unstable_cache ( getLicensesTotalSupply , [ 'licenses-total-supply ' ] , { revalidate : 300 } ) ;
25+ const getCachedLicenseTokenIds = unstable_cache ( getAllLicenseTokenIds , [ 'licenses-token-ids ' ] , { revalidate : 300 } ) ;
2626
2727export default async function LicensesPage ( props : {
2828 searchParams ?: Promise < {
@@ -32,25 +32,24 @@ export default async function LicensesPage(props: {
3232 const searchParams = await props . searchParams ;
3333 const currentPage = Number ( searchParams ?. page ) || 1 ;
3434
35- let ndTotalSupply : number , mndTotalSupply : number ;
36- let licenses : LicenseItem [ ] ;
37-
38- try {
39- const { ndTotalSupply : ndTotalSupplyStr , mndTotalSupply : mndTotalSupplyStr } = await getCachedSupply ( ) ;
40-
41- ndTotalSupply = Number ( ndTotalSupplyStr ) ;
42- mndTotalSupply = Number ( mndTotalSupplyStr ) ;
43-
44- licenses = [
45- ...Array . from ( { length : Number ( mndTotalSupply ) } , ( _ , i ) => ( {
46- licenseId : i + 1 ,
47- licenseType : i === 0 ? ( 'GND' as const ) : ( 'MND' as const ) ,
48- } ) ) ,
49- ...Array . from ( { length : Number ( ndTotalSupply ) } , ( _ , i ) => ( {
50- licenseId : i + 1 ,
51- licenseType : 'ND' as const ,
52- } ) ) ,
53- ] ;
35+ let ndTotalSupply : number , mndTotalSupply : number ;
36+ let licenses : LicenseItem [ ] ;
37+
38+ try {
39+ const { ndLicenseIds, mndLicenseIds } = await getCachedLicenseTokenIds ( ) ;
40+ ndTotalSupply = ndLicenseIds . length ;
41+ mndTotalSupply = mndLicenseIds . length ;
42+
43+ licenses = [
44+ ...mndLicenseIds . map ( ( licenseId ) => ( {
45+ licenseId,
46+ licenseType : licenseId === 1 ? ( 'GND' as const ) : ( 'MND' as const ) ,
47+ } ) ) ,
48+ ...ndLicenseIds . map ( ( licenseId ) => ( {
49+ licenseId,
50+ licenseType : 'ND' as const ,
51+ } ) ) ,
52+ ] ;
5453 } catch ( error ) {
5554 console . error ( error ) ;
5655 console . log ( '[Licenses Page] Failed to fetch license data' ) ;
0 commit comments