Skip to content

Commit e6cf09b

Browse files
committed
feat: support reward table & rank table
1 parent 68a561b commit e6cf09b

18 files changed

Lines changed: 487 additions & 35 deletions

File tree

apps/evm/src/components/Pagination/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ interface PaginationProps {
2727
onChange: (newPageIndex: number) => void;
2828
initialPageIndex?: number;
2929
itemsPerPageCount?: number;
30+
paramKey?: string;
3031
className?: string;
3132
}
3233

@@ -35,6 +36,7 @@ export const Pagination = ({
3536
onChange,
3637
initialPageIndex,
3738
itemsPerPageCount,
39+
paramKey,
3840
className,
3941
}: PaginationProps) => {
4042
const {
@@ -51,6 +53,7 @@ export const Pagination = ({
5153
onChange(newPageIndex + (initialPageIndex || 0));
5254
},
5355
itemsPerPageCount,
56+
paramKey,
5457
});
5558

5659
const styles = useStyles();

apps/evm/src/components/Pagination/usePagination.ts

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect, useMemo, useState } from 'react';
1+
import { useCallback, useEffect, useMemo, useState } from 'react';
22
import { useSearchParams } from 'react-router';
33

44
import { PAGE_CONTAINER_ID } from 'constants/layout';
@@ -9,31 +9,45 @@ type PaginationProps = {
99
itemsCount: number;
1010
onChange: (newPageIndex: number) => void;
1111
itemsPerPageCount?: number;
12+
// Search param key holding the active page, so several tables can paginate independently
13+
paramKey?: string;
1214
};
1315

1416
const PAGES_TO_SHOW_COUNT = 4;
1517

16-
export function usePagination({ itemsCount, onChange, itemsPerPageCount = 10 }: PaginationProps) {
18+
export function usePagination({
19+
itemsCount,
20+
onChange,
21+
itemsPerPageCount = 10,
22+
paramKey = PAGE_PARAM_KEY,
23+
}: PaginationProps) {
1724
const { t } = useTranslation();
1825
const scrollElem = document.getElementById(PAGE_CONTAINER_ID);
1926

2027
const [searchParams, setSearchParams] = useSearchParams();
2128

29+
const setPageParam = useCallback(
30+
(page: string) =>
31+
setSearchParams(currentSearchParams => ({
32+
...Object.fromEntries(currentSearchParams),
33+
[paramKey]: page,
34+
})),
35+
[setSearchParams, paramKey],
36+
);
37+
2238
const [urlPageParam, activePageIndex] = useMemo(() => {
23-
const pageParam = searchParams.get(PAGE_PARAM_KEY);
39+
const pageParam = searchParams.get(paramKey);
2440
const pageIndex = pageParam ? +pageParam - 1 : 0;
2541

2642
return [pageParam, pageIndex];
27-
}, [searchParams]);
43+
}, [searchParams, paramKey]);
2844

2945
// Automatically set default page param if none was set
3046
useEffect(() => {
3147
if (urlPageParam === undefined) {
32-
setSearchParams({
33-
[PAGE_PARAM_KEY]: '1',
34-
});
48+
setPageParam('1');
3549
}
36-
}, [urlPageParam, setSearchParams]);
50+
}, [urlPageParam, setPageParam]);
3751

3852
const [pagesCount, setPagesCount] = useState(0);
3953

