Skip to content
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

feat: add product type filter #94

Merged
merged 8 commits into from
Dec 21, 2024
7 changes: 7 additions & 0 deletions src/components/assetsView/filters/AssetsViewFilterModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
assetsViewFilterAtom,
} from 'src/states'

import { AssetsViewProductTypeFilter } from './AssetsViewFilterProductType'
import { AssetsViewRentStatusFilter } from './AssetsViewRentStatusFilter'
import { AssetsViewRmmStatusFilter } from './AssetsViewRmmStatusFilter'
import { AssetsViewSort } from './AssetsViewSort'
Expand Down Expand Up @@ -76,6 +77,12 @@ export const AssetsViewFilterModal: FC<ContextModalProps> = ({
setFilterModel({ ...filterModel, ...value })
}}
/>
<AssetsViewProductTypeFilter
filter={filterModel}
onChange={(value) => {
setFilterModel({ ...filterModel, ...value })
}}
/>
<AssetsViewUserProtocolFilter
filter={filterModel}
onChange={(value) => {
Expand Down
77 changes: 77 additions & 0 deletions src/components/assetsView/filters/AssetsViewFilterProductType.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { FC } from 'react'
import { useTranslation } from 'react-i18next'

import { Select } from '@mantine/core'

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

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

interface AssetsViewFilterType {
productType: AssetProductType
}

interface AssetsViewProductTypeFilterProps {
filter: AssetsViewFilterType
onChange: (value: AssetsViewFilterType) => void
}
export const AssetsViewProductTypeFilter: FC<
AssetsViewProductTypeFilterProps
> = ({ filter, onChange }) => {
const { t } = useTranslation('common', { keyPrefix: 'assetProductType' })
const { classes: inputClasses } = useInputStyles()

const viewOptions = [
{
value: AssetProductType.ALL,
label: t('options.all'),
},
{
value: AssetProductType.REAL_EASTATE_RENTAL,
label: t('options.realEstateRental'),
},
{
value: AssetProductType.LOAN_INCOME,
label: t('options.loanIncome'),
},
{
value: AssetProductType.EQUITY_TOKEN,
label: t('options.equityToken'),
},
]

return (
<Select
label={t('label')}
data={viewOptions}
value={filter.productType}
onChange={(value) => onChange({ productType: value as AssetProductType })}
classNames={inputClasses}
/>
)
}
AssetsViewProductTypeFilter.displayName = 'AssetsViewProductTypeFilter'

export function useAssetsViewProductTypeFilter(filter: AssetsViewFilterType) {
function assetProductTypeFilterFunction(asset: UserRealtoken | RWARealtoken) {
const Asset = asset as UserRealtoken
switch (filter.productType) {
case AssetProductType.ALL:
return true
case AssetProductType.REAL_EASTATE_RENTAL:
return (
String(Asset.productType) === AssetProductType.REAL_EASTATE_RENTAL
)
case AssetProductType.LOAN_INCOME:
return String(Asset.productType) === AssetProductType.LOAN_INCOME
case AssetProductType.EQUITY_TOKEN:
return String(Asset.productType) === AssetProductType.EQUITY_TOKEN
}
}

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

import { useAssetsViewProductTypeFilter } from './AssetsViewFilterProductType'
import { useAssetsViewRentStatusFilter } from './AssetsViewRentStatusFilter'
import { useAssetsViewRmmStatusFilter } from './AssetsViewRmmStatusFilter'
import { useAssetsViewSort } from './AssetsViewSort'
Expand All @@ -22,6 +23,8 @@ export function useAssetsViewFilters() {
useAssetsViewSubsidyFilter(activeFilter)
const { assetUserStatusFilterFunction } =
useAssetsViewUserStatusFilter(activeFilter)
const { assetProductTypeFilterFunction } =
useAssetsViewProductTypeFilter(activeFilter)
const { assetRentStatusFilterFunction } =
useAssetsViewRentStatusFilter(activeFilter)
const { assetRmmStatusFilterFunction } =
Expand All @@ -35,6 +38,7 @@ export function useAssetsViewFilters() {
return tokenList
.filter(assetUserStatusFilterFunction)
.filter(assetUserProtocolFilterFunction)
.filter(assetProductTypeFilterFunction)
.filter(assetRentStatusFilterFunction)
.filter(assetSubsidyFilterFunction)
.filter(assetRmmStatusFilterFunction)
Expand Down
6 changes: 6 additions & 0 deletions src/components/assetsView/types/assetProduct.type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export enum AssetProductType {
ALL = 'all',
REAL_EASTATE_RENTAL = 'real_estate_rental',
EQUITY_TOKEN = 'equity_token',
LOAN_INCOME = 'loan_income',
}
1 change: 1 addition & 0 deletions src/components/assetsView/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export * from './assetUserStatus.type'
export * from './assetRentStatus.type'
export * from './assetRmmStatus.type'
export * from './assetUserProtocol.type'
export * from './assetProduct.type'
9 changes: 9 additions & 0 deletions src/i18next/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,15 @@
"notWhitelisted": "Not whitelisted"
}
},
"assetProductType": {
"label": "Product type",
"options": {
"all": "All",
"realEstateRental": "Real estate rental",
"loanIncome": "Loan income",
"equityToken": "Equity token"
}
},
"assetRentStatus": {
"label": "Rent",
"options": {
Expand Down
9 changes: 9 additions & 0 deletions src/i18next/locales/fr/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,15 @@
"notWhitelisted": "Non whitelistées"
}
},
"assetProductType": {
"label": "Type de propriété",
"options": {
"all": "Tous",
"realEstateRental": "Location immobilière",
"loanIncome": "Revenu de prêt",
"equityToken": "Token d'équité"
}
},
"assetRentStatus": {
"label": "Loyers",
"options": {
Expand Down
3 changes: 3 additions & 0 deletions src/states/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { atomWithStorage } from 'jotai/utils'

import {
AssetProductType,
AssetRentStatusType,
AssetRmmStatusType,
AssetSortType,
Expand All @@ -20,6 +21,7 @@ export interface AssetsViewFilterType {
sortReverse: boolean
subsidy: AssetSubsidyType
userStatus: AssetUserStatusType
productType: AssetProductType
rentStatus: AssetRentStatusType
rmmStatus: AssetRmmStatusType
userProtocol: AssetUserProtocolType
Expand All @@ -30,6 +32,7 @@ export const assetsViewDefaultFilter: AssetsViewFilterType = {
sortReverse: false,
subsidy: AssetSubsidyType.ALL,
userStatus: AssetUserStatusType.OWNED,
productType: AssetProductType.ALL,
rentStatus: AssetRentStatusType.ALL,
rmmStatus: AssetRmmStatusType.ALL,
userProtocol: AssetUserProtocolType.ALL,
Expand Down
Loading