Skip to content

Commit

Permalink
fix(vp): unboost amounts
Browse files Browse the repository at this point in the history
  • Loading branch information
bearpong committed Dec 18, 2024
1 parent 6b9142a commit c64960a
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 53 deletions.
2 changes: 1 addition & 1 deletion apps/hub/src/app/validators/validator/unbond-modal.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState } from "react";
import { UserValidator, useUserBoostsOnValidator } from "@bera/berajs";
import { useUserBoostsOnValidator } from "@bera/berajs";
import { Button } from "@bera/ui/button";
import { Dialog, DialogContent } from "@bera/ui/dialog";

Expand Down
16 changes: 8 additions & 8 deletions apps/hub/src/app/validators/validator/undelegate-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
type UserValidator,
useBeraJs,
useUserActiveValidators,
useUserBoostsOnValidator,
} from "@bera/berajs";
import { bgtTokenAddress } from "@bera/config";
import { ActionButton, useTxn } from "@bera/shared-ui";
Expand All @@ -32,7 +33,10 @@ export const UnDelegateContent = ({
const t = theme === "system" ? systemTheme : theme;

const [amount, setAmount] = React.useState<string | undefined>(undefined);
const { data, refresh } = useUserActiveValidators();

const { data: userBoosts, refresh } = useUserBoostsOnValidator({
pubkey: validator?.pubkey as Address,
});

const {
write: unbondWrite,
Expand All @@ -51,13 +55,9 @@ export const UnDelegateContent = ({
},
});

const selectedValidator = data?.find(
(v) => v.pubkey.toLowerCase() === validator.pubkey.toLowerCase(),
);

const bgtDelegated = selectedValidator
? selectedValidator.userBoosts.activeBoosts
: "0";
const bgtDelegated = userBoosts
? Number(userBoosts?.activeBoosts) - Number(userBoosts.queuedUnboosts)
: 0;

return (
<div>
Expand Down
44 changes: 34 additions & 10 deletions apps/hub/src/columns/general-validator-columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,11 @@ const CLAIMABLE_BRIBES_COLUMN: ColumnDef<ValidatorWithUserBoost> = {
enableSorting: false,
};

const USER_STAKED_COLUMN: ColumnDef<ValidatorWithUserBoost> = {
const USER_BOOSTED_COLUMN: ColumnDef<ValidatorWithUserBoost> = {
header: ({ column }) => (
<DataTableColumnHeader
column={column}
title="User Staked"
title="Boosts"
className="whitespace-nowrap"
/>
),
Expand All @@ -161,14 +161,14 @@ const USER_STAKED_COLUMN: ColumnDef<ValidatorWithUserBoost> = {
sortingFn: (a, b) =>
Number(a.original.userBoosts.activeBoosts) -
Number(b.original.userBoosts.activeBoosts),
enableSorting: false,
enableSorting: true,
};

const USER_QUEUED_COLUMN: ColumnDef<ValidatorWithUserBoost> = {
const USER_QUEUED_BOOSTS_COLUMN: ColumnDef<ValidatorWithUserBoost> = {
header: ({ column }) => (
<DataTableColumnHeader
column={column}
title="User Queued"
title="Queued Boosts"
className="whitespace-nowrap"
/>
),
Expand All @@ -184,7 +184,31 @@ const USER_QUEUED_COLUMN: ColumnDef<ValidatorWithUserBoost> = {
sortingFn: (a, b) =>
Number(a.original.userBoosts?.queuedBoosts) -
Number(b.original.userBoosts?.queuedBoosts),
enableSorting: false,
enableSorting: true,
};

const USER_QUEUED_DROP_BOOSTS_COLUMN: ColumnDef<ValidatorWithUserBoost> = {
header: ({ column }) => (
<DataTableColumnHeader
column={column}
title="Queued Unboosts"
className="whitespace-nowrap"
/>
),
cell: ({ row }) => {
return (
<FormattedNumber
value={-(row.original.userBoosts?.queuedUnboosts ?? 0)}
symbol="BGT"
colored
/>
);
},
accessorKey: "userBoosts.queuedUnboosts",
sortingFn: (a, b) =>
Number(a.original.userBoosts?.queuedUnboosts) -
Number(b.original.userBoosts?.queuedUnboosts),
enableSorting: true,
};

export const getGaugeValidatorColumns = (rewardVault: ApiVaultFragment) => {
Expand Down Expand Up @@ -316,16 +340,16 @@ export const generalValidatorColumns: ColumnDef<ApiValidatorFragment>[] = [
export const user_general_validator_columns: ColumnDef<ValidatorWithUserBoost>[] =
[
VALIDATOR_COLUMN as ColumnDef<ValidatorWithUserBoost>,
USER_STAKED_COLUMN,
USER_QUEUED_COLUMN,
GLOBAL_VOTING_POWER_COLUMN as ColumnDef<ValidatorWithUserBoost>,
USER_BOOSTED_COLUMN,
USER_QUEUED_BOOSTS_COLUMN,
USER_QUEUED_DROP_BOOSTS_COLUMN,
{ ...APY_COLUMN, enableSorting: true } as ColumnDef<ValidatorWithUserBoost>,
BRIBES_COLUMN,
];

export const user_incentives_columns: ColumnDef<ValidatorWithUserBoost>[] = [
VALIDATOR_COLUMN as ColumnDef<ValidatorWithUserBoost>,
USER_STAKED_COLUMN,
USER_BOOSTED_COLUMN,
APY_COLUMN as ColumnDef<ValidatorWithUserBoost>,
CLAIMABLE_BRIBES_COLUMN,
];
66 changes: 32 additions & 34 deletions apps/hub/src/components/validator-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
useBeraJs,
useBgtUnstakedBalance,
useUserActiveValidators,
useUserBoostsOnValidator,
type UserValidator,
} from "@bera/berajs";
import { FormattedNumber, Tooltip } from "@bera/shared-ui";
Expand Down Expand Up @@ -43,15 +44,14 @@ export default function ValidatorInput({
const { isReady } = useBeraJs();
const { data: bgtBalance } = useBgtUnstakedBalance();

const { data } = useUserActiveValidators();
const { data: userBoosts } = useUserBoostsOnValidator({
pubkey: validatorAddress,
});

const bgtDelegated = userBoosts
? Number(userBoosts?.activeBoosts) - Number(userBoosts.queuedUnboosts)
: 0;

const selectedValidator = data?.find(
(validator) =>
validator.pubkey.toLowerCase() === validatorAddress?.toLowerCase(),
);
const bgtDelegated = selectedValidator
? selectedValidator.userBoosts.activeBoosts
: "0";
return (
<div className="relative">
<div
Expand Down Expand Up @@ -102,34 +102,32 @@ export default function ValidatorInput({
</div>
)}

{action !== DelegateEnum.DELEGATE &&
validatorAddress &&
Boolean(bgtDelegated) && (
<div className="absolute bottom-3 right-4 h-3 text-[10px] text-muted-foreground">
<div className="flex items-center gap-1">
{/* <ValidatorIcon className="h-6 w-6" address={validatorAddress} /> */}
<Tooltip
text="Amount of BGT boosted to this validator"
className="h-3 w-3"
/>
{action !== DelegateEnum.DELEGATE && validatorAddress && (
<div className="absolute bottom-3 right-4 h-3 text-[10px] text-muted-foreground">
<div className="flex items-center gap-1">
{/* <ValidatorIcon className="h-6 w-6" address={validatorAddress} /> */}
<Tooltip
text="Amount of BGT boosted to this validator, excluding queued unboosts"
className="h-3 w-3"
/>

<FormattedNumber
value={bgtDelegated}
compact
symbol="BGT"
showIsSmallerThanMin
/>
<span
className="underline hover:cursor-pointer"
onClick={() => {
if (bgtDelegated) onAmountChange(bgtDelegated);
}}
>
MAX
</span>
</div>
<FormattedNumber
value={bgtDelegated}
compact
symbol="BGT"
showIsSmallerThanMin
/>
<span
className="underline hover:cursor-pointer"
onClick={() => {
if (bgtDelegated) onAmountChange(bgtDelegated.toString());
}}
>
MAX
</span>
</div>
)}
</div>
)}
</div>
);
}

0 comments on commit c64960a

Please sign in to comment.