Commit 0bc1b865 authored by tom's avatar tom

common solution for next pages

parent c86070a2
import NETWORKS from './availableNetworks';
export default function getNetworkTitle({ network_type: type, network_sub_type: subType }: {network_type: string; network_sub_type: string}) {
export default function getNetworkTitle({ network_type: type, network_sub_type: subType }: {network_type?: string; network_sub_type?: string}) {
const currentNetwork = NETWORKS.find(n => n.type === type && n.subType === subType);
if (currentNetwork) {
return currentNetwork.name + (currentNetwork.shortName ? ` (${ currentNetwork.shortName })` : '') + ' Explorer';
......
import type { GetStaticProps, GetStaticPropsResult } from 'next';
export const getStaticProps: GetStaticProps = async(context): Promise<GetStaticPropsResult<{ [key: string]: unknown }>> => {
return {
props: {
pageParams: context.params,
},
};
};
import type { NextPage } from 'next';
import Head from 'next/head';
import React from 'react';
import type { PageParams } from './types';
import type { Props as TransactionProps } from 'ui/pages/Transaction';
import Transaction from 'ui/pages/Transaction';
import getSeo from './getSeo';
type Props = {
pageParams: PageParams;
tab: TransactionProps['tab'];
}
const TransactionNextPage: NextPage<Props> = ({ pageParams, tab }: Props) => {
const { title } = getSeo(pageParams);
return (
<>
<Head><title>{ title }</title></Head>
<Transaction tab={ tab }/>
</>
);
};
export default TransactionNextPage;
import type { PageParams } from './types';
import getNetworkTitle from 'lib/networks/getNetworkTitle';
export default function getSeo(params?: PageParams) {
const networkTitle = getNetworkTitle(params || {});
return {
title: params ? `Transaction ${ params.id } - ${ networkTitle }` : '',
description: params ? `View transaction ${ params.id } on ${ networkTitle }` : '',
};
}
import type { GetStaticPaths } from 'next';
export const getStaticPaths: GetStaticPaths = async() => {
return { paths: [], fallback: true };
};
export type PageParams = {
network_type: string;
network_sub_type: string;
id: string;
}
import type { NextPage, GetStaticPaths, GetStaticProps, GetStaticPropsResult } from 'next';
import Head from 'next/head';
import type { NextPage } from 'next';
import React from 'react';
import getNetworkTitle from 'lib/networks/getNetworkTitle';
import Transaction from 'ui/pages/Transaction';
import type { PageParams } from 'lib/next/tx/types';
type PageParams = {
network_type: string;
network_sub_type: string;
id: string;
}
import TransactionNextPage from 'lib/next/tx/TransactionNextPage';
type Props = {
pageParams: PageParams;
}
const TransactionPage: NextPage<Props> = ({ pageParams }: Props) => {
const title = getNetworkTitle(pageParams || {});
return (
<>
<Head><title>{ title }</title></Head>
<Transaction tab="details"/>
</>
<TransactionNextPage tab="details" pageParams={ pageParams }/>
);
};
export default TransactionPage;
export const getStaticPaths: GetStaticPaths = async() => {
return { paths: [], fallback: true };
};
export const getStaticProps: GetStaticProps = async(context): Promise<GetStaticPropsResult<Props>> => {
return {
props: {
pageParams: context.params as PageParams,
},
};
};
export { getStaticPaths } from 'lib/next/tx/getStaticPaths';
export { getStaticProps } from 'lib/next/getStaticProps';
import type { NextPage, GetStaticPaths, GetStaticProps, GetStaticPropsResult } from 'next';
import Head from 'next/head';
import type { NextPage } from 'next';
import React from 'react';
import getNetworkTitle from 'lib/networks/getNetworkTitle';
import Transaction from 'ui/pages/Transaction';
import type { PageParams } from 'lib/next/tx/types';
type PageParams = {
network_type: string;
network_sub_type: string;
id: string;
}
import TransactionNextPage from 'lib/next/tx/TransactionNextPage';
type Props = {
pageParams: PageParams;
}
const TransactionPage: NextPage<Props> = ({ pageParams }: Props) => {
const title = getNetworkTitle(pageParams || {});
return (
<>
<Head><title>{ title }</title></Head>
<Transaction tab="internal_txn"/>
</>
);
return <TransactionNextPage pageParams={ pageParams } tab="internal_txn"/>;
};
export default TransactionPage;
export const getStaticPaths: GetStaticPaths = async() => {
return { paths: [], fallback: true };
};
export const getStaticProps: GetStaticProps = async(context): Promise<GetStaticPropsResult<Props>> => {
return {
props: {
pageParams: context.params as PageParams,
},
};
};
export { getStaticPaths } from 'lib/next/tx/getStaticPaths';
export { getStaticProps } from 'lib/next/getStaticProps';
......@@ -22,7 +22,7 @@ const TABS: Array<Tab> = [
{ type: 'internal_txn', path: '/internal-transactions', name: 'Internal txn' },
];
interface Props {
export interface Props {
tab: Tab['type'];
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment