Skip to content

Commit

Permalink
feat(app): migrate node-explorer page to app router (#572)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-devstack authored Oct 22, 2024
1 parent f6f2de6 commit 65a0bc6
Show file tree
Hide file tree
Showing 9 changed files with 1,288 additions and 270 deletions.
67 changes: 67 additions & 0 deletions apps/app/src/app/[locale]/node-explorer/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import ExplorerIndex from '@/components/app/skeleton/node-explorer/Index';
import { appUrl } from '@/utils/app/config';
import { Metadata } from 'next';
import { unstable_setRequestLocale } from 'next-intl/server';
import { Suspense } from 'react';

const network = process.env.NEXT_PUBLIC_NETWORK_ID;
const ogUrl = process.env.NEXT_PUBLIC_OG_URL;

export async function generateMetadata({
params: { locale },
}: {
params: { hash: string; locale: string };
}): Promise<Metadata> {
unstable_setRequestLocale(locale);

const metaTitle = 'NEAR Validator List | Nearblocks';
const metaDescription = '';

const ogImageUrl = `${ogUrl}/api/og?basic=true&title=${encodeURIComponent(
metaTitle,
)}`;

return {
title: `${network === 'testnet' ? 'TESTNET' : ''} ${metaTitle}`,
description: metaDescription,
openGraph: {
title: metaTitle,
description: metaDescription,
images: [
{
url: ogImageUrl.toString(),
width: 720,
height: 405,
alt: metaTitle,
},
],
},
alternates: {
canonical: `${appUrl}/node-explorer`,
},
};
}

export default async function ExplorerLayout({
children,
}: {
children: React.ReactNode;
params: any;
}) {
return (
<>
<div className="bg-hero-pattern dark:bg-hero-pattern-dark h-72">
<div className="container mx-auto px-3">
<h1 className="mb-4 pt-8 sm:!text-2xl text-xl text-white">
NEAR Protocol Validator Explorer
</h1>
</div>
</div>
<div className="container mx-auto px-3 -mt-48">
<div className="relative">
<Suspense fallback={<ExplorerIndex />}>{children}</Suspense>
</div>
</div>
</>
);
}
29 changes: 29 additions & 0 deletions apps/app/src/app/[locale]/node-explorer/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import NodeList from '@/components/app/NodeExplorer/NodeList';
import { getRequest } from '@/utils/app/api';
import { RpcProviders } from '@/utils/app/rpc';
import { cookies } from 'next/headers';
import QueryString from 'qs';

const getCookieFromRequest = (cookieName: string): string | null => {
const cookie = cookies().get(cookieName);
return cookie ? cookie.value : null;
};

export default async function NodeExplorer({ searchParams }: any) {
const rpcUrl = getCookieFromRequest('rpcUrl') || RpcProviders?.[0]?.url;

const data = await getRequest(
`validators?${QueryString.stringify(searchParams)}&rpc=${rpcUrl}`,
);
const statsDetails = await getRequest('stats');
const latestBlock = await getRequest('blocks/latest?limit=1');

return (
<NodeList
data={data}
totalSupply={statsDetails}
latestBlock={latestBlock}
error={!data}
/>
);
}
Loading

0 comments on commit 65a0bc6

Please sign in to comment.