Skip to content

Commit 220fc56

Browse files
Merge pull request #272 from ssvlabs/feat/operator-performance-graph-2
Feat/operator performance graph with verified commits
2 parents 8ecb602 + 618f8f8 commit 220fc56

File tree

12 files changed

+317
-90
lines changed

12 files changed

+317
-90
lines changed

.github/workflows/lint_build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
run: pnpm install --frozen-lockfile
5757

5858
- name: Run lint
59-
run: pnpm lint
59+
run: pnpm typegen && pnpm lint
6060
env:
6161
SKIP_ENV_VALIDATION: true
6262

next-env.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/// <reference types="next" />
22
/// <reference types="next/image-types/global" />
3+
/// <reference path="./.next/types/routes.d.ts" />
34

45
// NOTE: This file should not be edited
56
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"start:stage": "dotenv -e .env.production -- next start",
1616
"lint": "next lint",
1717
"lint:fix": "next lint --fix",
18+
"typegen": "next typegen",
1819
"typecheck": "tsc --noEmit",
1920
"format:write": "prettier --write \"**/*.{ts,tsx,mdx}\" --cache",
2021
"format:check": "prettier --check \"**/*.{ts,tsx,mdx}\" --cache",

src/api/operator.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,17 @@
33
import { endpoint } from "@/api"
44
import { api } from "@/api/api-client"
55

6-
import type { Country, Operator, OperatorsSearchResponse } from "@/types/api"
6+
import type {
7+
Country,
8+
Operator,
9+
OperatorPerformanceChart,
10+
OperatorsSearchResponse,
11+
} from "@/types/api"
712
import { type ChainName } from "@/config/chains"
13+
import {
14+
operatorPerformanceChartParamsSerializer,
15+
type OperatorPerformanceChartParams,
16+
} from "@/lib/search-parsers/operator-performance-chart-parsers"
817
import {
918
operatorSearchParamsSerializer,
1019
type OperatorsSearchSchema,
@@ -171,3 +180,30 @@ export const getOperatorPerformanceV2 = async (params: {
171180
}
172181
)()
173182
}
183+
184+
export const getOperatorPerformanceChart = async (
185+
params: {
186+
network: ChainName
187+
operatorId: number
188+
} & Partial<OperatorPerformanceChartParams>
189+
) =>
190+
await unstable_cache(
191+
async () => {
192+
const searchParams = operatorPerformanceChartParamsSerializer({
193+
points: params.points,
194+
type: params.type,
195+
})
196+
197+
const url = endpoint(
198+
params.network,
199+
`duties/operator/${params.operatorId}/performance-chart`,
200+
searchParams ? `?${searchParams}` : ""
201+
)
202+
return await api.get<OperatorPerformanceChart>(url)
203+
},
204+
[JSON.stringify(params)],
205+
{
206+
revalidate: 30,
207+
tags: ["operator-performance-chart"],
208+
}
209+
)()

src/api/ssv.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"use server"
2+
13
import { unstable_cache } from "next/cache"
24
import { api } from "@/api/api-client"
35
import urlJoin from "url-join"

src/app/[network]/account/[address]/layout.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isAddress, type Address } from "viem"
1+
import { isAddress } from "viem"
22

33
import { shortenAddress } from "@/lib/utils/strings"
44
import { Card } from "@/components/ui/card"
@@ -12,15 +12,10 @@ import { Shell } from "@/components/shell"
1212
import { TableNavigation } from "./_components/table-navigations"
1313
import { AccountStats } from "./account-stats"
1414

15-
interface IndexPageProps {
16-
children: React.ReactNode
17-
params: Promise<{ address: Address }>
18-
}
19-
2015
export default async function AccountLayout({
2116
params,
2217
children,
23-
}: IndexPageProps) {
18+
}: LayoutProps<"/[network]/account/[address]">) {
2419
const { address } = await params
2520

2621
if (!isAddress(address)) {

src/app/[network]/operator/[id]/page.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { ErrorCard } from "@/components/ui/error-card"
1515
import { Outline } from "@/components/ui/outline"
1616
import { Stat } from "@/components/ui/stat"
1717
import { Text } from "@/components/ui/text"
18+
import { PerformanceChart } from "@/components/operators/charts/performance-chart"
1819
import { OperatorAvatar } from "@/components/operators/operator-avatar"
1920
import { OperatorMetaData } from "@/components/operators/operator-meta-data"
2021
import { PerformanceText } from "@/components/operators/performance-text"
@@ -88,7 +89,7 @@ export default async function Page(props: IndexPageProps) {
8889

8990
return (
9091
<Shell className="gap-2">
91-
{(async () => {
92+
{await (async () => {
9293
try {
9394
const operator = await getOperator({
9495
network,
@@ -200,6 +201,13 @@ export default async function Page(props: IndexPageProps) {
200201
/>
201202
</div>
202203
</Card>
204+
<div className="flex flex-row gap-4">
205+
<PerformanceChart
206+
className="w-full md:w-1/2"
207+
operatorId={+id}
208+
network={network}
209+
/>
210+
</div>
203211
<Card>
204212
<ValidatorsTable dataPromise={validators} hideOperatorsFilter />
205213
</Card>

src/app/layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export const viewport: Viewport = {
6363
],
6464
}
6565

66-
export default async function RootLayout(props: RootLayoutProps) {
66+
export default async function RootLayout(props: LayoutProps<"/">) {
6767
return (
6868
<html lang="en" suppressHydrationWarning>
6969
<head />

0 commit comments

Comments
 (0)