-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow to filter on owned protocol
- Loading branch information
1 parent
3520c4f
commit 2a6da69
Showing
8 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
src/components/assetsView/filters/AssetsViewUserProtocolFilter.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters