Skip to content

Commit

Permalink
fix(pol): val ranking and boost naming
Browse files Browse the repository at this point in the history
  • Loading branch information
bearpong committed Dec 18, 2024
1 parent a8dddda commit 6b9142a
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export function VoteDialog({
</DialogHeader>
<div className="flex w-full items-center justify-center">
<p className="text-3xl font-semibold">{votingPower}</p>
<p className="text-sm font-medium">BGT delegated</p>
<p className="text-sm font-medium">Boosts</p>
</div>

<div className="flex w-full flex-col items-center justify-center">
Expand Down
4 changes: 2 additions & 2 deletions apps/hub/src/app/incentivize/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
5 changes: 3 additions & 2 deletions apps/hub/src/app/validators/components/boost-queue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,9 @@ const ConfirmationCard = ({
showIsSmallerThanMin
value={userValidator.type === "boost" ? amount : -Number(amount)}
compact
/>{" "}
BGT
colored
symbol="BGT"
/>
</div>
</div>
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ const CustomBgtDelegatedTooltip = ({ active, payload, label }: any) => {
return (
<div className="flex min-w-[8rem] flex-col items-start gap-1.5 rounded-md border border-border/50 bg-background px-2.5 py-1.5 text-xs shadow-xl">
<p className="">{date.toISOString().split("T")[0]}</p>
<p className="">{"BGT Delegated: "}</p>
<p className="">{"Boosts: "}</p>
<FormattedNumber
value={payload[0].payload.bgtStaked}
className="text-sm font-semibold text-foreground"
/>
<p className="">{"All Time BGT Delegated: "}</p>
<p className="">{"All Time Boosts: "}</p>
<FormattedNumber
value={payload[0].payload.allTimeBGTStaked}
className="text-sm font-semibold text-foreground"
Expand All @@ -39,7 +39,7 @@ export const BgtDelegated = ({
}) => {
const chartConfig = {
bgt: {
label: "Bgt Delegated",
label: "Boosts",
color: "hsl(142, 69%, 58%)",
},
} satisfies ChartConfig;
Expand All @@ -59,7 +59,7 @@ export const BgtDelegated = ({
<div className="flex w-full flex-col gap-12 p-4">
<div className="flex items-center gap-1">
<Icons.bgt className="h-4 w-4" />
<span className="text-md mr-2 font-semibold">BGT Delegated</span>
<span className="text-md mr-2 font-semibold">BGT Boosted</span>
<span className="text-sm text-muted-foreground">{"All Time:"}</span>
<FormattedNumber
value={lastRecordedUsage ? lastRecordedUsage?.allTimeBGTStaked : ""}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export const UnDelegateContent = ({
/>

{isConnected && Number(amount) > Number(bgtDelegated) && (
<Alert variant="destructive">Insufficient BGT delegated</Alert>
<Alert variant="destructive">Insufficient boosts</Alert>
)}

<ActionButton>
Expand Down
105 changes: 63 additions & 42 deletions apps/hub/src/app/validators/validator/validator-overview.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
import {
useAllValidators,
usePollValidatorAllBlockStats,
usePollValidatorBlockStats,
useTokenHoneyPrices,
type Token,
} from "@bera/berajs";
import { FormattedNumber, Tooltip } from "@bera/shared-ui";
import { cn } from "@bera/ui";
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,
Expand Down Expand Up @@ -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,
Expand All @@ -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) =>
Expand Down Expand Up @@ -120,21 +140,19 @@ export const ValidatorOverview = ({
value={
<div className="flex flex-col items-start gap-1">
<div className="relative flex w-full flex-row justify-between">
{isLoadingValidators ? (
{isLoadingValidators || rank.validatorRank === -1 ? (
<Skeleton className="mt-1 h-8 w-40" />
) : (
<span className="text-2xl font-semibold">
{valStakedRanking === -1
{rank.validatorRank === -1
? "Unranked"
: `${valStakedRanking} of ${totalValidators}`}
: `${rank.validatorRank + 1} of ${
rank.totalValidators
}`}
</span>
)}
<Icons.logo className="absolute right-0 h-16 w-16 self-center text-muted" />
</div>
{/* TODO */}
{/* <span className="overflow-hidden text-ellipsis whitespace-nowrap text-sm text-muted-foreground">
{"+14 from last month"}
</span> */}
</div>
}
/>
Expand All @@ -144,31 +162,34 @@ export const ValidatorOverview = ({
value={
<div className="flex flex-col items-start gap-1">
<div className="relative flex w-full flex-row justify-between">
{isLoading || isLoadingValidators ? (
{isLoadingValidators ? (
<Skeleton className="mt-1 h-8 w-44" />
) : (
<span className="text-2xl font-semibold">
{valSignedRanking === -1
{rank.blockSigningRank === -1
? "Unranked"
: `${valSignedRanking + 1} of ${totalValidators}`}
: `${rank.blockSigningRank + 1} of ${
rank.totalValidators
}`}
</span>
)}
<Icons.cube className="absolute right-0 h-16 w-16 self-center text-muted" />
</div>

{isLoading || isLoadingAllValidatorBlockData ? (
{isLoadingAllValidatorBlockData ||
rank.blockSigningRank === -1 ? (
<Skeleton className="mt-1 h-4 w-full" />
) : (
<span className="overflow-hidden text-ellipsis whitespace-nowrap text-sm text-muted-foreground">
All time:{" "}
Last day:{" "}
<FormattedNumber
value={blocksSigned}
value={rank.blocksSigned}
compact
showIsSmallerThanMin
/>{" "}
/{" "}
<FormattedNumber
value={Number(totalBlocks)}
value={rank.totalBlocks}
compact
showIsSmallerThanMin
/>
Expand Down
2 changes: 1 addition & 1 deletion apps/hub/src/columns/general-validator-columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const VALIDATOR_COLUMN: ColumnDef<ApiValidatorFragment> = {
};

const GLOBAL_VOTING_POWER_COLUMN: ColumnDef<ApiValidatorFragment> = {
header: "BGT Delegated",
header: "BGT Boosts",
cell: ({ row }) => (
<div className="w-full text-start">
<FormattedNumber
Expand Down
2 changes: 1 addition & 1 deletion apps/hub/src/components/validator-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export default function ValidatorInput({
<div className="flex items-center gap-1">
{/* <ValidatorIcon className="h-6 w-6" address={validatorAddress} /> */}
<Tooltip
text="Amount of BGT delegated to this validator"
text="Amount of BGT boosted to this validator"
className="h-3 w-3"
/>

Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion packages/berajs/src/hooks/modules/pol/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit 6b9142a

Please sign in to comment.