fix(governance): validator tables - user staking fixes (#3533)

This commit is contained in:
Sam Keen 2023-04-25 15:17:27 +01:00 committed by GitHub
parent 77582a62a8
commit 613582ee00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 10 deletions

View File

@ -6,6 +6,7 @@ import { usePreviousEpochQuery } from '../__generated__/PreviousEpoch';
import { ValidatorTables } from './validator-tables';
import { useRefreshAfterEpoch } from '../../../hooks/use-refresh-after-epoch';
import { useVegaWallet } from '@vegaprotocol/wallet';
import { ENV } from '../../../config';
export const EpochData = () => {
// errorPolicy due to vegaprotocol/vega issue 5898
@ -14,11 +15,23 @@ export const EpochData = () => {
data: nodesData,
error: nodesError,
loading: nodesLoading,
refetch,
refetch: nodesRefetch,
} = useNodesQuery();
const { data: userStakingData } = useStakingQuery({
const { delegationsPagination } = ENV;
const {
data: userStakingData,
error: userStakingError,
loading: userStakingLoading,
refetch: userStakingRefetch,
} = useStakingQuery({
variables: {
partyId: pubKey || '',
delegationsPagination: delegationsPagination
? {
first: Number(delegationsPagination),
}
: undefined,
},
});
const { data: previousEpochData } = usePreviousEpochQuery({
@ -28,10 +41,17 @@ export const EpochData = () => {
skip: !nodesData?.epoch.id,
});
useRefreshAfterEpoch(nodesData?.epoch.timestamps.expiry, refetch);
useRefreshAfterEpoch(nodesData?.epoch.timestamps.expiry, () => {
nodesRefetch();
userStakingRefetch();
});
return (
<AsyncRenderer loading={nodesLoading} error={nodesError} data={nodesData}>
<AsyncRenderer
loading={nodesLoading || userStakingLoading}
error={nodesError || userStakingError}
data={nodesData}
>
{nodesData?.epoch &&
nodesData.epoch.timestamps.start &&
nodesData?.epoch.timestamps.expiry && (

View File

@ -211,7 +211,7 @@ export const ConsensusValidatorsTable = ({
: undefined,
[ValidatorFields.PENDING_USER_STAKE]: pendingUserStake,
[ValidatorFields.USER_STAKE_SHARE]: userStakeShare
? stakedTotalPercentage(userStakeShare)
? formatNumberPercentage(new BigNumber(userStakeShare))
: undefined,
};
}

View File

@ -59,9 +59,9 @@ export const addUserDataToValidator = (
: undefined,
[ValidatorFields.USER_STAKE_SHARE]:
currentEpochUserStaking && Number(currentEpochUserStaking.amount) > 0
? new BigNumber(currentEpochUserStaking.amount).dividedBy(
new BigNumber(currentUserStakeAvailable)
)
? new BigNumber(currentEpochUserStaking.amount)
.dividedBy(new BigNumber(currentUserStakeAvailable))
.times(100)
: undefined,
};
};

View File

@ -26,7 +26,11 @@ import {
import type { AgGridReact } from 'ag-grid-react';
import type { ColDef } from 'ag-grid-community';
import type { ValidatorsTableProps } from './shared';
import { formatNumber, toBigNum } from '@vegaprotocol/utils';
import {
formatNumber,
formatNumberPercentage,
toBigNum,
} from '@vegaprotocol/utils';
interface StandbyPendingValidatorsTableProps extends ValidatorsTableProps {
stakeNeededForPromotion: string | undefined;
@ -163,7 +167,7 @@ export const StandbyPendingValidatorsTable = ({
: undefined,
[ValidatorFields.PENDING_USER_STAKE]: pendingUserStake,
[ValidatorFields.USER_STAKE_SHARE]: userStakeShare
? stakedTotalPercentage(userStakeShare)
? formatNumberPercentage(new BigNumber(userStakeShare))
: undefined,
};
}