@@ -68,9 +82,7 @@ export function usePagination({ itemsCount, onChange, itemsPerPageCount = 10 }:
6882
: activePageIndex + halfOfPagesCount;
6983

7084
const handlePageChange = (pageIndex: number) => {
71-
setSearchParams({
72-
[PAGE_PARAM_KEY]: pageIndex.toString(),
73-
});
85+
setPageParam(pageIndex.toString());
7486

7587
onChange(pageIndex);
7688

apps/evm/src/hooks/useUrlPagination/index.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,29 @@ export type UseUrlPaginationOutput = {
99
export const PAGE_PARAM_DEFAULT_VALUE = 1;
1010
export const PAGE_PARAM_KEY = 'page';
1111

12-
export const useUrlPagination = (): UseUrlPaginationOutput => {
12+
export interface UseUrlPaginationInput {
13+
// Search param key holding the active page, so several tables can paginate independently
14+
paramKey?: string;
15+
}
16+
17+
export const useUrlPagination = ({
18+
paramKey = PAGE_PARAM_KEY,
19+
}: UseUrlPaginationInput = {}): UseUrlPaginationOutput => {
1320
const [searchParams, setSearchParams] = useSearchParams();
14-
const pageIndex = searchParams.get(PAGE_PARAM_KEY) ?? undefined;
21+
const pageIndex = searchParams.get(paramKey) ?? undefined;
1522

1623
const setPageIndex = useCallback(
1724
(newPageIndex: string | number) =>
1825
setSearchParams(
1926
currentSearchParams => ({
2027
...Object.fromEntries(currentSearchParams),
21-
[PAGE_PARAM_KEY]: String(newPageIndex),
28+
[paramKey]: String(newPageIndex),
2229
}),
2330
{
2431
replace: true,
2532
},
2633
),
27-
[setSearchParams],
34+
[setSearchParams, paramKey],
2835
);
2936

3037
useEffect(() => {

apps/evm/src/libs/translations/translations/en.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,6 +1261,20 @@
12611261
"sec": "Sec",
12621262
"title": "End of cycle"
12631263
},
1264+
"rankTable": {
1265+
"columns": {
1266+
"primeScore": "Prime score",
1267+
"wallet": "Wallet"
1268+
},
1269+
"walletTooltip": "Users ranked by Prime score. The top 500 wallets become eligible for Prime in the next cycle."
1270+
},
1271+
"rewardTable": {
1272+
"columns": {
1273+
"marketRewards": "{{symbol}} rewards",
1274+
"totalRewards": "Total rewards",
1275+
"wallet": "Wallet"
1276+
}
1277+
},
12641278
"tablesRefreshNote": "Refreshed hourly · Last refresh: {{date, distanceToNow}} ago",
12651279
"title": "Prime leaderboard"
12661280
},

apps/evm/src/libs/translations/translations/ja.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,6 +1261,20 @@
12611261
"sec": "",
12621262
"title": "サイクル終了"
12631263
},
1264+
"rankTable": {
1265+
"columns": {
1266+
"primeScore": "Prime スコア",
1267+
"wallet": "ウォレット"
1268+
},
1269+
"walletTooltip": "Prime スコア順のランキングです。上位 500 のウォレットが次のサイクルで Prime の対象になります。"
1270+
},
1271+
"rewardTable": {
1272+
"columns": {
1273+
"marketRewards": "{{symbol}} の報酬",
1274+
"totalRewards": "報酬合計",
1275+
"wallet": "ウォレット"
1276+
}
1277+
},
12641278
"tablesRefreshNote": "1時間ごとに更新 · 最終更新:{{date, distanceToNow}}前",
12651279
"title": "Prime リーダーボード"
12661280
},

apps/evm/src/libs/translations/translations/th.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,6 +1261,20 @@
12611261
"sec": "วินาที",
12621262
"title": "สิ้นสุดรอบ"
12631263
},
1264+
"rankTable": {
1265+
"columns": {
1266+
"primeScore": "คะแนน Prime",
1267+
"wallet": "กระเป๋าเงิน"
1268+
},
1269+
"walletTooltip": "ผู้ใช้จัดอันดับตามคะแนน Prime กระเป๋าเงิน 500 อันดับแรกจะมีสิทธิ์รับ Prime ในรอบถัดไป"
1270+
},
1271+
"rewardTable": {
1272+
"columns": {
1273+
"marketRewards": "รางวัล {{symbol}}",
1274+
"totalRewards": "รางวัลทั้งหมด",
1275+
"wallet": "กระเป๋าเงิน"
1276+
}
1277+
},
12641278
"tablesRefreshNote": "รีเฟรชทุกชั่วโมง · รีเฟรชล่าสุด: {{date, distanceToNow}} ที่แล้ว",
12651279
"title": "กระดานผู้นำ Prime"
12661280
},

apps/evm/src/libs/translations/translations/tr.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,6 +1261,20 @@
12611261
"sec": "Sn.",
12621262
"title": "Döngü sonu"
12631263
},
1264+
"rankTable": {
1265+
"columns": {
1266+
"primeScore": "Prime puanı",
1267+
"wallet": "Cüzdan"
1268+
},
1269+
"walletTooltip": "Kullanıcılar Prime puanına göre sıralanır. İlk 500 cüzdan bir sonraki döngüde Prime için uygun olur."
1270+
},
1271+
"rewardTable": {
1272+
"columns": {
1273+
"marketRewards": "{{symbol}} ödülleri",
1274+
"totalRewards": "Toplam ödüller",
1275+
"wallet": "Cüzdan"
1276+
}
1277+
},
12641278
"tablesRefreshNote": "Saatlik yenilenir · Son yenileme: {{date, distanceToNow}} önce",
12651279
"title": "Prime lider tablosu"
12661280
},

