Skip to content

Commit

Permalink
feat: add total rewards
Browse files Browse the repository at this point in the history
  • Loading branch information
xrypto.c committed Oct 11, 2024
1 parent e4c162f commit 8498cf2
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions packages/page-staking/src/Overview/MainnetRewards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,31 @@ interface Props {

const UNIT = new BN(1_000_000_000_000)

async function getAllRewards(idx: number): Promise<number> {
const { api } = useApi();

// erasStakingPayout
const erasp = await api.query.staking.erasStakingPayout(idx);

const erasStakingPayout = JSON.parse(JSON.stringify(erasp));
// console.log(`erasStakingPayout: ${idx}: ${erasStakingPayout}`);

// erasAuthoringPayout
const keys = await api.query.staking.erasAuthoringPayout.keys(idx);

let totalValue = new BN(0);

for (const key of keys) {
const [_, accountId] = key.args;
const value = await api.query.staking.erasAuthoringPayout(idx, accountId);
totalValue = totalValue.add(new BN(value.toString()));
}

// console.log(`erasAuthoringPayout ${idx}: ${totalValue.toString()}`);

return totalValue.add(new BN(erasStakingPayout as string)).div(UNIT).toNumber();
}

function MainnetReward ({ children, className = '', label }: Props): React.ReactElement<Props> {
const { api } = useApi();
const { t } = useTranslation();
Expand All @@ -31,6 +56,10 @@ function MainnetReward ({ children, className = '', label }: Props): React.React
const stakingRewards = new BN(3011.635871031734).mul(UNIT)
const total = marketPayout && stakingRewards.add(new BN(Number(marketPayout).toString()))

getAllRewards(activeEra as number - 1).then((res) => {
console.log("================> getAllRewards: ", res);
})

return (
<div className={className}>
{label || ''}
Expand Down

0 comments on commit 8498cf2

Please sign in to comment.