fix(governance): reward aggregation for validator types (#3773)
This commit is contained in:
parent
4a7296312a
commit
aa2b755b93
@ -79,7 +79,24 @@ export const generateEpochIndividualRewardsList = ({
|
|||||||
epoch?.rewards.push(asset);
|
epoch?.rewards.push(asset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!asset.rewardTypes[rewardType]) {
|
||||||
asset.rewardTypes[rewardType] = { amount, percentageOfTotal };
|
asset.rewardTypes[rewardType] = { amount, percentageOfTotal };
|
||||||
|
} else {
|
||||||
|
const previousAmount = asset.rewardTypes[rewardType]?.amount;
|
||||||
|
const previousPercentageOfTotal =
|
||||||
|
asset.rewardTypes[rewardType]?.percentageOfTotal;
|
||||||
|
|
||||||
|
asset.rewardTypes[rewardType] = {
|
||||||
|
amount: previousAmount
|
||||||
|
? new BigNumber(previousAmount).plus(amount).toString()
|
||||||
|
: amount,
|
||||||
|
percentageOfTotal: previousPercentageOfTotal
|
||||||
|
? new BigNumber(previousPercentageOfTotal)
|
||||||
|
.plus(percentageOfTotal)
|
||||||
|
.toString()
|
||||||
|
: percentageOfTotal,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// totalAmount is the sum of all rewardTypes amounts
|
// totalAmount is the sum of all rewardTypes amounts
|
||||||
asset.totalAmount = Object.values(asset.rewardTypes).reduce(
|
asset.totalAmount = Object.values(asset.rewardTypes).reduce(
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { useEffect, useState } from 'react';
|
||||||
import { ENV } from '../../../config';
|
import { ENV } from '../../../config';
|
||||||
import { Callout, Intent, Splash } from '@vegaprotocol/ui-toolkit';
|
import { Callout, Intent, Splash } from '@vegaprotocol/ui-toolkit';
|
||||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
import { useVegaWallet } from '@vegaprotocol/wallet';
|
||||||
@ -28,6 +29,7 @@ export const NodeContainer = ({
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { pubKey } = useVegaWallet();
|
const { pubKey } = useVegaWallet();
|
||||||
const { delegationsPagination } = ENV;
|
const { delegationsPagination } = ENV;
|
||||||
|
|
||||||
const { data, loading, error, refetch } = useStakingQuery({
|
const { data, loading, error, refetch } = useStakingQuery({
|
||||||
variables: {
|
variables: {
|
||||||
partyId: pubKey || '',
|
partyId: pubKey || '',
|
||||||
@ -38,6 +40,20 @@ export const NodeContainer = ({
|
|||||||
: undefined,
|
: undefined,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const [isRefetching, setIsRefetching] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (error && error.message.includes('failed to get party for ID')) {
|
||||||
|
setIsRefetching(true);
|
||||||
|
// The API errors if there is a pubkey, but it hasn't interacted with the
|
||||||
|
// chain before. In that case, retry the query with empty pubKey
|
||||||
|
refetch({
|
||||||
|
partyId: '',
|
||||||
|
}).finally(() => setIsRefetching(false));
|
||||||
|
}
|
||||||
|
}, [error, refetch, delegationsPagination]);
|
||||||
|
|
||||||
const { data: previousEpochData } = usePreviousEpochQuery({
|
const { data: previousEpochData } = usePreviousEpochQuery({
|
||||||
variables: {
|
variables: {
|
||||||
epochId: (Number(data?.epoch.id) - 1).toString(),
|
epochId: (Number(data?.epoch.id) - 1).toString(),
|
||||||
@ -47,7 +63,7 @@ export const NodeContainer = ({
|
|||||||
|
|
||||||
useRefreshAfterEpoch(data?.epoch.timestamps.expiry, refetch);
|
useRefreshAfterEpoch(data?.epoch.timestamps.expiry, refetch);
|
||||||
|
|
||||||
if (error) {
|
if (error && !isRefetching) {
|
||||||
return (
|
return (
|
||||||
<Callout intent={Intent.Danger} title={t('Something went wrong')}>
|
<Callout intent={Intent.Danger} title={t('Something went wrong')}>
|
||||||
<pre>
|
<pre>
|
||||||
@ -59,7 +75,7 @@ export const NodeContainer = ({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (loading) {
|
if (loading || isRefetching) {
|
||||||
return (
|
return (
|
||||||
<Splash>
|
<Splash>
|
||||||
<SplashLoader />
|
<SplashLoader />
|
||||||
|
Loading…
Reference in New Issue
Block a user