Skip to content

Commit

Permalink
stats updates
Browse files Browse the repository at this point in the history
  • Loading branch information
isstuev committed Sep 6, 2024
1 parent e2081d4 commit 012f787
Show file tree
Hide file tree
Showing 31 changed files with 936 additions and 296 deletions.
4 changes: 2 additions & 2 deletions configs/envs/.env.eth_sepolia
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ NEXT_PUBLIC_AD_ADBUTLER_CONFIG_DESKTOP={ "id": "632019", "width": "728", "height
NEXT_PUBLIC_AD_ADBUTLER_CONFIG_MOBILE={ "id": "632018", "width": "320", "height": "100" }
NEXT_PUBLIC_ADMIN_SERVICE_API_HOST=https://admin-rs.services.blockscout.com
NEXT_PUBLIC_API_BASE_PATH=/
NEXT_PUBLIC_API_HOST=eth-sepolia.blockscout.com
NEXT_PUBLIC_API_HOST=eth-sepolia.k8s-dev.blockscout.com
NEXT_PUBLIC_API_SPEC_URL=https://raw.githubusercontent.com/blockscout/blockscout-api-v2-swagger/main/swagger.yaml
NEXT_PUBLIC_CONTRACT_CODE_IDES=[{'title':'Remix IDE','url':'https://remix.ethereum.org/?address={hash}&blockscout={domain}','icon_url':'https://raw.githubusercontent.com/blockscout/frontend-configs/main/configs/ide-icons/remix.png'}]
NEXT_PUBLIC_CONTRACT_INFO_API_HOST=https://contracts-info.services.blockscout.com
Expand Down Expand Up @@ -59,7 +59,7 @@ NEXT_PUBLIC_OG_IMAGE_URL=https://raw.githubusercontent.com/blockscout/frontend-c
NEXT_PUBLIC_OTHER_LINKS=[{'url':'https://sepolia.drpc.org?ref=559183','text':'Public RPC'}]
NEXT_PUBLIC_SAFE_TX_SERVICE_URL=https://safe-transaction-sepolia.safe.global
NEXT_PUBLIC_SENTRY_ENABLE_TRACING=true
NEXT_PUBLIC_STATS_API_HOST=https://stats-sepolia.k8s.blockscout.com
NEXT_PUBLIC_STATS_API_HOST=https://stats-sepolia.k8s-dev.blockscout.com
NEXT_PUBLIC_TRANSACTION_INTERPRETATION_PROVIDER=noves
NEXT_PUBLIC_VIEWS_CONTRACT_SOLIDITYSCAN_ENABLED=true
NEXT_PUBLIC_VISUALIZE_API_HOST=https://visualizer.services.blockscout.com
1 change: 1 addition & 0 deletions lib/metadata/getPageOgType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const OG_TYPE_DICT: Record<Route['pathname'], OGPageType> = {
'/apps': 'Root page',
'/apps/[id]': 'Regular page',
'/stats': 'Root page',
'/stats/[id]': 'Regular page',
'/api-docs': 'Regular page',
'/graphiql': 'Regular page',
'/search-results': 'Regular page',
Expand Down
1 change: 1 addition & 0 deletions lib/metadata/templates/description.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const TEMPLATE_MAP: Record<Route['pathname'], string> = {
'/apps': DEFAULT_TEMPLATE,
'/apps/[id]': DEFAULT_TEMPLATE,
'/stats': DEFAULT_TEMPLATE,
'/stats/[id]': DEFAULT_TEMPLATE,
'/api-docs': DEFAULT_TEMPLATE,
'/graphiql': DEFAULT_TEMPLATE,
'/search-results': DEFAULT_TEMPLATE,
Expand Down
2 changes: 2 additions & 0 deletions lib/metadata/templates/title.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const TEMPLATE_MAP: Record<Route['pathname'], string> = {
'/apps': '%network_name% DApps - Explore top apps',
'/apps/[id]': '%network_name% marketplace app',
'/stats': '%network_name% stats - %network_name% network insights',
'/stats/[id]': '%network_name% stats - %id% chart',
'/api-docs': '%network_name% API docs - %network_name% developer tools',
'/graphiql': 'GraphQL for %network_name% - %network_name% data query',
'/search-results': '%network_name% search result for %q%',
Expand Down Expand Up @@ -71,6 +72,7 @@ const TEMPLATE_MAP_ENHANCED: Partial<Record<Route['pathname'], string>> = {
'/token/[hash]/instance/[id]': '%network_name% token instance for %symbol%',
'/apps/[id]': '%network_name% - %app_name%',
'/address/[hash]': '%network_name% address details for %domain_name%',
'/stats/[id]': '%title% chart on %network_name%',
};

export function make(pathname: Route['pathname'], isEnriched = false) {
Expand Down
2 changes: 2 additions & 0 deletions lib/metadata/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { LineChart } from '@blockscout/stats-types';
import type { TokenInfo } from 'types/api/token';

import type { Route } from 'nextjs-routes';
Expand All @@ -9,6 +10,7 @@ export type ApiData<Pathname extends Route['pathname']> =
Pathname extends '/token/[hash]' ? TokenInfo :
Pathname extends '/token/[hash]/instance/[id]' ? { symbol: string } :
Pathname extends '/apps/[id]' ? { app_name: string } :
Pathname extends '/stats/[id]' ? LineChart['info'] :
never
) | null;

Expand Down
1 change: 1 addition & 0 deletions lib/mixpanel/getPageType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const PAGE_TYPE_DICT: Record<Route['pathname'], string> = {
'/apps': 'DApps',
'/apps/[id]': 'DApp',
'/stats': 'Stats',
'/stats/[id]': 'Stats chart',
'/api-docs': 'REST API',
'/graphiql': 'GraphQL',
'/search-results': 'Search results',
Expand Down
3 changes: 3 additions & 0 deletions lib/mixpanel/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ Type extends EventTypes.PAGE_WIDGET ? (
'Type': 'Address tag';
'Info': string;
'URL': string;
} | {
'Type': 'Share chart';
'Info': string;
}
) :
Type extends EventTypes.TX_INTERPRETATION_INTERACTION ? {
Expand Down
37 changes: 37 additions & 0 deletions mocks/stats/line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,158 +4,195 @@ export const averageGasPrice: stats.LineChart = {
chart: [
{
date: '2023-12-22',
date_to: '2023-12-22',
value: '37.7804422597599',
is_approximate: false,
},
{
date: '2023-12-23',
date_to: '2023-12-23',
value: '25.84889883009387',
is_approximate: false,
},
{
date: '2023-12-24',
date_to: '2023-12-24',
value: '25.818463227198574',
is_approximate: false,
},
{
date: '2023-12-25',
date_to: '2023-12-25',
value: '26.045513050051298',
is_approximate: false,
},
{
date: '2023-12-26',
date_to: '2023-12-26',
value: '21.42600692652399',
is_approximate: false,
},
{
date: '2023-12-27',
date_to: '2023-12-27',
value: '31.066730409846656',
is_approximate: false,
},
{
date: '2023-12-28',
date_to: '2023-12-28',
value: '33.63955781902089',
is_approximate: false,
},
{
date: '2023-12-29',
date_to: '2023-12-29',
value: '28.064736756058384',
is_approximate: false,
},
{
date: '2023-12-30',
date_to: '2023-12-30',
value: '23.074500869678175',
is_approximate: false,
},
{
date: '2023-12-31',
date_to: '2023-12-31',
value: '17.651005734615133',
is_approximate: false,
},
{
date: '2024-01-01',
date_to: '2023-01-01',
value: '14.906085174476441',
is_approximate: false,
},
{
date: '2024-01-02',
date_to: '2023-01-02',
value: '22.28459059038656',
is_approximate: false,
},
{
date: '2024-01-03',
date_to: '2023-01-03',
value: '39.8311646806592',
is_approximate: false,
},
{
date: '2024-01-04',
date_to: '2023-01-04',
value: '26.09989322256083',
is_approximate: false,
},
{
date: '2024-01-05',
date_to: '2023-01-05',
value: '22.821996688111998',
is_approximate: false,
},
{
date: '2024-01-06',
date_to: '2023-01-06',
value: '20.32680041262083',
is_approximate: false,
},
{
date: '2024-01-07',
date_to: '2023-01-07',
value: '32.535045831809704',
is_approximate: false,
},
{
date: '2024-01-08',
date_to: '2023-01-08',
value: '27.443477102139482',
is_approximate: false,
},
{
date: '2024-01-09',
date_to: '2023-01-09',
value: '20.7911332558055',
is_approximate: false,
},
{
date: '2024-01-10',
date_to: '2023-01-10',
value: '42.10740192523919',
is_approximate: false,
},
{
date: '2024-01-11',
date_to: '2023-01-11',
value: '35.75215680343582',
is_approximate: false,
},
{
date: '2024-01-12',
date_to: '2023-01-12',
value: '27.430414798093253',
is_approximate: false,
},
{
date: '2024-01-13',
date_to: '2023-01-13',
value: '20.170934096589875',
is_approximate: false,
},
{
date: '2024-01-14',
date_to: '2023-01-14',
value: '38.79660984371034',
is_approximate: false,
},
{
date: '2024-01-15',
date_to: '2023-01-15',
value: '26.140740484554204',
is_approximate: false,
},
{
date: '2024-01-16',
date_to: '2023-01-16',
value: '36.708543184194156',
is_approximate: false,
},
{
date: '2024-01-17',
date_to: '2023-01-17',
value: '40.325438794298876',
is_approximate: false,
},
{
date: '2024-01-18',
date_to: '2023-01-18',
value: '37.55145309930694',
is_approximate: false,
},
{
date: '2024-01-19',
date_to: '2023-01-19',
value: '33.271450114434664',
is_approximate: false,
},
{
date: '2024-01-20',
date_to: '2023-01-20',
value: '19.303304377685638',
is_approximate: false,
},
{
date: '2024-01-21',
date_to: '2023-01-21',
value: '14.375908594704976',
is_approximate: false,
},
],
info: {
title: 'Chart title',
description: 'Chert description',
id: 'chart',
resolutions: [ 'DAY', 'MONTH' ],
},
};
1 change: 1 addition & 0 deletions nextjs/nextjs-routes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ declare module "nextjs-routes" {
| StaticRoute<"/public-tags/submit">
| StaticRoute<"/search-results">
| StaticRoute<"/sprite">
| DynamicRoute<"/stats/[id]", { "id": string }>
| StaticRoute<"/stats">
| DynamicRoute<"/token/[hash]", { "hash": string }>
| DynamicRoute<"/token/[hash]/instance/[id]", { "hash": string; "id": string }>
Expand Down
4 changes: 2 additions & 2 deletions nextjs/utils/fetchApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type Params<R extends ResourceName> = (
{
resource: R;
pathParams?: ResourcePathParams<R>;
queryParams?: Record<string, string | number | undefined>;
} | {
url: string;
route: string;
Expand All @@ -22,12 +23,11 @@ type Params<R extends ResourceName> = (

export default async function fetchApi<R extends ResourceName = never, S = ResourcePayload<R>>(params: Params<R>): Promise<S | undefined> {
const controller = new AbortController();

const timeout = setTimeout(() => {
controller.abort();
}, params.timeout || SECOND);

const url = 'url' in params ? params.url : buildUrl(params.resource, params.pathParams);
const url = 'url' in params ? params.url : buildUrl(params.resource, params.pathParams, params.queryParams);
const route = 'route' in params ? params.route : RESOURCES[params.resource]['path'];

const end = metrics?.apiRequestDuration.startTimer();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
},
"dependencies": {
"@blockscout/bens-types": "1.4.1",
"@blockscout/stats-types": "1.6.0",
"@blockscout/stats-types": "^1.6.2-alpha",
"@blockscout/visualizer-types": "0.2.0",
"@chakra-ui/react": "2.7.1",
"@chakra-ui/theme-tools": "^2.0.18",
Expand Down
52 changes: 52 additions & 0 deletions pages/stats/[id].tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import type { GetServerSideProps, NextPage } from 'next';
import dynamic from 'next/dynamic';
import React from 'react';

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

import config from 'configs/app';
import dayjs from 'lib/date/dayjs';
import getQueryParamString from 'lib/router/getQueryParamString';

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

const pathname: Route['pathname'] = '/stats/[id]';

const Page: NextPage<Props<typeof pathname>> = (props: Props<typeof pathname>) => {
return (
<PageNextJs pathname="/stats/[id]" query={ props.query } apiData={ props.apiData }>
<Chart/>
</PageNextJs>
);
};

export default Page;

export const getServerSideProps: GetServerSideProps<Props<typeof pathname>> = async(ctx) => {
const baseResponse = await gSSP.base<typeof pathname>(ctx);

if ('props' in baseResponse) {
if (
config.meta.seo.enhancedDataEnabled ||
(config.meta.og.enhancedDataEnabled && detectBotRequest(ctx.req)?.type === 'social_preview')
) {
const chartData = await fetchApi({
resource: 'stats_line',
pathParams: { id: getQueryParamString(ctx.query.id) },
queryParams: { from: dayjs().format('YYYY-MM-DD'), to: dayjs().format('YYYY-MM-DD') },
timeout: 1000,
});

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

return baseResponse;
};

// export { base as getServerSideProps } from 'nextjs/getServerSideProps';
3 changes: 3 additions & 0 deletions public/static/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 012f787

Please sign in to comment.