apps/evm/src/libs/translations/translations/vi.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,6 +1261,20 @@
12611261
"sec": "Giây",
12621262
"title": "Kết thúc chu kỳ"
12631263
},
1264+
"rankTable": {
1265+
"columns": {
1266+
"primeScore": "Điểm Prime",
1267+
"wallet": ""
1268+
},
1269+
"walletTooltip": "Người dùng được xếp hạng theo điểm Prime. 500 ví dẫn đầu sẽ đủ điều kiện nhận Prime trong chu kỳ tiếp theo."
1270+
},
1271+
"rewardTable": {
1272+
"columns": {
1273+
"marketRewards": "Phần thưởng {{symbol}}",
1274+
"totalRewards": "Tổng phần thưởng",
1275+
"wallet": ""
1276+
}
1277+
},
12641278
"tablesRefreshNote": "Làm mới mỗi giờ · Lần làm mới cuối: {{date, distanceToNow}} trước",
12651279
"title": "Bảng xếp hạng Prime"
12661280
},

apps/evm/src/libs/translations/translations/zh-Hans.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,6 +1261,20 @@
12611261
"sec": "",
12621262
"title": "周期结束"
12631263
},
1264+
"rankTable": {
1265+
"columns": {
1266+
"primeScore": "Prime 分数",
1267+
"wallet": "钱包"
1268+
},
1269+
"walletTooltip": "用户按 Prime 分数排名。排名前 500 的钱包将在下个周期获得 Prime 资格。"
1270+
},
1271+
"rewardTable": {
1272+
"columns": {
1273+
"marketRewards": "{{symbol}} 奖励",
1274+
"totalRewards": "总奖励",
1275+
"wallet": "钱包"
1276+
}
1277+
},
12641278
"tablesRefreshNote": "每小时刷新 · 上次刷新:{{date, distanceToNow}}前",
12651279
"title": "Prime 排行榜"
12661280
},

apps/evm/src/libs/translations/translations/zh-Hant.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,6 +1261,20 @@
12611261
"sec": "",
12621262
"title": "週期結束"
12631263
},
1264+
"rankTable": {
1265+
"columns": {
1266+
"primeScore": "Prime 分數",
1267+
"wallet": "錢包"
1268+
},
1269+
"walletTooltip": "使用者依 Prime 分數排名。排名前 500 的錢包將在下個週期取得 Prime 資格。"
1270+
},
1271+
"rewardTable": {
1272+
"columns": {
1273+
"marketRewards": "{{symbol}} 獎勵",
1274+
"totalRewards": "總獎勵",
1275+
"wallet": "錢包"
1276+
}
1277+
},
12641278
"tablesRefreshNote": "每小時刷新 · 上次刷新:{{date, distanceToNow}}前",
12651279
"title": "Prime 排行榜"
12661280
},

0 commit comments

Comments
 (0)