Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
isstuev committed Oct 6, 2024
1 parent 10e5e93 commit 8ec5ba9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
2 changes: 2 additions & 0 deletions lib/metadata/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { LineChart } from '@blockscout/stats-types';
import type { TokenInfo } from 'types/api/token';
import type { Transaction } from 'types/api/transaction';

import type { Route } from 'nextjs-routes';

Expand All @@ -11,6 +12,7 @@ export type ApiData<Pathname extends Route['pathname']> =
Pathname extends '/token/[hash]/instance/[id]' ? { symbol: string } :
Pathname extends '/apps/[id]' ? { app_name: string } :
Pathname extends '/stats/[id]' ? LineChart['info'] :
Pathname extends '/tx/[hash]' ? Transaction :
never
) | null;

Expand Down
27 changes: 24 additions & 3 deletions pages/tx/[hash].tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,41 @@
import type { NextPage } from 'next';
import type { GetServerSideProps, NextPage } from 'next';
import dynamic from 'next/dynamic';
import React from 'react';

import type { Route } from 'nextjs-routes';
import type { Props } from 'nextjs/getServerSideProps';
import * as gSSP from 'nextjs/getServerSideProps';
import PageNextJs from 'nextjs/PageNextJs';
import fetchApi from 'nextjs/utils/fetchApi';

import getQueryParamString from 'lib/router/getQueryParamString';

const pathname: Route['pathname'] = '/tx/[hash]';

const Transaction = dynamic(() => import('ui/pages/Transaction'), { ssr: false });

const Page: NextPage<Props> = (props: Props) => {
return (
<PageNextJs pathname="/tx/[hash]" query={ props.query }>
<Transaction/>
<Transaction apiData={ props.apiData }/>
</PageNextJs>
);
};

export default Page;

export { base as getServerSideProps } from 'nextjs/getServerSideProps';
export const getServerSideProps: GetServerSideProps<Props<typeof pathname>> = async(ctx) => {
const baseResponse = await gSSP.base<typeof pathname>(ctx);

if ('props' in baseResponse) {
const txData = await fetchApi({
resource: 'tx',
pathParams: { hash: getQueryParamString(ctx.query.hash) },
timeout: 1000,
});

(await baseResponse.props).apiData = txData ?? null;
}

return baseResponse;
};
5 changes: 3 additions & 2 deletions ui/pages/Transaction.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useRouter } from 'next/router';
import React from 'react';

import type { Transaction } from 'types/api/transaction';
import type { RoutedTab } from 'ui/shared/Tabs/types';

import config from 'configs/app';
Expand Down Expand Up @@ -31,12 +32,12 @@ import useTxQuery from 'ui/tx/useTxQuery';

const txInterpretation = config.features.txInterpretation;

const TransactionPageContent = () => {
const TransactionPageContent = (props: { apiData: Transaction | null }) => {
const router = useRouter();
const appProps = useAppContext();

const hash = getQueryParamString(router.query.hash);
const txQuery = useTxQuery();
const txQuery = useTxQuery({ apiData: props.apiData });
const { data, isPlaceholderData, isError, error, errorUpdateCount } = txQuery;

const showDegradedView = publicClient && ((isError && error.status !== 422) || isPlaceholderData) && errorUpdateCount > 0;
Expand Down
2 changes: 2 additions & 0 deletions ui/tx/useTxQuery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export type TxQuery = UseQueryResult<Transaction, ResourceError<{ status: number
interface Params {
hash?: string;
isEnabled?: boolean;
apiData?: Transaction | null;
}

export default function useTxQuery(params?: Params): TxQuery {
Expand All @@ -49,6 +50,7 @@ export default function useTxQuery(params?: Params): TxQuery {
enabled: Boolean(hash) && params?.isEnabled !== false,
refetchOnMount: false,
placeholderData: rollupFeature.isEnabled && rollupFeature.type === 'zkEvm' ? TX_ZKEVM_L2 : TX,
initialData: params?.apiData ?? undefined,
retry: (failureCount, error) => {
if (isRefetchEnabled) {
return false;
Expand Down

0 comments on commit 8ec5ba9

Please sign in to comment.