Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"javascript.validate.enable": false,
"javascript.format.enable": false,
"typescript.format.enable": false,

"search.exclude": {
".eslintcache": true,
".git": true,
Expand All @@ -26,18 +25,15 @@
"test/**/__snapshots__": true,
"yarn.lock": true
},

// Disable organize imports on save to prevent conflicts with Prettier, keep ESLint fixes
"editor.codeActionsOnSave": {
"source.organizeImports": "never",
"source.fixAll.eslint": "explicit",
"source.fixAll.ts": "explicit"
},

// Use Prettier as the default formatter for consistent import ordering
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,

// Language-specific settings
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
Expand Down
6 changes: 5 additions & 1 deletion src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ export const endpoint = (
if (!ssvNetwork) {
throw new Error(`SSV network details not found for chainId: ${chainName}`)
}
return urlJoin(
const url = urlJoin(
ssvNetwork.api,
ssvNetwork.apiVersion,
ssvNetwork.apiNetwork,
...paths.map(String)
)

// For debugging purposes
if (process.env.NODE_ENV === "development") console.log("endpoint:", url)
return url
}
11 changes: 1 addition & 10 deletions src/api/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { endpoint } from "@/api"
import { api } from "@/api/api-client"
import { formatGwei, parseEther } from "viem"

Check warning on line 5 in src/api/validators.ts

View workflow job for this annotation

GitHub Actions / lint-and-build

'parseEther' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 5 in src/api/validators.ts

View workflow job for this annotation

GitHub Actions / lint-and-build

'formatGwei' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 5 in src/api/validators.ts

View workflow job for this annotation

GitHub Actions / lint-and-build

'parseEther' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 5 in src/api/validators.ts

View workflow job for this annotation

GitHub Actions / lint-and-build

'formatGwei' is defined but never used. Allowed unused vars must match /^_/u

import type { PaginatedValidatorsResponse, Validator } from "@/types/api"
import { type ChainName } from "@/config/chains"
Expand All @@ -19,16 +19,7 @@
) =>
await unstable_cache(
async () => {
const augmentedParams = {
...params,
effectiveBalance: params.effectiveBalance
? (params.effectiveBalance.map(
(value) => +formatGwei(parseEther(value.toString()))
) as [number, number])
: params.effectiveBalance,
}

const searchParams = validatorsSearchParamsSerializer(augmentedParams)
const searchParams = validatorsSearchParamsSerializer(params)
const url = endpoint(params.network, "validators", searchParams)
const response = await api.get<PaginatedValidatorsResponse>(url)

Expand Down
6 changes: 5 additions & 1 deletion src/app/_components/accounts/account-table-filters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ export const AccountTableFilters = () => {
step={1}
decimals={0}
/>
<EffectiveBalanceFilter searchParamsHook={useAccountsSearchParams} />
<EffectiveBalanceFilter<AccountSearchFilterKeys>
name="Effective Balance"
searchQueryKey="effectiveBalance"
parser={accountsSearchFilters.effectiveBalance}
/>
<RangeFilter<AccountSearchFilterKeys>
name="Operators"
searchQueryKey="operators"
Expand Down
6 changes: 5 additions & 1 deletion src/app/_components/clusters/cluster-table-filters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ export const ClusterTableFilters = ({
/>
)}
<OperatorsFilter />
<EffectiveBalanceFilter searchParamsHook={useClustersSearchParams} />
<EffectiveBalanceFilter<ClusterSearchFilterKeys>
name="Effective Balance"
searchQueryKey="effectiveBalance"
parser={clustersSearchFilters.effectiveBalance}
/>
<StatusFilter />
<IsLiquidatedFilter />
{enabledFilters.count > 0 && (
Expand Down
71 changes: 0 additions & 71 deletions src/app/_components/operators/filters/managed-eth-filter.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import { Button } from "@/components/ui/button"
import { textVariants } from "@/components/ui/text"
import { MevRelaysFilter } from "@/app/_components/operators/filters/mev-relays-filter"
import { HexFilter } from "@/app/_components/shared/filters/address-filter"
import { EffectiveBalanceFilter } from "@/app/_components/shared/filters/effective-balance-filter"

import { EthFeeFilter } from "./eth-fee-filter"
import { Eth1ClientFilter } from "./eth1-client-filter"
import { Eth2ClientFilter } from "./eth2-client-filter"
import { FeeFilter } from "./fee-filter"
import { IdFilter } from "./id-filter"
import { LocationFilter } from "./location-filter"
import { ManagedEthFilter } from "./managed-eth-filter"
import { NameFilter } from "./name-filter"
import { Performance24hFilter } from "./performance-24h-filter"
import { Performance30dFilter } from "./performance-30d-filter"
Expand Down Expand Up @@ -74,7 +74,11 @@ export const OperatorTableFilters = ({
<MevRelaysFilter />
<EthFeeFilter />
<FeeFilter />
<ManagedEthFilter />
<EffectiveBalanceFilter<OperatorSearchFilterKeys>
name="ETH Managed"
searchQueryKey="effectiveBalance"
parser={operatorSearchParsers.effectiveBalance}
/>
<ValidatorsFilter />
<Performance24hFilter />
<Performance30dFilter />
Expand Down
4 changes: 2 additions & 2 deletions src/app/_components/shared/filters/address-filter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { useState } from "react"
import { xor } from "lodash-es"
import { X } from "lucide-react"
import { useQueryState, type ParserBuilder } from "nuqs"
import { SingleParserBuilder, useQueryState } from "nuqs"
import { Collapse } from "react-collapse"
import { MdKeyboardReturn } from "react-icons/md"
import { type Address, type Hex } from "viem"
Expand All @@ -24,7 +24,7 @@ import { FilterButton } from "@/components/filter/filter-button"
type HexFilterProps<TSearchKey extends string = string> = {
name: string
searchQueryKey: TSearchKey
parser: ParserBuilder<Address[]>
parser: SingleParserBuilder<Address[]>
placeholder?: string
invalidMessage?: string
}
Expand Down
54 changes: 29 additions & 25 deletions src/app/_components/shared/filters/effective-balance-filter.tsx
Original file line number Diff line number Diff line change
@@ -1,71 +1,75 @@
"use client"

import { isEqual } from "lodash-es"
import { SingleParserBuilder, useQueryState } from "nuqs"

import { effectiveBalanceParser } from "@/lib/search-parsers/shared/parsers"
import { useCustomSearchParams } from "@/hooks/search/use-custom-search-params"
import { useDisclosure } from "@/hooks/use-disclosure"
import { Text } from "@/components/ui/text"
import { FilterButton } from "@/components/filter/filter-button"
import { Range } from "@/components/filter/range-filter"
import { OpenRange } from "@/components/filter/open-range-filter"

export function EffectiveBalanceFilter({
searchParamsHook,
}: {
searchParamsHook: () => ReturnType<
typeof useCustomSearchParams<{
effectiveBalance: typeof effectiveBalanceParser
}>
>
}) {
const { filters, setFilters } = searchParamsHook()
type Props<TSearchKey extends string = string> = {
name: string
searchQueryKey: TSearchKey
parser: SingleParserBuilder<[number, number]> & {
defaultValue: [number, number]
}
}
export function EffectiveBalanceFilter<TSearchKey extends string = string>({
name,
searchQueryKey,
parser,
}: Props<TSearchKey>) {
const popup = useDisclosure()

const defaultRange = effectiveBalanceParser.defaultValue
const [searchRange, setSearchRange] = useQueryState(searchQueryKey, parser)
const defaultRange = parser.defaultValue

const isActive =
!isEqual(filters.effectiveBalance, defaultRange) &&
Boolean(filters.effectiveBalance)
const isActive = !isEqual(searchRange, defaultRange) && Boolean(searchRange)

const apply = (range: [number, number]) => {
const isCleared = isEqual(range, defaultRange)
setFilters((prev) => ({
...prev,
effectiveBalance: isCleared ? null : range,
}))
setSearchRange(isCleared ? null : range)
popup.onOpenChange(false)
}

const remove = () => {
apply(defaultRange)
popup.onOpenChange(false)
}

return (
<FilterButton
isActive={isActive}
name="Effective Balance"
name={name}
onClear={remove}
popover={{
root: popup,
content: {
className: "w-[400px] max-w-full",
},
}}
>
<Range
<OpenRange
className="w-[400px] max-w-full"
name="Effective Balance"
searchRange={filters.effectiveBalance}
name={name}
searchRange={searchRange}
defaultRange={defaultRange}
apply={apply}
remove={remove}
step={1}
decimals={0}
inputs={{
start: {
placeholder: "From",
rightSlot: (
<Text variant="body-3-medium" className="text-gray-500">
ETH
</Text>
),
},
end: {
placeholder: "To",
rightSlot: (
<Text variant="body-3-medium" className="text-gray-500">
ETH
Expand Down
6 changes: 5 additions & 1 deletion src/app/_components/validators/validator-table-filters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ export const ValidatorTableFilters = ({
searchQueryKey="dateRange"
parser={validatorsSearchParsers.dateRange}
/>
<EffectiveBalanceFilter searchParamsHook={useValidatorsSearchParams} />
<EffectiveBalanceFilter<ValidatorSearchFilterKeys>
name="Effective Balance"
searchQueryKey="effectiveBalance"
parser={validatorsSearchParsers.effectiveBalance}
/>
{enabledFilters.count > 0 && (
<Button
variant="ghost"
Expand Down
Loading
Loading