Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 40 additions & 40 deletions app/license/[licenseType]/[licenseId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,49 +10,49 @@ import * as types from '@/typedefs/blockchain';
import { Skeleton } from '@heroui/skeleton';
import { cache, Suspense } from 'react';

export async function generateMetadata({ params }) {
const { licenseType, licenseId } = await params;
const errorMetadata = {
title: 'Error',
openGraph: {
title: 'Error',
},
};

if (!licenseType || !['ND', 'MND', 'GND'].includes(licenseType)) {
return errorMetadata;
}
export async function generateMetadata({ params }) {
const { licenseType, licenseId } = await params;
const errorMetadata = {
title: 'Error',
openGraph: {
title: 'Error',
},
};
if (!licenseType || !['ND', 'MND', 'GND'].includes(licenseType)) {
return errorMetadata;
}

const licenseIdNum = parseInt(licenseId);

if (isNaN(licenseIdNum) || licenseIdNum < 0 || licenseIdNum > 10000) {
return errorMetadata;
}

const canonical = `/license/${encodeURIComponent(licenseType)}/${encodeURIComponent(licenseId)}`;
const errorMetadataWithCanonical = {
...errorMetadata,
alternates: {
canonical,
},
};

try {
await fetchLicense(licenseType, licenseId, config.environment);
} catch (error) {
return errorMetadataWithCanonical;
}

return {
title: `License #${licenseId}`,
openGraph: {
title: `License #${licenseId}`,
},
alternates: {
canonical,
},
};
}
if (isNaN(licenseIdNum) || licenseIdNum < 0 || licenseIdNum > 10000) {
return errorMetadata;
}
const canonical = `/license/${encodeURIComponent(licenseType)}/${encodeURIComponent(licenseId)}`;
const errorMetadataWithCanonical = {
...errorMetadata,
alternates: {
canonical,
},
};
try {
await fetchLicense(licenseType, licenseId, config.environment);
} catch (error) {
return errorMetadataWithCanonical;
}
return {
title: `License #${licenseId}`,
openGraph: {
title: `License #${licenseId}`,
},
alternates: {
canonical,
},
};
}

const fetchLicense = async (
licenseType: 'ND' | 'MND' | 'GND',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default async function LicensePageNodeCardWrapper({
await cachedGetNodeAvailability();

if (!nodeResponse) {
return <ErrorAlert />;
return null;
}

return <NodeCard nodeResponse={nodeResponse} hasLink />;
Expand Down
2 changes: 1 addition & 1 deletion app/server-components/Licenses/License.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export default async function License({ licenseType, licenseId }: Props) {
<CardItem
label="Assign Timestamp"
value={
!assignTimestamp ? (
!assignTimestamp || assignTimestamp === '0' ? (
<>
<div className="block lg:hidden">
<div className="text-slate-400">Not assigned</div>
Expand Down
7 changes: 4 additions & 3 deletions app/server-components/Licenses/LicenseRewardsPoA.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import { SmallTag } from '../shared/SmallTag';
export default async function LicenseRewardsPoA({
license,
licenseType,
licenseId,
getNodeAvailability,
}: {
license: types.License;
licenseType: 'ND' | 'MND' | 'GND';
licenseId: string;
getNodeAvailability: () => Promise<(types.OraclesAvailabilityResult & types.OraclesDefaultResult) | undefined>;
}) {
try {
Expand All @@ -21,9 +23,7 @@ export default async function LicenseRewardsPoA({
await getNodeAvailability();

if (!nodeResponse) {
return (
<CardHorizontal label="Rewards" value={<SmallTag variant="banned">Error loading rewards</SmallTag>} isSmall />
);
return null;
}

const firstCheckEpoch: number = getLicenseFirstCheckEpoch(license.assignTimestamp);
Expand All @@ -32,6 +32,7 @@ export default async function LicenseRewardsPoA({
rewards = await getLicenseRewards(
license,
licenseType,
BigInt(licenseId),
nodeResponse.epochs.slice(lastClaimEpoch - firstCheckEpoch),
nodeResponse.epochs_vals.slice(lastClaimEpoch - firstCheckEpoch),
);
Expand Down
11 changes: 6 additions & 5 deletions app/server-components/main-cards/LicenseCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,12 @@ export default async function LicenseCard({ license, licenseType, licenseId, own
<PoA totalAssignedAmount={license.totalAssignedAmount} totalClaimedAmount={license.totalClaimedAmount} />

<Suspense fallback={<Skeleton className="min-h-[76px] w-full rounded-xl md:max-w-[258px]" />}>
<LicenseRewardsPoA
license={license}
licenseType={licenseType as 'ND' | 'MND' | 'GND'}
getNodeAvailability={getNodeAvailability}
/>
<LicenseRewardsPoA
license={license}
licenseType={licenseType as 'ND' | 'MND' | 'GND'}
licenseId={licenseId}
getNodeAvailability={getNodeAvailability}
/>
</Suspense>

{licenseType === 'ND' && (
Expand Down
Loading