Skip to content

Commit

Permalink
feat: allow to filter on rmm status
Browse files Browse the repository at this point in the history
  • Loading branch information
jycssu-com committed Nov 18, 2023
1 parent 2a48063 commit 3520c4f
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/components/assetsView/filters/AssetsViewFilterModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from 'src/states'

import { AssetsViewRentStatusFilter } from './AssetsViewRentStatusFilter'
import { AssetsViewRmmStatusFilter } from './AssetsViewRmmStatusFilter'
import { AssetsViewSort } from './AssetsViewSort'
import { AssetsViewSubsidyFilter } from './AssetsViewSubsidyFilter'
import { AssetsViewUserStatusFilter } from './AssetsViewUserStatusFilter'
Expand Down Expand Up @@ -67,6 +68,12 @@ export const AssetsViewFilterModal: FC<ContextModalProps> = ({
setFilterModel({ ...filterModel, ...value })
}}
/>
<AssetsViewRmmStatusFilter
filter={filterModel}
onChange={(value) => {
setFilterModel({ ...filterModel, ...value })
}}
/>
</Flex>
<Flex gap={'lg'} justify={'center'}>
<Button onClick={onClose} variant={'subtle'}>
Expand Down
68 changes: 68 additions & 0 deletions src/components/assetsView/filters/AssetsViewRmmStatusFilter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { FC } from 'react'
import { useTranslation } from 'react-i18next'

import { Select } from '@mantine/core'

import { UserRealtoken } from 'src/store/features/wallets/walletsSelector'

import { useInputStyles } from '../../inputs/useInputStyles'
import { AssetRmmStatusType } from '../types'

interface AssetsViewRmmStatusFilterModel {
rmmStatus: AssetRmmStatusType
}

interface AssetsViewRmmStatusFilterProps {
filter: AssetsViewRmmStatusFilterModel
onChange: (value: AssetsViewRmmStatusFilterModel) => void
}
export const AssetsViewRmmStatusFilter: FC<AssetsViewRmmStatusFilterProps> = ({
filter,
onChange,
}) => {
const { t } = useTranslation('common', { keyPrefix: 'assetRmmStatus' })
const { classes: inputClasses } = useInputStyles()

const viewOptions = [
{
value: AssetRmmStatusType.ALL,
label: t('options.all'),
},
{
value: AssetRmmStatusType.AVAILABLE,
label: t('options.available'),
},
{
value: AssetRmmStatusType.NOT_AVAILABLE,
label: t('options.notAvailable'),
},
]

return (
<Select
label={t('label')}
data={viewOptions}
value={filter.rmmStatus}
onChange={(value: AssetRmmStatusType) => onChange({ rmmStatus: value })}
classNames={inputClasses}
/>
)
}
AssetsViewRmmStatusFilter.displayName = 'AssetsViewRmmStatusFilter'

export function useAssetsViewRmmStatusFilter(
filter: AssetsViewRmmStatusFilterModel
) {
function assetRmmStatusFilterFunction(asset: UserRealtoken) {
switch (filter.rmmStatus) {
case AssetRmmStatusType.ALL:
return true
case AssetRmmStatusType.AVAILABLE:
return asset.isRmmAvailable
case AssetRmmStatusType.NOT_AVAILABLE:
return !asset.isRmmAvailable
}
}

return { assetRmmStatusFilterFunction }
}
4 changes: 4 additions & 0 deletions src/components/assetsView/filters/useFilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { assetsViewDefaultFilter, assetsViewFilterAtom } from 'src/states'
import { UserRealtoken } from 'src/store/features/wallets/walletsSelector'

import { useAssetsViewRentStatusFilter } from './AssetsViewRentStatusFilter'
import { useAssetsViewRmmStatusFilter } from './AssetsViewRmmStatusFilter'
import { useAssetsViewSort } from './AssetsViewSort'
import { useAssetsViewSubsidyFilter } from './AssetsViewSubsidyFilter'
import { useAssetsViewUserStatusFilter } from './AssetsViewUserStatusFilter'
Expand All @@ -19,12 +20,15 @@ export function useAssetsViewFilters() {
useAssetsViewUserStatusFilter(activeFilter)
const { assetRentStatusFilterFunction } =
useAssetsViewRentStatusFilter(activeFilter)
const { assetRmmStatusFilterFunction } =
useAssetsViewRmmStatusFilter(activeFilter)

function assetsViewFilterFunction(tokenList: UserRealtoken[]) {
return tokenList
.filter(assetUserStatusFilterFunction)
.filter(assetRentStatusFilterFunction)
.filter(assetSubsidyFilterFunction)
.filter(assetRmmStatusFilterFunction)
.sort(assetSortFunction)
}

Expand Down
5 changes: 5 additions & 0 deletions src/components/assetsView/types/assetRmmStatus.type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export enum AssetRmmStatusType {
ALL = 'ALL',
AVAILABLE = 'AVAILABLE',
NOT_AVAILABLE = 'NOT_AVAILABLE',
}
1 change: 1 addition & 0 deletions src/components/assetsView/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from './assetView.type'
export * from './assetSubsidy.type'
export * from './assetUserStatus.type'
export * from './assetRentStatus.type'
export * from './assetRmmStatus.type'
9 changes: 8 additions & 1 deletion src/i18next/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@
"notWhitelisted": "Not whitelisted"
}
},

"assetRentStatus": {
"label": "Rent",
"options": {
Expand All @@ -120,6 +119,14 @@
"partiallyRented": "Partially rented"
}
},
"assetRmmStatus": {
"label": "Available on RMM",
"options": {
"all": "All",
"available": "Yes",
"notAvailable": "No"
}
},
"assetCard": {
"tokens": "Tokens",
"apr": "APR",
Expand Down
8 changes: 8 additions & 0 deletions src/i18next/locales/fr/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@
"partiallyRented": "Partiellement loués"
}
},
"assetRmmStatus": {
"label": "Disponible sur le RMM",
"options": {
"all": "Tous",
"available": "Oui",
"notAvailable": "Non"
}
},
"assetCard": {
"tokens": "Tokens",
"apr": "Rendement annuel",
Expand Down
3 changes: 3 additions & 0 deletions src/states/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { atomWithStorage } from 'jotai/utils'

import {
AssetRentStatusType,
AssetRmmStatusType,
AssetSortType,
AssetSubsidyType,
AssetUserStatusType,
Expand All @@ -19,6 +20,7 @@ export interface AssetsViewFilterType {
subsidy: AssetSubsidyType
userStatus: AssetUserStatusType
rentStatus: AssetRentStatusType
rmmStatus: AssetRmmStatusType
}

export const assetsViewDefaultFilter: AssetsViewFilterType = {
Expand All @@ -27,6 +29,7 @@ export const assetsViewDefaultFilter: AssetsViewFilterType = {
subsidy: AssetSubsidyType.ALL,
userStatus: AssetUserStatusType.OWNED,
rentStatus: AssetRentStatusType.ALL,
rmmStatus: AssetRmmStatusType.ALL,
}

export const assetsViewFilterAtom = atomWithStorage<AssetsViewFilterType>(
Expand Down

0 comments on commit 3520c4f

Please sign in to comment.