From 28f05cebbaca5a5730e563d511b29d05908f27dd Mon Sep 17 00:00:00 2001 From: Gareth Fuller Date: Wed, 16 Oct 2024 16:57:42 +0100 Subject: [PATCH 1/5] chore: Init --- .../PoolListTable/PoolListTableHeader.tsx | 2 +- .../PoolListTable/PoolListTableRow.tsx | 31 ++++++++++++++++--- .../lib/shared/components/badges/BalBadge.tsx | 21 +++++++++++++ .../shared/components/icons/logos/CowIcon.tsx | 4 +-- 4 files changed, 50 insertions(+), 8 deletions(-) create mode 100644 packages/lib/shared/components/badges/BalBadge.tsx diff --git a/packages/lib/modules/pool/PoolList/PoolListTable/PoolListTableHeader.tsx b/packages/lib/modules/pool/PoolList/PoolListTable/PoolListTableHeader.tsx index 5a1d0ca48..0f000b147 100644 --- a/packages/lib/modules/pool/PoolList/PoolListTable/PoolListTableHeader.tsx +++ b/packages/lib/modules/pool/PoolList/PoolListTable/PoolListTableHeader.tsx @@ -37,7 +37,7 @@ export function PoolListTableHeader({ ...rest }) { - Type + Details {orderBy.map((orderByItem, index) => ( diff --git a/packages/lib/modules/pool/PoolList/PoolListTable/PoolListTableRow.tsx b/packages/lib/modules/pool/PoolList/PoolListTable/PoolListTableRow.tsx index 26a9e5dc5..3ecabe5ac 100644 --- a/packages/lib/modules/pool/PoolList/PoolListTable/PoolListTableRow.tsx +++ b/packages/lib/modules/pool/PoolList/PoolListTable/PoolListTableRow.tsx @@ -1,4 +1,4 @@ -import { Box, Grid, GridItem, GridProps, Text } from '@chakra-ui/react' +import { Box, Grid, GridItem, GridProps, HStack, Text } from '@chakra-ui/react' import Link from 'next/link' import { getPoolPath, getPoolTypeLabel } from '../../pool.utils' import MainAprTooltip from '@repo/lib/shared/components/tooltips/apr-tooltip/MainAprTooltip' @@ -10,6 +10,9 @@ import { PoolListItem } from '../../pool.types' import { PoolListTokenPills } from '../PoolListTokenPills' import { getUserTotalBalanceUsd } from '../../user-balance.helpers' import FadeInOnView from '@repo/lib/shared/components/containers/FadeInOnView' +import { isCowAmmPool } from '../../pool.helpers' +import { BalBadge } from '@repo/lib/shared/components/badges/BalBadge' +import { CowIcon } from '@repo/lib/shared/components/icons/logos/CowIcon' interface Props extends GridProps { pool: PoolListItem @@ -18,6 +21,21 @@ interface Props extends GridProps { const MemoizedMainAprTooltip = memo(MainAprTooltip) +function PoolVersionTag({ pool }: { pool: PoolListItem }) { + if (isCowAmmPool(pool.type)) { + return ( + + + + ) + } else if (pool.protocolVersion === 3) { + return v3 + } else if (pool.protocolVersion === 2) { + return v2 + } + return null +} + export function PoolListTableRow({ pool, keyValue, ...rest }: Props) { const { userAddress } = usePoolListQueryState() const { toCurrency } = useCurrency() @@ -48,10 +66,13 @@ export function PoolListTableRow({ pool, keyValue, ...rest }: Props) { iconSize={20} /> - - - {getPoolTypeLabel(pool.type)} - + + + + + {getPoolTypeLabel(pool.type)} + + {userAddress && ( diff --git a/packages/lib/shared/components/badges/BalBadge.tsx b/packages/lib/shared/components/badges/BalBadge.tsx new file mode 100644 index 000000000..d704fc647 --- /dev/null +++ b/packages/lib/shared/components/badges/BalBadge.tsx @@ -0,0 +1,21 @@ +import { Badge, BadgeProps } from '@chakra-ui/react' + +export function BalBadge({ children, ...props }: BadgeProps) { + return ( + + {children} + + ) +} diff --git a/packages/lib/shared/components/icons/logos/CowIcon.tsx b/packages/lib/shared/components/icons/logos/CowIcon.tsx index 647d19453..67aeac74b 100644 --- a/packages/lib/shared/components/icons/logos/CowIcon.tsx +++ b/packages/lib/shared/components/icons/logos/CowIcon.tsx @@ -1,7 +1,7 @@ /* eslint-disable max-len */ -export function CowIcon() { +export function CowIcon({ width = 36, height = 24 }: { width?: number; height?: number }) { return ( - + Date: Thu, 17 Oct 2024 09:51:16 +0100 Subject: [PATCH 2/5] chore: Make icons circular --- .../PoolListTable/PoolListTableRow.tsx | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/packages/lib/modules/pool/PoolList/PoolListTable/PoolListTableRow.tsx b/packages/lib/modules/pool/PoolList/PoolListTable/PoolListTableRow.tsx index 3ecabe5ac..464b827c5 100644 --- a/packages/lib/modules/pool/PoolList/PoolListTable/PoolListTableRow.tsx +++ b/packages/lib/modules/pool/PoolList/PoolListTable/PoolListTableRow.tsx @@ -1,4 +1,4 @@ -import { Box, Grid, GridItem, GridProps, HStack, Text } from '@chakra-ui/react' +import { Box, Center, Grid, GridItem, GridProps, HStack, Text } from '@chakra-ui/react' import Link from 'next/link' import { getPoolPath, getPoolTypeLabel } from '../../pool.utils' import MainAprTooltip from '@repo/lib/shared/components/tooltips/apr-tooltip/MainAprTooltip' @@ -24,14 +24,28 @@ const MemoizedMainAprTooltip = memo(MainAprTooltip) function PoolVersionTag({ pool }: { pool: PoolListItem }) { if (isCowAmmPool(pool.type)) { return ( - - + +
+ +
) } else if (pool.protocolVersion === 3) { - return v3 + return ( + +
+ v2 +
+
+ ) } else if (pool.protocolVersion === 2) { - return v2 + return ( + +
+ v2 +
+
+ ) } return null } From 9ca757eeee6cf45b8f3f1763ff45914306353c04 Mon Sep 17 00:00:00 2001 From: Gareth Fuller Date: Fri, 18 Oct 2024 08:50:05 +0100 Subject: [PATCH 3/5] chore: Fix cow icon --- .../pool/PoolList/PoolListTable/PoolListTableRow.tsx | 8 ++++---- packages/lib/shared/components/icons/logos/CowIcon.tsx | 8 +++++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/lib/modules/pool/PoolList/PoolListTable/PoolListTableRow.tsx b/packages/lib/modules/pool/PoolList/PoolListTable/PoolListTableRow.tsx index 464b827c5..691142097 100644 --- a/packages/lib/modules/pool/PoolList/PoolListTable/PoolListTableRow.tsx +++ b/packages/lib/modules/pool/PoolList/PoolListTable/PoolListTableRow.tsx @@ -24,15 +24,15 @@ const MemoizedMainAprTooltip = memo(MainAprTooltip) function PoolVersionTag({ pool }: { pool: PoolListItem }) { if (isCowAmmPool(pool.type)) { return ( - +
- +
) } else if (pool.protocolVersion === 3) { return ( - +
v2
@@ -40,7 +40,7 @@ function PoolVersionTag({ pool }: { pool: PoolListItem }) { ) } else if (pool.protocolVersion === 2) { return ( - +
v2
diff --git a/packages/lib/shared/components/icons/logos/CowIcon.tsx b/packages/lib/shared/components/icons/logos/CowIcon.tsx index 67aeac74b..902001a9f 100644 --- a/packages/lib/shared/components/icons/logos/CowIcon.tsx +++ b/packages/lib/shared/components/icons/logos/CowIcon.tsx @@ -1,7 +1,13 @@ /* eslint-disable max-len */ export function CowIcon({ width = 36, height = 24 }: { width?: number; height?: number }) { return ( - + Date: Fri, 18 Oct 2024 13:53:54 +0100 Subject: [PATCH 4/5] chore: Refactor into component --- .vscode/settings.json | 5 +- .../modules/pool/PoolList/PoolListFilters.tsx | 91 ++++++++++++++++--- .../PoolListTable/PoolListTableRow.tsx | 2 +- .../pool/PoolList/usePoolListQueryState.tsx | 37 +++++++- packages/lib/modules/pool/pool.types.ts | 1 + 5 files changed, 122 insertions(+), 14 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 44a73ec3a..ea1afb54e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,5 +3,8 @@ { "mode": "auto" } - ] + ], + "[typescriptreact]": { + "editor.defaultFormatter": "esbenp.prettier-vscode" + } } diff --git a/packages/lib/modules/pool/PoolList/PoolListFilters.tsx b/packages/lib/modules/pool/PoolList/PoolListFilters.tsx index 0b3af8b83..2b8f1dd72 100644 --- a/packages/lib/modules/pool/PoolList/PoolListFilters.tsx +++ b/packages/lib/modules/pool/PoolList/PoolListFilters.tsx @@ -33,7 +33,7 @@ import { } from '@chakra-ui/react' import { PoolListSearch } from './PoolListSearch' import { getProjectConfig } from '@repo/lib/config/getProjectConfig' -import { usePoolListQueryState } from './usePoolListQueryState' +import { PROTOCOL_VERSION_TABS, usePoolListQueryState } from './usePoolListQueryState' import { PoolFilterType, poolTypeFilters, @@ -49,11 +49,14 @@ import { useDebouncedCallback } from 'use-debounce' import { defaultDebounceMs } from '@repo/lib/shared/utils/queries' import { motion, AnimatePresence } from 'framer-motion' import { staggeredFadeInUp } from '@repo/lib/shared/utils/animations' -import { getChainShortName } from '@repo/lib/config/app.config' +import { getChainShortName, isDev, isStaging } from '@repo/lib/config/app.config' import { usePoolList } from './PoolListProvider' import { MultiSelect } from '@repo/lib/shared/components/inputs/MultiSelect' -import { GqlChain } from '@repo/lib/shared/services/api/generated/graphql' +import { GqlChain, GqlPoolType } from '@repo/lib/shared/services/api/generated/graphql' import Image from 'next/image' +import ButtonGroup, { + ButtonGroupOption, +} from '@repo/lib/shared/components/btns/button-group/ButtonGroup' const SLIDER_MAX_VALUE = 10000000 const SLIDER_STEP_SIZE = 100000 @@ -133,9 +136,11 @@ function PoolTypeFilters() { } }, [poolTypes]) + const _poolTypeFilters = poolTypeFilters.filter(poolType => poolType !== GqlPoolType.CowAmm) + return ( - {poolTypeFilters.map(poolType => ( + {_poolTypeFilters.map(poolType => ( selected === poolType)} @@ -380,12 +385,71 @@ const FilterButton = forwardRef((props, ref) => { ) }) +function ProtocolVersionFilter() { + const { + togglePoolType, + setProtocolVersion, + protocolVersion, + poolTypes, + activeProtocolVersionTab, + setActiveProtocolVersionTab, + } = usePoolListQueryState() + + const tabs = + isDev || isStaging + ? PROTOCOL_VERSION_TABS + : PROTOCOL_VERSION_TABS.filter(tab => tab.value !== 'v3') + + function toggleTab(option: ButtonGroupOption) { + setActiveProtocolVersionTab(option) + } + + useEffect(() => { + if (protocolVersion === 3) { + setActiveProtocolVersionTab(tabs[2]) + } else if (protocolVersion === 2) { + setActiveProtocolVersionTab(tabs[1]) + } else if (poolTypes.includes(GqlPoolType.CowAmm)) { + setActiveProtocolVersionTab(tabs[3]) + } else { + setActiveProtocolVersionTab(tabs[0]) + } + }, []) + + useEffect(() => { + if (activeProtocolVersionTab.value === 'cow') { + togglePoolType(true, GqlPoolType.CowAmm) + } else if (activeProtocolVersionTab.value === 'v3') { + setProtocolVersion(3) + } else if (activeProtocolVersionTab.value === 'v2') { + setProtocolVersion(2) + } else { + setProtocolVersion(null) + } + }, [activeProtocolVersionTab]) + + return ( + + ) +} + export function PoolListFilters() { const { isConnected } = useUserAccount() const [isPopoverOpen, setIsPopoverOpen] = useState(false) - const { resetFilters, totalFilterCount } = usePoolListQueryState() + const { resetFilters, totalFilterCount, setActiveProtocolVersionTab } = usePoolListQueryState() const { isFixedPoolType } = usePoolList() + function _resetFilters() { + resetFilters() + setActiveProtocolVersionTab(PROTOCOL_VERSION_TABS[0]) + } + return ( @@ -412,7 +476,7 @@ export function PoolListFilters() { as={motion.div} exit="exit" initial="hidden" - spacing="xxs" + spacing="md" variants={staggeredFadeInUp} > @@ -422,13 +486,12 @@ export function PoolListFilters() { backgroundClip="text" display="inline" fontSize="xs" - lineHeight="1" variant="eyebrow" > Filters - ) : null} - + Networks + + + Protocol version + + + {!isFixedPoolType && ( - + Pool types )} - + Pool categories diff --git a/packages/lib/modules/pool/PoolList/PoolListTable/PoolListTableRow.tsx b/packages/lib/modules/pool/PoolList/PoolListTable/PoolListTableRow.tsx index 691142097..158eb4ce3 100644 --- a/packages/lib/modules/pool/PoolList/PoolListTable/PoolListTableRow.tsx +++ b/packages/lib/modules/pool/PoolList/PoolListTable/PoolListTableRow.tsx @@ -34,7 +34,7 @@ function PoolVersionTag({ pool }: { pool: PoolListItem }) { return (
- v2 + v3
) diff --git a/packages/lib/modules/pool/PoolList/usePoolListQueryState.tsx b/packages/lib/modules/pool/PoolList/usePoolListQueryState.tsx index af967017a..b1482b8e3 100644 --- a/packages/lib/modules/pool/PoolList/usePoolListQueryState.tsx +++ b/packages/lib/modules/pool/PoolList/usePoolListQueryState.tsx @@ -18,18 +18,45 @@ import { SortingState, } from '../pool.types' import { PaginationState } from '@repo/lib/shared/components/pagination/pagination.types' +import { useState } from 'react' +import { ButtonGroupOption } from '@repo/lib/shared/components/btns/button-group/ButtonGroup' + +export const PROTOCOL_VERSION_TABS: ButtonGroupOption[] = [ + { + value: 'all', + label: 'All', + }, + { + value: 'v2', + label: 'v2', + }, + { + value: 'v3', + label: 'v3', + }, + { + value: 'cow', + label: 'CoW', + }, +] as const export function usePoolListQueryState() { const [first, setFirst] = useQueryState('first', poolListQueryStateParsers.first) const [skip, setSkip] = useQueryState('skip', poolListQueryStateParsers.skip) const [orderBy, setOrderBy] = useQueryState('orderBy', poolListQueryStateParsers.orderBy) + const [activeProtocolVersionTab, setActiveProtocolVersionTab] = useState(PROTOCOL_VERSION_TABS[0]) + const [orderDirection, setOrderDirection] = useQueryState( 'orderDirection', poolListQueryStateParsers.orderDirection ) const [poolTypes, setPoolTypes] = useQueryState('poolTypes', poolListQueryStateParsers.poolTypes) + const [protocolVersion, setProtocolVersion] = useQueryState( + 'protocolVersion', + poolListQueryStateParsers.protocolVersion + ) const [networks, setNetworks] = useQueryState('networks', poolListQueryStateParsers.networks) const [textSearch, setTextSearch] = useQueryState( @@ -150,6 +177,7 @@ export function usePoolListQueryState() { setSkip(null) setOrderBy(null) setOrderDirection(null) + setProtocolVersion(null) } const totalFilterCount = @@ -157,7 +185,8 @@ export function usePoolListQueryState() { poolTypes.length + (userAddress ? 1 : 0) + (minTvl > 0 ? 1 : 0) + - poolCategories.length + poolCategories.length + + (protocolVersion ? 1 : 0) const sorting: SortingState = orderBy ? [{ id: orderBy, desc: orderDirection === GqlPoolOrderDirection.Desc }] @@ -192,6 +221,7 @@ export function usePoolListQueryState() { minTvl, tagIn: mappedPoolCategories.length > 0 ? mappedPoolCategories : null, tagNotIn: ['BLACK_LISTED'], + protocolVersionIn: protocolVersion ? [protocolVersion] : undefined, }, textSearch, } @@ -205,6 +235,7 @@ export function usePoolListQueryState() { poolTypes, networks, textSearch, + protocolVersion, }, toggleUserAddress, toggleNetwork, @@ -220,7 +251,11 @@ export function usePoolListQueryState() { resetFilters, poolCategoryLabel, setNetworks, + setProtocolVersion, + setActiveProtocolVersionTab, + activeProtocolVersionTab, poolCategories, + protocolVersion, minTvl, searchText: textSearch, pagination, diff --git a/packages/lib/modules/pool/pool.types.ts b/packages/lib/modules/pool/pool.types.ts index b824b814b..d5a32c462 100644 --- a/packages/lib/modules/pool/pool.types.ts +++ b/packages/lib/modules/pool/pool.types.ts @@ -119,6 +119,7 @@ export const poolListQueryStateParsers = { parseAsStringEnum(Object.values(poolTypeFilters)) ).withDefault([]), networks: parseAsArrayOf(parseAsStringEnum(Object.values(GqlChain))).withDefault([]), + protocolVersion: parseAsInteger, textSearch: parseAsString, userAddress: parseAsString, minTvl: parseAsFloat.withDefault(0), From 0f2893140b3a2991b9c4461a79d1f09ffe7b8301 Mon Sep 17 00:00:00 2001 From: Gareth Fuller Date: Fri, 18 Oct 2024 16:17:58 +0100 Subject: [PATCH 5/5] fix: CoW toggle --- packages/lib/modules/pool/PoolList/PoolListFilters.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/lib/modules/pool/PoolList/PoolListFilters.tsx b/packages/lib/modules/pool/PoolList/PoolListFilters.tsx index 2b8f1dd72..86da82972 100644 --- a/packages/lib/modules/pool/PoolList/PoolListFilters.tsx +++ b/packages/lib/modules/pool/PoolList/PoolListFilters.tsx @@ -419,7 +419,11 @@ function ProtocolVersionFilter() { useEffect(() => { if (activeProtocolVersionTab.value === 'cow') { togglePoolType(true, GqlPoolType.CowAmm) - } else if (activeProtocolVersionTab.value === 'v3') { + } else { + togglePoolType(false, GqlPoolType.CowAmm) + } + + if (activeProtocolVersionTab.value === 'v3') { setProtocolVersion(3) } else if (activeProtocolVersionTab.value === 'v2') { setProtocolVersion(2)