diff --git a/apps/hub/src/app/governance/[genre]/components/deposit-dialog.tsx b/apps/hub/src/app/governance/[genre]/components/deposit-dialog.tsx index 1f412f2eb..0928e885d 100755 --- a/apps/hub/src/app/governance/[genre]/components/deposit-dialog.tsx +++ b/apps/hub/src/app/governance/[genre]/components/deposit-dialog.tsx @@ -50,7 +50,7 @@ export function VoteDialog({

{votingPower}

-

BGT delegated

+

Boosts

diff --git a/apps/hub/src/app/incentivize/page.tsx b/apps/hub/src/app/incentivize/page.tsx index e0d778921..25cd4b297 100755 --- a/apps/hub/src/app/incentivize/page.tsx +++ b/apps/hub/src/app/incentivize/page.tsx @@ -5,8 +5,8 @@ import { Address } from "viem"; import { Incentivize } from "./incentivize"; export const metadata: Metadata = { - title: "Delegate", - description: "Delegate, Redelegate, or Undelegate your BGT", + title: "Incentivize", + description: "Incentivize a reward vault", }; export default function Page() { diff --git a/apps/hub/src/app/validators/components/boost-queue.tsx b/apps/hub/src/app/validators/components/boost-queue.tsx index afa804ca9..370066aec 100755 --- a/apps/hub/src/app/validators/components/boost-queue.tsx +++ b/apps/hub/src/app/validators/components/boost-queue.tsx @@ -313,8 +313,9 @@ const ConfirmationCard = ({ showIsSmallerThanMin value={userValidator.type === "boost" ? amount : -Number(amount)} compact - />{" "} - BGT + colored + symbol="BGT" + />
diff --git a/apps/hub/src/app/validators/components/charts/bgt-delegated.tsx b/apps/hub/src/app/validators/components/charts/bgt-delegated.tsx index ab37b1515..adbba95fa 100644 --- a/apps/hub/src/app/validators/components/charts/bgt-delegated.tsx +++ b/apps/hub/src/app/validators/components/charts/bgt-delegated.tsx @@ -15,12 +15,12 @@ const CustomBgtDelegatedTooltip = ({ active, payload, label }: any) => { return (

{date.toISOString().split("T")[0]}

-

{"BGT Delegated: "}

+

{"Boosts: "}

-

{"All Time BGT Delegated: "}

+

{"All Time Boosts: "}

{ const chartConfig = { bgt: { - label: "Bgt Delegated", + label: "Boosts", color: "hsl(142, 69%, 58%)", }, } satisfies ChartConfig; @@ -59,7 +59,7 @@ export const BgtDelegated = ({
- BGT Delegated + BGT Boosted {"All Time:"} {isConnected && Number(amount) > Number(bgtDelegated) && ( - Insufficient BGT delegated + Insufficient boosts )} diff --git a/apps/hub/src/app/validators/validator/validator-overview.tsx b/apps/hub/src/app/validators/validator/validator-overview.tsx index 1b9458eff..dba81ce06 100644 --- a/apps/hub/src/app/validators/validator/validator-overview.tsx +++ b/apps/hub/src/app/validators/validator/validator-overview.tsx @@ -1,9 +1,7 @@ import { useAllValidators, usePollValidatorAllBlockStats, - usePollValidatorBlockStats, useTokenHoneyPrices, - type Token, } from "@bera/berajs"; import { FormattedNumber, Tooltip } from "@bera/shared-ui"; import { cn } from "@bera/ui"; @@ -11,11 +9,10 @@ import { Card } from "@bera/ui/card"; import { Icons } from "@bera/ui/icons"; import { Skeleton } from "@bera/ui/skeleton"; import { type Address } from "viem"; -import { useBlockNumber } from "wagmi"; -import { type ActiveIncentiveWithVault } from "~/types/validators"; -// import Uptime from "../components/charts/validator-uptime"; import { UserDelegation } from "./user-delegation"; import { ApiValidatorFragment } from "@bera/graphql/pol/api"; +import { useEffect, useState } from "react"; +import { isSameAddress } from "@berachain-foundation/berancer-sdk"; export const ValidatorDataCard = ({ title, @@ -46,13 +43,19 @@ export const ValidatorOverview = ({ (rv) => rv.receivingVault?.activeIncentives, ); - const { data: totalBlocks = 0 } = useBlockNumber(); - const { data, isLoading } = usePollValidatorBlockStats( - validator.id as Address, - ); - - const blocksSigned = - data?.blockStatsByValidators?.[0]?.allTimeBlockCount ?? 0; + const [rank, setRank] = useState<{ + validatorRank: number; + totalValidators: number; + blockSigningRank: number; + blocksSigned: number; + totalBlocks: number; + }>({ + validatorRank: -1, + totalValidators: 0, + blockSigningRank: -1, + blocksSigned: 0, + totalBlocks: 0, + }); const { data: allValidatorBlockData, @@ -62,23 +65,40 @@ export const ValidatorOverview = ({ const { data: allValidators, isLoading: isLoadingValidators } = useAllValidators(); - const totalValidators = allValidators?.validators?.length ?? 0; - let valStakedRanking = -1; - allValidators?.validators?.find((v, index: number) => { - if (v.id === validator.id.toLowerCase()) { - valStakedRanking = index + 1; - return true; - } - return; - }); + useEffect(() => { + const totalValidators = allValidators?.validators?.length ?? 0; + const valStakedRanking = allValidators?.validators?.findIndex( + (v) => v.id === validator.id.toLowerCase(), + ); - const valSignedRanking = - allValidatorBlockData?.blockStatsByValidators?.findIndex((v) => { - if (v.validator.id.toLowerCase() === validator.id.toLowerCase()) { - return true; - } - return false; - }) ?? -1; + const blocksSigned = allValidatorBlockData?.blockStatsByValidators?.reduce( + (acc, v, idx) => { + if (isSameAddress(v.validator.id, validator.id as Address)) { + return { + ...acc, + rank: idx, + blocksSigned: Number(v.blockCount), + totalBlocks: acc.totalBlocks + Number(v.blockCount), + }; + } + + return { ...acc, totalBlocks: acc.totalBlocks + Number(v.blockCount) }; + }, + { + rank: -1, + blocksSigned: 0, + totalBlocks: 0, + }, + ); + + setRank({ + validatorRank: valStakedRanking ?? -1, + totalValidators, + blockSigningRank: blocksSigned?.rank ?? -1, + blocksSigned: blocksSigned?.blocksSigned ?? 0, + totalBlocks: blocksSigned?.totalBlocks ?? 0, + }); + }, [validator.id, allValidatorBlockData, allValidators]); const activeIncentivesTokens = activeIncentivesArray?.filter( (incentive, index, array) => @@ -120,21 +140,19 @@ export const ValidatorOverview = ({ value={
- {isLoadingValidators ? ( + {isLoadingValidators || rank.validatorRank === -1 ? ( ) : ( - {valStakedRanking === -1 + {rank.validatorRank === -1 ? "Unranked" - : `${valStakedRanking} of ${totalValidators}`} + : `${rank.validatorRank + 1} of ${ + rank.totalValidators + }`} )}
- {/* TODO */} - {/* - {"+14 from last month"} - */}
} /> @@ -144,31 +162,34 @@ export const ValidatorOverview = ({ value={
- {isLoading || isLoadingValidators ? ( + {isLoadingValidators ? ( ) : ( - {valSignedRanking === -1 + {rank.blockSigningRank === -1 ? "Unranked" - : `${valSignedRanking + 1} of ${totalValidators}`} + : `${rank.blockSigningRank + 1} of ${ + rank.totalValidators + }`} )}
- {isLoading || isLoadingAllValidatorBlockData ? ( + {isLoadingAllValidatorBlockData || + rank.blockSigningRank === -1 ? ( ) : ( - All time:{" "} + Last day:{" "} {" "} /{" "} diff --git a/apps/hub/src/columns/general-validator-columns.tsx b/apps/hub/src/columns/general-validator-columns.tsx index 3a0317d53..e68bf5785 100755 --- a/apps/hub/src/columns/general-validator-columns.tsx +++ b/apps/hub/src/columns/general-validator-columns.tsx @@ -37,7 +37,7 @@ const VALIDATOR_COLUMN: ColumnDef = { }; const GLOBAL_VOTING_POWER_COLUMN: ColumnDef = { - header: "BGT Delegated", + header: "BGT Boosts", cell: ({ row }) => (
{/* */} diff --git a/packages/berajs/src/hooks/modules/pol/hooks/poll-validator-block-stats.ts b/packages/berajs/src/hooks/modules/pol/hooks/poll-validator-block-stats.ts deleted file mode 100644 index 18167a4c5..000000000 --- a/packages/berajs/src/hooks/modules/pol/hooks/poll-validator-block-stats.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { type GetValidatorBlockStatsQuery } from "@bera/graphql/pol/subgraph"; -import { mutate } from "swr"; -import useSWRImmutable from "swr/immutable"; -import { Address } from "viem"; - -import { getValidatorBlockStats } from "~/actions"; -import { useBeraJs } from "~/contexts"; -import { DefaultHookOptions, DefaultHookReturnType } from "~/types"; - -export const usePollValidatorBlockStats = ( - address: Address, - options?: DefaultHookOptions, -): DefaultHookReturnType => { - const { config: beraConfig } = useBeraJs(); - const config = options?.beraConfigOverride ?? beraConfig; - const QUERY_KEY = ["useValidatorBlockStatsSubgraph", address]; - const swrResponse = useSWRImmutable( - QUERY_KEY, - async () => { - if (!address) { - throw new Error( - "usePollValidatorBlockStats needs a valid validator address", - ); - } - return await getValidatorBlockStats({ - config, - address: address, - }); - }, - { - ...options?.opts, - }, - ); - - return { - ...swrResponse, - refresh: () => mutate(QUERY_KEY), - }; -}; diff --git a/packages/berajs/src/hooks/modules/pol/index.ts b/packages/berajs/src/hooks/modules/pol/index.ts index eb0514302..b68f51469 100644 --- a/packages/berajs/src/hooks/modules/pol/index.ts +++ b/packages/berajs/src/hooks/modules/pol/index.ts @@ -5,7 +5,6 @@ export { usePollValidatorBgtBoost } from "./hooks/poll-validator-bgt-boost"; export { usePollValidatorBgtStaked } from "./hooks/poll-validator-bgt-staked"; export { usePollValidatorBlockRewardStats } from "./hooks/poll-validator-block-rewards-stats"; -export { usePollValidatorBlockStats } from "./hooks/poll-validator-block-stats"; export { useAllValidators } from "./hooks/useAllValidators"; export { usePollValidatorTokenRewards } from "./hooks/poll-validator-token-rewards"; export { useUserActiveValidators } from "./hooks/useUserActiveValidators";