Skip to content

Commit e4bcde7

Browse files
committed
refactor: extract shared prime rank label helper
1 parent 0229d4f commit e4bcde7

3 files changed

Lines changed: 28 additions & 17 deletions

File tree

apps/evm/src/containers/PrimeRank/Footer/index.tsx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import BigNumber from 'bignumber.js';
2-
31
import { routes } from 'constants/routing';
42
import { Link } from 'containers/Link';
53
import { useTranslation } from 'libs/translations';
6-
import { shortenValueWithSuffix } from 'utilities';
74

85
import { EligibilityStatus } from '../EligibilityStatus';
6+
import { getRankLabels } from '../getRankLabels';
97
import { useGetPrimeRank } from '../useGetPrimeRank';
108

119
export interface FooterProps {
@@ -15,13 +13,10 @@ export interface FooterProps {
1513
export const Footer: React.FC<FooterProps> = ({ hideLeaderboardLink }) => {
1614
const { t, Trans } = useTranslation();
1715

18-
const { hasStakedXvs, isCandidate, isPrime, hasSupplied, rank, primeScore, gapXvsTokens } =
19-
useGetPrimeRank();
16+
const rankData = useGetPrimeRank();
17+
const { hasStakedXvs, isCandidate, isPrime, hasSupplied, gapXvsTokens } = rankData;
2018

21-
const rankLabel = hasStakedXvs ? `#${rank}` : '#-';
22-
const primeScoreLabel = hasStakedXvs
23-
? shortenValueWithSuffix({ value: new BigNumber(primeScore) })
24-
: '-';
19+
const { rankLabel, primeScoreLabel } = getRankLabels(rankData);
2520

2621
return (
2722
<div className="flex flex-col gap-1 rounded-lg border border-dark-blue-hover p-3">
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import BigNumber from 'bignumber.js';
2+
3+
import { shortenValueWithSuffix } from 'utilities';
4+
5+
import type { PrimeRankData } from '../useGetPrimeRank';
6+
7+
export interface RankLabels {
8+
rankLabel: string;
9+
primeScoreLabel: string;
10+
}
11+
12+
export const getRankLabels = ({
13+
hasStakedXvs,
14+
rank,
15+
primeScore,
16+
}: Pick<PrimeRankData, 'hasStakedXvs' | 'rank' | 'primeScore'>): RankLabels => ({
17+
rankLabel: hasStakedXvs ? `#${rank}` : '#-',
18+
primeScoreLabel: hasStakedXvs
19+
? shortenValueWithSuffix({ value: new BigNumber(primeScore) })
20+
: '-',
21+
});

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { cn } from '@venusprotocol/ui';
2-
import BigNumber from 'bignumber.js';
32

43
import { EligibilityStatus } from 'containers/PrimeRank/EligibilityStatus';
4+
import { getRankLabels } from 'containers/PrimeRank/getRankLabels';
55
import type { PrimeRankData } from 'containers/PrimeRank/useGetPrimeRank';
6-
import { shortenValueWithSuffix } from 'utilities';
76

87
import { ConnectPrompt } from './ConnectPrompt';
98
import { RankActions } from './RankActions';
@@ -32,13 +31,9 @@ export const RankCard: React.FC<RankCardProps> = ({
3231
);
3332
}
3433

35-
const { hasStakedXvs, isCandidate, isPrime, hasSupplied, rank, primeScore, gapXvsTokens } =
36-
rankData;
34+
const { hasStakedXvs, isCandidate, isPrime, hasSupplied, gapXvsTokens } = rankData;
3735

38-
const rankLabel = hasStakedXvs ? `#${rank}` : '#-';
39-
const primeScoreLabel = hasStakedXvs
40-
? shortenValueWithSuffix({ value: new BigNumber(primeScore) })
41-
: '-';
36+
const { rankLabel, primeScoreLabel } = getRankLabels(rankData);
4237

4338
return (
4439
<div className={cn(cardClassName, 'justify-between')}>

0 commit comments

Comments
 (0)