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 hook tag on pools list #211

Merged
merged 4 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions packages/lib/modules/hooks/useHook.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
import { Pool } from '../pool/PoolProvider'
import {
GqlChain,
GqlHook,
GqlPoolTokenDetail,
} from '@repo/lib/shared/services/api/generated/graphql'
import { useHooks } from './HooksProvider'
import { getChainId } from '@repo/lib/config/app.config'

export function useHook(pool: Pool) {
export function useHook({
hook,
poolTokens,
chain,
}: {
hook: GqlHook | null | undefined
Copy link
Contributor

@garethfuller garethfuller Nov 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert to just pass in the pool. It's more verbose in all the components you need to use this hook or the hook tag component otherwise. If you did it because of the different pool types between the detail and list then just set the prop style as Pool | PoolListItem, it should work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are different pool types in pools vs pool query, that's why decided to pass just properties

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, like I said, can you not just use the type Pool | PoolListItem?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

poolTokens: GqlPoolTokenDetail[]
chain: GqlChain
}) {
const { metadata } = useHooks()
const hasHook = !!pool.hook?.address
const hasNestedHook = pool.poolTokens.map(token => token.nestedPool?.hook).some(Boolean)
const hasHook = !!hook?.address
const hasNestedHook = poolTokens.map(token => token.nestedPool?.hook).some(Boolean)

const hookAddresses = [
...(hasHook ? [pool.hook?.address] : []),
...pool.poolTokens.map(token => token.nestedPool?.hook?.address),
...(hasHook ? [hook.address] : []),
...poolTokens.map(token => token.nestedPool?.hook?.address),
]

const chainId = getChainId(pool.chain)
const chainId = getChainId(chain)

const hooks = hookAddresses
.map(hookAddress =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { getChainShortName } from '@repo/lib/config/app.config'
import { PoolTypeTag } from '../PoolTypeTag'
import { PoolVersionTag } from '../../PoolList/PoolListTable/PoolVersionTag'
import { PoolHookTag } from '../PoolHookTag'
import { GqlPoolTokenDetail } from '@repo/lib/shared/services/api/generated/graphql'

export default function PoolMetaBadges() {
const { pool, chain } = usePool()
Expand All @@ -45,7 +46,11 @@ export default function PoolMetaBadges() {
<PoolListTokenPills pool={pool} px="sm" py="2" />
<PoolVersionTag isSmall pool={pool} />
<PoolTypeTag pool={pool} />
<PoolHookTag />
<PoolHookTag
chain={pool.chain}
poolHook={pool.hook}
poolTokens={pool.poolTokens as GqlPoolTokenDetail[]}
/>
{!shouldHideSwapFee(pool.type) && (
<Popover trigger="hover">
<PopoverTrigger>
Expand Down
7 changes: 6 additions & 1 deletion packages/lib/modules/pool/PoolDetail/PoolHookBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@ import { Badge, Card, Center, Heading, HStack, Stack, Text, VStack } from '@chak
import { useHook } from '../../hooks/useHook'
import { usePool } from '../PoolProvider'
import { HookIcon } from '@repo/lib/shared/components/icons/HookIcon'
import { GqlPoolTokenDetail } from '@repo/lib/shared/services/api/generated/graphql'

export function PoolHookBanner() {
const { pool } = usePool()
const { hooks, hasHookData } = useHook(pool)
const { hooks, hasHookData } = useHook({
hook: pool.hook,
poolTokens: pool.poolTokens as GqlPoolTokenDetail[],
chain: pool.chain,
})

if (!hasHookData) return null

Expand Down
44 changes: 34 additions & 10 deletions packages/lib/modules/pool/PoolDetail/PoolHookTag.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
import { Badge, Center, Popover, PopoverContent, PopoverTrigger, Text } from '@chakra-ui/react'
import {
Badge,
Center,
Popover,
PopoverContent,
PopoverTrigger,
Portal,
Text,
} from '@chakra-ui/react'
import { HookIcon } from '@repo/lib/shared/components/icons/HookIcon'
import { useHook } from '../../hooks/useHook'
import { usePool } from '../PoolProvider'

export function PoolHookTag() {
const { pool } = usePool()
const { hooks } = useHook(pool)
import {
GqlHook,
GqlPoolTokenDetail,
GqlChain,
} from '@repo/lib/shared/services/api/generated/graphql'

type Props = {
poolHook: GqlHook | null | undefined
poolTokens: GqlPoolTokenDetail[]
chain: GqlChain
}

export function PoolHookTag({ poolHook, poolTokens, chain }: Props) {
const { hooks } = useHook({
hook: poolHook,
poolTokens,
chain,
})

// TODO: add nested hook support when needed

Expand Down Expand Up @@ -35,11 +57,13 @@ export function PoolHookTag() {
</Center>
</Badge>
</PopoverTrigger>
<PopoverContent px="sm" py="sm" width="fit-content">
<Text fontSize="sm" variant="secondary">
{hook.name}
</Text>
</PopoverContent>
<Portal>
<PopoverContent px="sm" py="sm" width="fit-content">
<Text fontSize="sm" variant="secondary">
{hook.name}
</Text>
</PopoverContent>
</Portal>
</Popover>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function PoolListTable({ pools, count, loading }: Props) {

const rowProps = {
px: { base: 'sm', sm: '0' },
gridTemplateColumns: `32px minmax(320px, 1fr) 100px ${
gridTemplateColumns: `32px minmax(320px, 1fr) 150px ${
userAddress ? furthestLeftColWidth : ''
} ${userAddress ? numberColumnWidth : furthestLeftColWidth} ${numberColumnWidth} 200px`,
alignItems: 'center',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { isBoosted } from '../../pool.helpers'
import { TokenIcon } from '@repo/lib/modules/tokens/TokenIcon'
import { useErc4626Metadata } from '../../../erc4626/Erc4626MetadataProvider'
import Image from 'next/image'
import { PoolHookTag } from '../../PoolDetail/PoolHookTag'
import { GqlPoolTokenDetail } from '@repo/lib/shared/services/api/generated/graphql'
alter-eggo marked this conversation as resolved.
Show resolved Hide resolved

interface Props extends GridProps {
pool: PoolListItem
Expand Down Expand Up @@ -102,6 +104,11 @@ export function PoolListTableRow({ pool, keyValue, ...rest }: Props) {
width={20}
/>
))}
<PoolHookTag
chain={pool.chain}
poolHook={pool.hook}
poolTokens={pool.poolTokens as GqlPoolTokenDetail[]}
/>
</HStack>
</GridItem>
{userAddress ? (
Expand Down
6 changes: 5 additions & 1 deletion packages/lib/modules/pool/alerts/usePoolAlerts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ export function usePoolAlerts(pool: Pool) {
const pathname = usePathname()
const router = useRouter()
const [poolAlerts, setPoolAlerts] = useState<PoolAlert[]>([])
const { hooks } = useHook(pool)
const { hooks } = useHook({
hook: pool.hook,
poolTokens: pool.poolTokens as GqlPoolTokenDetail[],
chain: pool.chain,
})

const getNetworkPoolAlerts = (pool: Pool): PoolAlert[] => {
const networkPoolsIssues = getNetworkConfig(pool.chain).pools?.issues
Expand Down
3 changes: 3 additions & 0 deletions packages/lib/shared/services/api/pools.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ query GetPools(
symbol
}
}
hook {
...Hook
}
dynamicData {
totalLiquidity
lifetimeVolume
Expand Down
Loading