-
Notifications
You must be signed in to change notification settings - Fork 88
feat: support last cycle prime summary modal #5630
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
Open
cuzz-venus
wants to merge
5
commits into
feat/prime-total-rewards
Choose a base branch
from
feat/prime-last-cycle-summary
base: feat/prime-total-rewards
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0a7626e
feat: support last cycle prime summary modal
cuzz-venus 0077259
fix: solve comments
cuzz-venus ac5d3b9
feat: support last cycle modal open
cuzz-venus b9ef2df
feat: show user rank card in last cycle summary modal
cuzz-venus bd2ecf9
refactor: simplify last cycle summary user rewards card
cuzz-venus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1261,6 +1261,15 @@ | |||||||||||||
| "sec": "Sec", | ||||||||||||||
| "title": "End of cycle" | ||||||||||||||
| }, | ||||||||||||||
| "lastCycleSummary": { | ||||||||||||||
| "primeScoreLabel": "Prime score", | ||||||||||||||
| "rankLabel": "Your rank", | ||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mentioned this to Zed yesterday, this should be "You ranked". Sorry for the last minute change. |
||||||||||||||
| "rankMissed": "Almost there! You weren't in last cycle's top 500. Boost your stake to qualify this cycle.", | ||||||||||||||
| "rankNoStake": "You didn't stake XVS last cycle. Stake now to qualify for Prime and earn extra rewards.", | ||||||||||||||
| "rankQualified": "Congrats! You're in the Top 500 during last cycle and qualified for Prime Rewards.", | ||||||||||||||
|
Comment on lines
+1267
to
+1269
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These weren't proof read I think.
Suggested change
|
||||||||||||||
| "title": "Last Cycle Prime Summary", | ||||||||||||||
| "userRewardsTitle": "Your Prime rewards last cycle" | ||||||||||||||
| }, | ||||||||||||||
| "rankTable": { | ||||||||||||||
| "columns": { | ||||||||||||||
| "primeScore": "Prime score", | ||||||||||||||
|
|
||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
apps/evm/src/pages/PrimeLeaderboard/LastCycleSummaryModal/UserRankCard/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import { cn } from '@venusprotocol/ui'; | ||
| import type BigNumber from 'bignumber.js'; | ||
|
|
||
| import { PRIME_RANK_LIMIT } from 'constants/prime'; | ||
| import { useTranslation } from 'libs/translations'; | ||
| import { shortenValueWithSuffix } from 'utilities'; | ||
|
|
||
| export interface UserRankCardProps { | ||
| rank?: number; | ||
| primeScore?: BigNumber; | ||
| className?: string; | ||
| } | ||
|
|
||
| export const UserRankCard: React.FC<UserRankCardProps> = ({ rank, primeScore, className }) => { | ||
| const { t } = useTranslation(); | ||
|
|
||
| const isRanked = rank !== undefined; | ||
| const isInTopRank = isRanked && rank <= PRIME_RANK_LIMIT; | ||
| const rankLabel = isRanked ? `#${rank}` : '#-'; | ||
| const primeScoreLabel = | ||
| isRanked && primeScore ? shortenValueWithSuffix({ value: primeScore }) : '-'; | ||
|
|
||
| let message = t('primeLeaderboard.lastCycleSummary.rankNoStake'); | ||
| let messageClassName = 'text-yellow'; | ||
|
|
||
| if (isInTopRank) { | ||
| message = t('primeLeaderboard.lastCycleSummary.rankQualified'); | ||
| messageClassName = 'text-white'; | ||
| } else if (isRanked) { | ||
| message = t('primeLeaderboard.lastCycleSummary.rankMissed'); | ||
| } | ||
|
|
||
| return ( | ||
| <div className={cn('flex flex-col gap-4 rounded-lg bg-background-active p-4', className)}> | ||
| <div className="flex items-start justify-between"> | ||
| <div className="flex flex-col"> | ||
| <span className="text-b1r text-light-grey"> | ||
| {t('primeLeaderboard.lastCycleSummary.rankLabel')} | ||
| </span> | ||
|
|
||
| <span className="text-h5 text-white">{rankLabel}</span> | ||
| </div> | ||
|
|
||
| <div className="flex flex-col items-end"> | ||
| <span className="text-b1r text-light-grey"> | ||
| {t('primeLeaderboard.lastCycleSummary.primeScoreLabel')} | ||
| </span> | ||
|
|
||
| <span className="text-h5 text-white">{primeScoreLabel}</span> | ||
| </div> | ||
| </div> | ||
|
|
||
| <p className={cn('text-b1r', messageClassName)}>{message}</p> | ||
| </div> | ||
| ); | ||
| }; |
15 changes: 15 additions & 0 deletions
15
apps/evm/src/pages/PrimeLeaderboard/LastCycleSummaryModal/__tests__/index.spec.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import { screen } from '@testing-library/react'; | ||
|
|
||
| import { renderComponent } from 'testUtils/render'; | ||
|
|
||
| import { LastCycleSummaryModal } from '..'; | ||
|
|
||
| describe('pages/PrimeLeaderboard/LastCycleSummaryModal', () => { | ||
| it('renders the last cycle user rank and rewards', async () => { | ||
| renderComponent(<LastCycleSummaryModal isOpen handleClose={() => {}} />); | ||
|
|
||
| expect(await screen.findByText('Last Cycle Prime Summary')).toBeInTheDocument(); | ||
| expect(screen.getByText('Your rank')).toBeInTheDocument(); | ||
| expect(screen.getByText('Your Prime rewards last cycle')).toBeInTheDocument(); | ||
| }); | ||
| }); |
57 changes: 57 additions & 0 deletions
57
apps/evm/src/pages/PrimeLeaderboard/LastCycleSummaryModal/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import BigNumber from 'bignumber.js'; | ||
|
|
||
| import { Modal } from 'components'; | ||
| import { useGetTokens } from 'libs/tokens'; | ||
| import { useTranslation } from 'libs/translations'; | ||
|
|
||
| import { UserRewardsCard } from '../UserRewardsCard'; | ||
| import { UserRankCard } from './UserRankCard'; | ||
|
|
||
| // TODO: replace these placeholder values with the data returned by the API | ||
| const placeholderRank = 1222; | ||
| const placeholderPrimeScore = new BigNumber(542_500_000); | ||
| const placeholderUserRewardsCents = 1_840_000; | ||
| const placeholderUserMarketRewardsCents = [1_140_000, 700_000]; | ||
| const placeholderApyPercentage = 3.78; | ||
|
|
||
| export interface LastCycleSummaryModalProps { | ||
| isOpen: boolean; | ||
| handleClose: () => void; | ||
| } | ||
|
|
||
| export const LastCycleSummaryModal: React.FC<LastCycleSummaryModalProps> = ({ | ||
| isOpen, | ||
| handleClose, | ||
| }) => { | ||
| const { t } = useTranslation(); | ||
| const tokens = useGetTokens(); | ||
|
|
||
| // TODO: replace these placeholder tokens with the real Prime markets returned by the API | ||
| const markets = tokens.slice(0, placeholderUserMarketRewardsCents.length); | ||
|
|
||
| const userMarketRewards = markets.map((token, index) => ({ | ||
| token, | ||
| rewardsCents: placeholderUserMarketRewardsCents[index], | ||
| apyPercentage: placeholderApyPercentage, | ||
| })); | ||
|
|
||
| return ( | ||
| <Modal | ||
| isOpen={isOpen} | ||
| handleClose={handleClose} | ||
| title={t('primeLeaderboard.lastCycleSummary.title')} | ||
| className="max-w-113" | ||
| > | ||
| <div className="flex flex-col gap-3"> | ||
| <UserRankCard rank={placeholderRank} primeScore={placeholderPrimeScore} /> | ||
|
|
||
| <UserRewardsCard | ||
| title={t('primeLeaderboard.lastCycleSummary.userRewardsTitle')} | ||
| totalRewardsCents={placeholderUserRewardsCents} | ||
| marketRewards={userMarketRewards} | ||
| showMarketActions={false} | ||
| /> | ||
| </div> | ||
| </Modal> | ||
| ); | ||
| }; |
18 changes: 18 additions & 0 deletions
18
apps/evm/src/pages/PrimeLeaderboard/PrimeRewardBadge/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import { cn } from '@venusprotocol/ui'; | ||
|
|
||
| import primeLogoSrc from 'assets/img/primeLogo.svg'; | ||
|
|
||
| export interface PrimeRewardBadgeProps { | ||
| className?: string; | ||
| } | ||
|
|
||
| export const PrimeRewardBadge: React.FC<PrimeRewardBadgeProps> = ({ className }) => ( | ||
| <span | ||
| className={cn( | ||
| 'flex size-10 shrink-0 items-center justify-center rounded-lg border border-[#805c4e]', | ||
| className, | ||
| )} | ||
| > | ||
| <img src={primeLogoSrc} alt="" className="h-5" /> | ||
| </span> | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be fetched from the contract (it could change in the future through a VIP).