Skip to content

Commit 62bff1f

Browse files
committed
feat: support total rewards
1 parent 32da2f1 commit 62bff1f

8 files changed

Lines changed: 134 additions & 42 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { screen } from '@testing-library/react';
2+
3+
import { renderComponent } from 'testUtils/render';
4+
5+
import { TotalRewardsSection } from '..';
6+
7+
describe('pages/PrimeLeaderboard/TotalRewardsSection', () => {
8+
it('renders the total Prime rewards from the data hook', () => {
9+
renderComponent(<TotalRewardsSection />);
10+
11+
expect(screen.getByText('Total Prime rewards distributed this cycle')).toBeInTheDocument();
12+
expect(screen.getByText('$462.3K')).toBeInTheDocument();
13+
});
14+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { TotalRewardsCard } from '../TotalRewardsCard';
2+
import { useGetPrimeTotalRewards } from '../useGetPrimeTotalRewards';
3+
4+
export interface TotalRewardsSectionProps {
5+
className?: string;
6+
}
7+
8+
export const TotalRewardsSection: React.FC<TotalRewardsSectionProps> = ({ className }) => {
9+
const { totalRewardsCents, marketRewards } = useGetPrimeTotalRewards();
10+
11+
return (
12+
<TotalRewardsCard
13+
totalRewardsCents={totalRewardsCents}
14+
marketRewards={marketRewards}
15+
className={className}
16+
/>
17+
);
18+
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { screen } from '@testing-library/react';
2+
3+
import { renderComponent } from 'testUtils/render';
4+
5+
import { UserRewardsSection } from '..';
6+
7+
describe('pages/PrimeLeaderboard/UserRewardsSection', () => {
8+
it('renders the user Prime rewards from the data hook', () => {
9+
renderComponent(<UserRewardsSection />);
10+
11+
expect(screen.getByText('Your Prime rewards this cycle')).toBeInTheDocument();
12+
expect(screen.getByText('$18.4K')).toBeInTheDocument();
13+
});
14+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { UserRewardsCard } from '../UserRewardsCard';
2+
import { useGetPrimeUserRewards } from '../useGetPrimeUserRewards';
3+
4+
export interface UserRewardsSectionProps {
5+
className?: string;
6+
}
7+
8+
export const UserRewardsSection: React.FC<UserRewardsSectionProps> = ({ className }) => {
9+
const { totalRewardsCents, marketRewards } = useGetPrimeUserRewards();
10+
11+
return (
12+
<UserRewardsCard
13+
totalRewardsCents={totalRewardsCents}
14+
marketRewards={marketRewards}
15+
className={className}
16+
/>
17+
);
18+
};

apps/evm/src/pages/PrimeLeaderboard/__tests__/index.spec.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ vi.mock('../EndOfCycle', () => ({
1717
EndOfCycle: () => <div data-testid="end-of-cycle" />,
1818
}));
1919

20-
vi.mock('../TotalRewardsCard', () => ({
21-
TotalRewardsCard: () => <div data-testid="total-rewards-card" />,
20+
vi.mock('../TotalRewardsSection', () => ({
21+
TotalRewardsSection: () => <div data-testid="total-rewards-section" />,
2222
}));
2323

24-
vi.mock('../UserRewardsCard', () => ({
25-
UserRewardsCard: () => <div data-testid="user-rewards-card" />,
24+
vi.mock('../UserRewardsSection', () => ({
25+
UserRewardsSection: () => <div data-testid="user-rewards-section" />,
2626
}));
2727

2828
vi.mock('../RewardTable', () => ({
@@ -43,8 +43,8 @@ describe('pages/PrimeLeaderboard', () => {
4343

4444
expect(screen.getByTestId('hero')).toBeInTheDocument();
4545
expect(screen.getByTestId('end-of-cycle')).toBeInTheDocument();
46-
expect(screen.getByTestId('total-rewards-card')).toBeInTheDocument();
47-
expect(screen.getByTestId('user-rewards-card')).toBeInTheDocument();
46+
expect(screen.getByTestId('total-rewards-section')).toBeInTheDocument();
47+
expect(screen.getByTestId('user-rewards-section')).toBeInTheDocument();
4848
expect(screen.getByTestId('reward-table')).toBeInTheDocument();
4949
expect(screen.getByTestId('rank-card')).toBeInTheDocument();
5050
expect(screen.getByTestId('rank-table')).toBeInTheDocument();
@@ -53,7 +53,7 @@ describe('pages/PrimeLeaderboard', () => {
5353
it('hides the user rewards card when the wallet is not connected', () => {
5454
renderComponent(<PrimeLeaderboard />);
5555

56-
expect(screen.getByTestId('total-rewards-card')).toBeInTheDocument();
57-
expect(screen.queryByTestId('user-rewards-card')).not.toBeInTheDocument();
56+
expect(screen.getByTestId('total-rewards-section')).toBeInTheDocument();
57+
expect(screen.queryByTestId('user-rewards-section')).not.toBeInTheDocument();
5858
});
5959
});

apps/evm/src/pages/PrimeLeaderboard/index.tsx

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,16 @@
11
import { Card, Page } from 'components';
2-
import { useGetTokens } from 'libs/tokens';
32
import { useAccountAddress } from 'libs/wallet';
43

54
import { EndOfCycle } from './EndOfCycle';
65
import { Hero } from './Hero';
76
import { RankCard } from './RankCard';
87
import { RankTable } from './RankTable';
98
import { RewardTable } from './RewardTable';
10-
import { TotalRewardsCard } from './TotalRewardsCard';
11-
import { UserRewardsCard } from './UserRewardsCard';
12-
13-
// TODO: use the reward pool data returned by the API
14-
const placeholderTotalRewardsCents = 46_230_000;
15-
const placeholderUserRewardsCents = 1_840_000;
16-
const placeholderMarketRewardsCents = [28_040_000, 17_190_000];
17-
const placeholderApyPercentage = 3.78;
9+
import { TotalRewardsSection } from './TotalRewardsSection';
10+
import { UserRewardsSection } from './UserRewardsSection';
1811

1912
const PrimeLeaderboard: React.FC = () => {
2013
const { accountAddress } = useAccountAddress();
21-
const tokens = useGetTokens();
22-
23-
// TODO: replace these placeholder tokens (currently the first tokens from the list, unrelated
24-
// to the actual Prime reward markets) with the real markets returned by the API
25-
const marketRewards = tokens
26-
.slice(0, placeholderMarketRewardsCents.length)
27-
.map((token, index) => ({ token, rewardsCents: placeholderMarketRewardsCents[index] }));
28-
29-
const userMarketRewards = marketRewards.map(reward => ({
30-
...reward,
31-
apyPercentage: placeholderApyPercentage,
32-
}));
33-
34-
const totalRewardsCard = (
35-
<TotalRewardsCard
36-
totalRewardsCents={placeholderTotalRewardsCents}
37-
marketRewards={marketRewards}
38-
/>
39-
);
4014

4115
return (
4216
<Page>
@@ -61,15 +35,12 @@ const PrimeLeaderboard: React.FC = () => {
6135
<Card className="flex flex-col gap-2.5 border-dark-grey bg-background p-3 lg:grow">
6236
{accountAddress ? (
6337
<div className="grid grid-cols-1 gap-3 sm:grid-cols-2">
64-
{totalRewardsCard}
38+
<TotalRewardsSection />
6539

66-
<UserRewardsCard
67-
totalRewardsCents={placeholderUserRewardsCents}
68-
marketRewards={userMarketRewards}
69-
/>
40+
<UserRewardsSection />
7041
</div>
7142
) : (
72-
totalRewardsCard
43+
<TotalRewardsSection />
7344
)}
7445

7546
<RewardTable />
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { useGetTokens } from 'libs/tokens';
2+
3+
import type { MarketReward } from '../TotalRewardsCard';
4+
5+
export interface UseGetPrimeTotalRewardsOutput {
6+
totalRewardsCents: number;
7+
marketRewards: MarketReward[];
8+
}
9+
10+
// TODO: replace these placeholder values with the data returned by the API
11+
const placeholderTotalRewardsCents = 46_230_000;
12+
const placeholderMarketRewardsCents = [28_040_000, 17_190_000];
13+
14+
export const useGetPrimeTotalRewards = (): UseGetPrimeTotalRewardsOutput => {
15+
const tokens = useGetTokens();
16+
17+
// TODO: replace these placeholder tokens with the real Prime markets returned by the API
18+
const marketRewards = tokens
19+
.slice(0, placeholderMarketRewardsCents.length)
20+
.map((token, index) => ({ token, rewardsCents: placeholderMarketRewardsCents[index] }));
21+
22+
return {
23+
totalRewardsCents: placeholderTotalRewardsCents,
24+
marketRewards,
25+
};
26+
};
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { useGetTokens } from 'libs/tokens';
2+
3+
import type { UserMarketReward } from '../UserRewardsCard';
4+
5+
export interface UseGetPrimeUserRewardsOutput {
6+
totalRewardsCents: number;
7+
marketRewards: UserMarketReward[];
8+
}
9+
10+
// TODO: replace these placeholder values with the data returned by the API
11+
const placeholderTotalRewardsCents = 1_840_000;
12+
const placeholderMarketRewardsCents = [1_140_000, 700_000];
13+
const placeholderApyPercentage = 3.78;
14+
15+
export const useGetPrimeUserRewards = (): UseGetPrimeUserRewardsOutput => {
16+
const tokens = useGetTokens();
17+
18+
// TODO: replace these placeholder tokens with the real Prime markets returned by the API
19+
const marketRewards = tokens
20+
.slice(0, placeholderMarketRewardsCents.length)
21+
.map((token, index) => ({
22+
token,
23+
rewardsCents: placeholderMarketRewardsCents[index],
24+
apyPercentage: placeholderApyPercentage,
25+
}));
26+
27+
return {
28+
totalRewardsCents: placeholderTotalRewardsCents,
29+
marketRewards,
30+
};
31+
};

0 commit comments

Comments
 (0)