Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement rewards calculator and merge payout history #2482

Open
wants to merge 31 commits into
base: main
Choose a base branch
from

Conversation

joeljkrb
Copy link
Contributor

@joeljkrb joeljkrb commented Feb 3, 2025

This PR implements a new Rewards Calculator feature and merges it with the Payout History into a single tabbed interface.

Key changes:

  • Create new Rewards Calculator tool with real-time calculations
  • Migrate Payout History to new tabbed interface
  • Add number formatting with locale support
  • Update translations for Spanish and English locales (Chinese pending review)

This enhances both reward projection capabilities and historical tracking in a unified interface.

Addresses #1821

- Create tabbed Rewards Calculator page
- Move PayoutHistory to Rewards Calculator
- Refactor components into Graph, Stats, PayoutList
- Add history tab alongside rewards calculator
- Update imports and file structure
- Removal of Payouts page
- Creation of Rewards & Payouts
- Add English & Spanish translation for updated menu item
- Ting to review /cn/base.json & pages.json
@rossbulat
Copy link
Collaborator

Just making a note of next steps; to finalise the Stats that will be displayed at the top of the current Calculator page, both with Staking API enabled and disabled.

We can leverage historical data with Staking API to get reward estimations based on historical performance. With the API disabled, we can derive stats based on chain state available on-chain at the current era.

Note for Ross: Revise Stat ui components to enable a calculator stat-as-a-button.

Copy link
Collaborator

@rossbulat rossbulat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I correct in assuming that everything from pages/Payouts has been duplicated into pages/Rewards? If so, pages/Payouts can be deleted.

return (
<Wrapper>
<PageTitle
title={t('rewards.rewardsCalculator')}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Page title can just be Rewards

title={t('rewards.rewardsCalculator')}
tabs={[
{
title: t('rewards.calculator'),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This page can be Overview. The payout history graph currently present in "Payout History" tab can be displayed at this top of this page, with the new "Projected Rewards" module being displayed below it.

The Payout History tab can then just list historical payout records.

step="0.01"
value={manualStake ?? ''}
onChange={(e) =>
setManualStake(Number(e.target.value) || null)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can currently enter values less than 0. We can default to 0 on non-number & enforce a minimum of 0:

Suggested change
setManualStake(Number(e.target.value) || null)
const value = Number(e.target.value)
const newManualStake = isNaN(value) ? 0 : Math.max(0, value)
setManualStake(newManualStake)

padding: '0.5rem',
marginTop: '0.5rem',
border: '1px solid var(--border-primary-color)',
borderRadius: '4px',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use a rem value here so all styling is in proportion to the global font size.

Suggested change
borderRadius: '4px',
borderRadius: '0.5rem',

import { CardHeader, PageRow, StatRow } from 'ui-core/base'
import { RewardText, RewardsGrid } from '../Wrappers'

export const Active = () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename this component and its folder to Overview.

Suggested change
export const Active = () => {
export const Overview = () => {

import { ItemWrapper } from '../Wrappers'
import type { PayoutListProps } from '../types'

export const PayoutListInner = ({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export const PayoutListInner = ({
export const PayoutHistoryInner = ({

)
}

export const PayoutList = (props: PayoutListProps) => (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export const PayoutList = (props: PayoutListProps) => (
export const PayoutHistory = (props: PayoutHistoryProps) => (

title,
payouts: initialPayouts,
itemsPerPage,
}: PayoutListProps) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}: PayoutListProps) => {
}: PayoutHistoryProps) => {

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename to RecentPayouts

import { PayoutList } from './PayoutList'
import { LastEraPayout } from './Stats/LastEraPayout'

export const PayoutHistory = () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export const PayoutHistory = () => {
export const RecentPayouts = () => {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: ✂️ In progress
Development

Successfully merging this pull request may close these issues.

2 participants