Skip to content

Commit 6e03f19

Browse files
committed
fix: Unlinked licenses handling
1 parent 840b4e0 commit 6e03f19

File tree

4 files changed

+43
-45
lines changed

4 files changed

+43
-45
lines changed

app/license/[licenseType]/[licenseId]/page.tsx

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -10,49 +10,49 @@ import * as types from '@/typedefs/blockchain';
1010
import { Skeleton } from '@heroui/skeleton';
1111
import { cache, Suspense } from 'react';
1212

13-
export async function generateMetadata({ params }) {
14-
const { licenseType, licenseId } = await params;
15-
const errorMetadata = {
16-
title: 'Error',
17-
openGraph: {
18-
title: 'Error',
19-
},
20-
};
21-
22-
if (!licenseType || !['ND', 'MND', 'GND'].includes(licenseType)) {
23-
return errorMetadata;
24-
}
13+
export async function generateMetadata({ params }) {
14+
const { licenseType, licenseId } = await params;
15+
const errorMetadata = {
16+
title: 'Error',
17+
openGraph: {
18+
title: 'Error',
19+
},
20+
};
21+
22+
if (!licenseType || !['ND', 'MND', 'GND'].includes(licenseType)) {
23+
return errorMetadata;
24+
}
2525

2626
const licenseIdNum = parseInt(licenseId);
2727

28-
if (isNaN(licenseIdNum) || licenseIdNum < 0 || licenseIdNum > 10000) {
29-
return errorMetadata;
30-
}
31-
32-
const canonical = `/license/${encodeURIComponent(licenseType)}/${encodeURIComponent(licenseId)}`;
33-
const errorMetadataWithCanonical = {
34-
...errorMetadata,
35-
alternates: {
36-
canonical,
37-
},
38-
};
39-
40-
try {
41-
await fetchLicense(licenseType, licenseId, config.environment);
42-
} catch (error) {
43-
return errorMetadataWithCanonical;
44-
}
45-
46-
return {
47-
title: `License #${licenseId}`,
48-
openGraph: {
49-
title: `License #${licenseId}`,
50-
},
51-
alternates: {
52-
canonical,
53-
},
54-
};
55-
}
28+
if (isNaN(licenseIdNum) || licenseIdNum < 0 || licenseIdNum > 10000) {
29+
return errorMetadata;
30+
}
31+
32+
const canonical = `/license/${encodeURIComponent(licenseType)}/${encodeURIComponent(licenseId)}`;
33+
const errorMetadataWithCanonical = {
34+
...errorMetadata,
35+
alternates: {
36+
canonical,
37+
},
38+
};
39+
40+
try {
41+
await fetchLicense(licenseType, licenseId, config.environment);
42+
} catch (error) {
43+
return errorMetadataWithCanonical;
44+
}
45+
46+
return {
47+
title: `License #${licenseId}`,
48+
openGraph: {
49+
title: `License #${licenseId}`,
50+
},
51+
alternates: {
52+
canonical,
53+
},
54+
};
55+
}
5656

5757
const fetchLicense = async (
5858
licenseType: 'ND' | 'MND' | 'GND',

app/server-components/LicensePage/LicensePageNodeCardWrapper.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export default async function LicensePageNodeCardWrapper({
1313
await cachedGetNodeAvailability();
1414

1515
if (!nodeResponse) {
16-
return <ErrorAlert />;
16+
return null;
1717
}
1818

1919
return <NodeCard nodeResponse={nodeResponse} hasLink />;

app/server-components/Licenses/License.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export default async function License({ licenseType, licenseId }: Props) {
8787
<CardItem
8888
label="Assign Timestamp"
8989
value={
90-
!assignTimestamp ? (
90+
!assignTimestamp || assignTimestamp === '0' ? (
9191
<>
9292
<div className="block lg:hidden">
9393
<div className="text-slate-400">Not assigned</div>

app/server-components/Licenses/LicenseRewardsPoA.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ export default async function LicenseRewardsPoA({
2121
await getNodeAvailability();
2222

2323
if (!nodeResponse) {
24-
return (
25-
<CardHorizontal label="Rewards" value={<SmallTag variant="banned">Error loading rewards</SmallTag>} isSmall />
26-
);
24+
return null;
2725
}
2826

2927
const firstCheckEpoch: number = getLicenseFirstCheckEpoch(license.assignTimestamp);

0 commit comments

Comments
 (0)