import type { GetServerSideProps, GetServerSidePropsContext, GetServerSidePropsResult } from 'next'; import type { AdBannerProviders } from 'types/client/adProviders'; import type { RollupType } from 'types/client/rollup'; import type { Route } from 'nextjs-routes'; import config from 'configs/app'; const rollupFeature = config.features.rollup; const adBannerFeature = config.features.adsBanner; import isNeedProxy from 'lib/api/isNeedProxy'; import type * as metadata from 'lib/metadata'; export interface Props { query: Route['query']; cookies: string; referrer: string; adBannerProvider: AdBannerProviders | null; // if apiData is undefined, Next.js will complain that it is not serializable // so we force it to be always present in the props but it can be null apiData: metadata.ApiData | null; } export const base = async ({ req, query }: GetServerSidePropsContext): Promise>> => { const adBannerProvider = (() => { if (adBannerFeature.isEnabled) { if ('additionalProvider' in adBannerFeature && adBannerFeature.additionalProvider) { // we need to get a random ad provider on the server side to keep it consistent with the client side const randomIndex = Math.round(Math.random()); return [ adBannerFeature.provider, adBannerFeature.additionalProvider ][randomIndex]; } else { return adBannerFeature.provider; } } return null; })(); return { props: { query, cookies: req.headers.cookie || '', referrer: req.headers.referer || '', adBannerProvider: adBannerProvider, apiData: null, }, }; }; export const account: GetServerSideProps = async(context) => { if (!config.features.account.isEnabled) { return { notFound: true, }; } return base(context); }; export const verifiedAddresses: GetServerSideProps = async(context) => { if (!config.features.addressVerification.isEnabled) { return { notFound: true, }; } return account(context); }; const DEPOSITS_ROLLUP_TYPES: Array = [ 'optimistic', 'shibarium', 'zkEvm', 'arbitrum', 'scroll' ]; export const deposits: GetServerSideProps = async(context) => { if (!(rollupFeature.isEnabled && DEPOSITS_ROLLUP_TYPES.includes(rollupFeature.type))) { return { notFound: true, }; } return base(context); }; const WITHDRAWALS_ROLLUP_TYPES: Array = [ 'optimistic', 'shibarium', 'zkEvm', 'arbitrum', 'scroll' ]; export const withdrawals: GetServerSideProps = async(context) => { if ( !config.features.beaconChain.isEnabled && !(rollupFeature.isEnabled && WITHDRAWALS_ROLLUP_TYPES.includes(rollupFeature.type)) ) { return { notFound: true, }; } return base(context); }; export const rollup: GetServerSideProps = async(context) => { if (!config.features.rollup.isEnabled) { return { notFound: true, }; } return base(context); }; export const outputRoots: GetServerSideProps = async(context) => { if (!(rollupFeature.isEnabled && rollupFeature.outputRootsEnabled)) { return { notFound: true, }; } return base(context); }; const BATCH_ROLLUP_TYPES: Array = [ 'zkEvm', 'zkSync', 'arbitrum', 'optimistic', 'scroll' ]; export const batch: GetServerSideProps = async(context) => { if (!(rollupFeature.isEnabled && BATCH_ROLLUP_TYPES.includes(rollupFeature.type))) { return { notFound: true, }; } return base(context); }; export const marketplace = async (context: GetServerSidePropsContext): Promise>> => { if (!config.features.marketplace.isEnabled) { return { notFound: true, }; } return base(context); }; export const apiDocs: GetServerSideProps = async(context) => { if (!config.features.restApiDocs.isEnabled) { return { notFound: true, }; } return base(context); }; export const graphIQl: GetServerSideProps = async(context) => { if (!config.features.graphqlApiDocs.isEnabled) { return { notFound: true, }; } return base(context); }; export const csvExport: GetServerSideProps = async(context) => { if (!config.features.csvExport.isEnabled) { return { notFound: true, }; } return base(context); }; export const stats: GetServerSideProps = async(context) => { if (!config.features.stats.isEnabled) { return { notFound: true, }; } return base(context); }; export const suave: GetServerSideProps = async(context) => { if (!config.features.suave.isEnabled) { return { notFound: true, }; } return base(context); }; export const nameService: GetServerSideProps = async(context) => { if (!config.features.nameService.isEnabled) { return { notFound: true, }; } return base(context); }; export const accounts: GetServerSideProps = async(context) => { if (config.UI.views.address.hiddenViews?.top_accounts) { return { notFound: true, }; } return base(context); }; export const accountsLabelSearch: GetServerSideProps = async(context) => { if (!config.features.addressMetadata.isEnabled || !context.query.tagType) { return { notFound: true, }; } return base(context); }; export const userOps: GetServerSideProps = async(context) => { if (!config.features.userOps.isEnabled) { return { notFound: true, }; } return base(context); }; export const validators: GetServerSideProps = async(context) => { if (!config.features.validators.isEnabled) { return { notFound: true, }; } return base(context); }; export const gasTracker: GetServerSideProps = async(context) => { if (!config.features.gasTracker.isEnabled) { return { notFound: true, }; } return base(context); }; export const advancedFilter: GetServerSideProps = async(context) => { if (!config.features.advancedFilter.isEnabled) { return { notFound: true, }; } return base(context); }; export const dataAvailability: GetServerSideProps = async(context) => { if (!config.features.dataAvailability.isEnabled) { return { notFound: true, }; } return base(context); }; export const login: GetServerSideProps = async(context) => { if (!isNeedProxy()) { return { notFound: true, }; } return base(context); }; export const dev: GetServerSideProps = async(context) => { if (!config.app.isDev) { return { notFound: true, }; } return base(context); }; export const publicTagsSubmit: GetServerSideProps = async(context) => { if (!config.features.publicTagsSubmission.isEnabled) { return { notFound: true, }; } return base(context); }; export const disputeGames: GetServerSideProps = async(context) => { if (!config.features.faultProofSystem.isEnabled) { return { notFound: true, }; } return base(context); }; export const mud: GetServerSideProps = async(context) => { if (!config.features.mudFramework.isEnabled) { return { notFound: true, }; } return base(context); }; export const pools: GetServerSideProps = async(context) => { if (!config.features.pools.isEnabled) { return { notFound: true, }; } return base(context); };