Skip to content

Commit

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

export const AssetsViewFilterModal: FC<ContextModalProps> = ({
Expand Down Expand Up @@ -56,6 +57,12 @@ export const AssetsViewFilterModal: FC<ContextModalProps> = ({
setFilterModel({ ...filterModel, ...value })
}}
/>
<AssetsViewUserProtocolFilter
filter={filterModel}
onChange={(value) => {
setFilterModel({ ...filterModel, ...value })
}}
/>
<AssetsViewRentStatusFilter
filter={filterModel}
onChange={(value) => {
Expand Down
81 changes: 81 additions & 0 deletions src/components/assetsView/filters/AssetsViewUserProtocolFilter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
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 { AssetUserProtocolType } from '../types'

interface AssetsViewUserProtocolFilterModel {
userProtocol: AssetUserProtocolType
}

interface AssetsViewUserProtocolFilterProps {
filter: AssetsViewUserProtocolFilterModel
onChange: (value: AssetsViewUserProtocolFilterModel) => void
}
export const AssetsViewUserProtocolFilter: FC<
AssetsViewUserProtocolFilterProps
> = ({ filter, onChange }) => {
const { t } = useTranslation('common', { keyPrefix: 'assetUserProtocol' })
const { classes: inputClasses } = useInputStyles()

const viewOptions = [
{
value: AssetUserProtocolType.ALL,
label: t('options.all'),
},
{
value: AssetUserProtocolType.ETHEREUM,
label: t('options.ethereum'),
},
{
value: AssetUserProtocolType.GNOSIS,
label: t('options.gnosis'),
},
{
value: AssetUserProtocolType.RMM,
label: t('options.rmm'),
},
{
value: AssetUserProtocolType.LEVINSWAP,
label: t('options.levinSwap'),
},
]

return (
<Select
label={t('label')}
data={viewOptions}
value={filter.userProtocol}
onChange={(value: AssetUserProtocolType) =>
onChange({ userProtocol: value })
}
classNames={inputClasses}
/>
)
}
AssetsViewUserProtocolFilter.displayName = 'AssetsViewUserProtocolFilter'

export function useAssetsViewUserProtocolFilter(
filter: AssetsViewUserProtocolFilterModel
) {
function assetUserProtocolFilterFunction(asset: UserRealtoken) {
switch (filter.userProtocol) {
case AssetUserProtocolType.ALL:
return true
case AssetUserProtocolType.ETHEREUM:
return asset.balance.ethereum.amount > 0
case AssetUserProtocolType.GNOSIS:
return asset.balance.gnosis.amount > 0
case AssetUserProtocolType.RMM:
return asset.balance.rmm.amount > 0
case AssetUserProtocolType.LEVINSWAP:
return asset.balance.levinSwap.amount > 0
}
}

return { assetUserProtocolFilterFunction }
}
4 changes: 4 additions & 0 deletions src/components/assetsView/filters/useFilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useAssetsViewRentStatusFilter } from './AssetsViewRentStatusFilter'
import { useAssetsViewRmmStatusFilter } from './AssetsViewRmmStatusFilter'
import { useAssetsViewSort } from './AssetsViewSort'
import { useAssetsViewSubsidyFilter } from './AssetsViewSubsidyFilter'
import { useAssetsViewUserProtocolFilter } from './AssetsViewUserProtocolFilter'
import { useAssetsViewUserStatusFilter } from './AssetsViewUserStatusFilter'

export function useAssetsViewFilters() {
Expand All @@ -22,10 +23,13 @@ export function useAssetsViewFilters() {
useAssetsViewRentStatusFilter(activeFilter)
const { assetRmmStatusFilterFunction } =
useAssetsViewRmmStatusFilter(activeFilter)
const { assetUserProtocolFilterFunction } =
useAssetsViewUserProtocolFilter(activeFilter)

function assetsViewFilterFunction(tokenList: UserRealtoken[]) {
return tokenList
.filter(assetUserStatusFilterFunction)
.filter(assetUserProtocolFilterFunction)
.filter(assetRentStatusFilterFunction)
.filter(assetSubsidyFilterFunction)
.filter(assetRmmStatusFilterFunction)
Expand Down
7 changes: 7 additions & 0 deletions src/components/assetsView/types/assetUserProtocol.type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export enum AssetUserProtocolType {
ALL = 'all',
ETHEREUM = 'ethereum',
GNOSIS = 'gnosis',
RMM = 'rmm',
LEVINSWAP = 'levinSwap',
}
1 change: 1 addition & 0 deletions src/components/assetsView/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * from './assetSubsidy.type'
export * from './assetUserStatus.type'
export * from './assetRentStatus.type'
export * from './assetRmmStatus.type'
export * from './assetUserProtocol.type'
10 changes: 10 additions & 0 deletions src/i18next/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,16 @@
"notAvailable": "No"
}
},
"assetUserProtocol": {
"label": "Owned on",
"options": {
"all": "All",
"ethereum": "Ethereum",
"gnosis": "Gnosis",
"rmm": "RMM",
"levinSwap": "LevinSwap"
}
},
"assetCard": {
"tokens": "Tokens",
"apr": "APR",
Expand Down
10 changes: 10 additions & 0 deletions src/i18next/locales/fr/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,16 @@
"notAvailable": "Non"
}
},
"assetUserProtocol": {
"label": "Possédées sur",
"options": {
"all": "Tous",
"ethereum": "Ethereum",
"gnosis": "Gnosis",
"rmm": "RMM",
"levinSwap": "LevinSwap"
}
},
"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 @@ -5,6 +5,7 @@ import {
AssetRmmStatusType,
AssetSortType,
AssetSubsidyType,
AssetUserProtocolType,
AssetUserStatusType,
AssetViewType,
} from 'src/components/assetsView/types'
Expand All @@ -21,6 +22,7 @@ export interface AssetsViewFilterType {
userStatus: AssetUserStatusType
rentStatus: AssetRentStatusType
rmmStatus: AssetRmmStatusType
userProtocol: AssetUserProtocolType
}

export const assetsViewDefaultFilter: AssetsViewFilterType = {
Expand All @@ -30,6 +32,7 @@ export const assetsViewDefaultFilter: AssetsViewFilterType = {
userStatus: AssetUserStatusType.OWNED,
rentStatus: AssetRentStatusType.ALL,
rmmStatus: AssetRmmStatusType.ALL,
userProtocol: AssetUserProtocolType.ALL,
}

export const assetsViewFilterAtom = atomWithStorage<AssetsViewFilterType>(
Expand Down

0 comments on commit 2a6da69

Please sign in to comment.