Skip to content

Commit

Permalink
fix last epoch rewards (MystenLabs#9851)
Browse files Browse the repository at this point in the history
## Description 

Describe the changes or additions included in this PR.

Add epoch rewards to the validator page

<img width="1492" alt="Screenshot 2023-03-24 at 3 29 34 PM"
src="https://user-images.githubusercontent.com/126525197/227622554-4b0e7bf8-57e6-413d-b42b-4b92c2d53530.png">

## Test Plan 

How did you test the new or updated feature?

---
If your changes are not user-facing and not a breaking change, you can
skip the following section. Otherwise, please indicate what changed, and
then add to the Release Notes section as highlighted during the release
process.

### Type of Change (Check all that apply)

- [ ] user-visible impact
- [ ] breaking change for a client SDKs
- [ ] breaking change for FNs (FN binary must upgrade)
- [ ] breaking change for validators or node operators (must upgrade
binaries)
- [ ] breaking change for on-chain data layout
- [ ] necessitate either a data wipe or data migration

### Release notes
Jibz-Mysten authored Mar 24, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent da34b28 commit b1fb38c
Showing 4 changed files with 13 additions and 11 deletions.
5 changes: 2 additions & 3 deletions apps/explorer/src/components/validator/ValidatorStats.tsx
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ import { Stats } from '~/ui/Stats';
type StatsCardProps = {
validatorData: SuiValidatorSummary;
epoch: number | string;
epochRewards: string;
epochRewards: number;
};

export function ValidatorStats({
@@ -68,8 +68,7 @@ export function ValidatorStats({
<div className="flex flex-col gap-8 lg:flex-row">
<Stats
label="Commission"
tooltip="Coming soon"
unavailable={commission <= 0}
tooltip="Fee charged by the validator for staking services"
>
<Heading
as="h3"
3 changes: 2 additions & 1 deletion apps/explorer/src/hooks/useGetValidatorsEvents.ts
Original file line number Diff line number Diff line change
@@ -5,7 +5,8 @@ import { useRpcClient } from '@mysten/core';
import { type PaginatedEvents, type EventId } from '@mysten/sui.js';
import { useQuery, type UseQueryResult } from '@tanstack/react-query';

export const VALIDATORS_EVENTS_QUERY = '0x3::validator_set::ValidatorEpochInfo';
export const VALIDATORS_EVENTS_QUERY =
'0x3::validator_set::ValidatorEpochInfoEvent';

type GetValidatorsEvent = {
cursor?: EventId | null;
8 changes: 5 additions & 3 deletions apps/explorer/src/pages/validator/ValidatorDetails.tsx
Original file line number Diff line number Diff line change
@@ -31,9 +31,11 @@ function ValidatorDetails() {

const validatorRewards = useMemo(() => {
if (!validatorEvents || !id) return 0;
return (
getValidatorMoveEvent(validatorEvents.data, id)?.stake_rewards || 0
);
const rewards = getValidatorMoveEvent(
validatorEvents.data,
id
)?.pool_staking_reward;
return +rewards || 0;
}, [id, validatorEvents]);

if (isLoading || validatorsEventsLoading) {
8 changes: 4 additions & 4 deletions apps/explorer/src/pages/validators/Validators.tsx
Original file line number Diff line number Diff line change
@@ -51,7 +51,7 @@ export function validatorsTableData(
commission: +validator.commissionRate / 100,
img: img,
address: validator.suiAddress,
lastReward: event?.stake_rewards || 0,
lastReward: +event?.pool_staking_reward || 0,
atRisk: systemState.atRiskValidators.some(
([address]) => address === validator.suiAddress
),
@@ -138,7 +138,7 @@ export function validatorsTableData(
const commissionRate = props.getValue();
return (
<Text variant="bodySmall/medium" color="steel-darker">
{commissionRate > 0 ? `${commissionRate}%` : '--'}
{commissionRate}%
</Text>
);
},
@@ -149,7 +149,7 @@ export function validatorsTableData(
cell: (props: any) => {
const lastReward = props.getValue();
return lastReward > 0 ? (
<StakeColumn stake={lastReward} hideCoinSymbol />
<StakeColumn stake={lastReward} />
) : (
<Text variant="bodySmall/medium" color="steel-darker">
--
@@ -223,7 +223,7 @@ function ValidatorPageResult() {
let totalRewards = 0;

validatorEvents.data.forEach(({ parsedJson }) => {
totalRewards += +parsedJson!.stake_rewards;
totalRewards += +parsedJson!.pool_staking_reward;
});

return totalRewards;

0 comments on commit b1fb38c

Please sign in to comment.