-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathuseTokenSortOptions.ts
44 lines (41 loc) · 1.16 KB
/
useTokenSortOptions.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { useTranslation } from 'react-i18next'
import { SortFn, TokenCardInfo, TypedOption } from '@dao-dao/types'
import {
sortTokensValueAscending,
sortTokensValueDescending,
} from '@dao-dao/utils'
/**
* Options to use with the `useButtonPopupSorter` hook and the `ButtonPopup`
* component for sorting token lists.
*/
export const useTokenSortOptions = (): TypedOption<
SortFn<Pick<TokenCardInfo, 'token' | 'unstakedBalance' | 'lazyInfo'>>
>[] => {
const { t } = useTranslation()
return [
{
label: t('info.highestUsdValue'),
value: sortTokensValueDescending,
},
{
label: t('info.lowestUsdValue'),
value: sortTokensValueAscending,
},
{
// Most token symbols are in English, so no need to translate.
label: 'A → Z',
value: (a, b) =>
a.token.symbol
.toLocaleLowerCase()
.localeCompare(b.token.symbol.toLocaleLowerCase()),
},
{
// Most token symbols are in English, so no need to translate.
label: 'Z → A',
value: (a, b) =>
b.token.symbol
.toLocaleLowerCase()
.localeCompare(a.token.symbol.toLocaleLowerCase()),
},
]
}