Skip to content

Commit

Permalink
Actually fix the pool header
Browse files Browse the repository at this point in the history
  • Loading branch information
noisekit committed Nov 26, 2024
1 parent 16485f3 commit 455074f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 21 deletions.
2 changes: 1 addition & 1 deletion liquidity/lib/usePoolsList/usePoolsList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function usePoolsList() {
});
}

export function usePool(networkId: number, poolId: string) {
export function usePool(networkId?: number, poolId?: string) {
const { data, isPending } = usePoolsList();

// TODO: In the future if we have multiple pools per network filter by poolId also
Expand Down
25 changes: 17 additions & 8 deletions liquidity/ui/src/components/Manage/PositionTitle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,23 @@ import { useCollateralType } from '@snx-v3/useCollateralTypes';
import { usePool } from '@snx-v3/usePoolsList';
import { useParams } from '@snx-v3/useParams';

export const PositionTitle: FC<{
export function PositionTitle({
collateralSymbol,
isOpen,
}: {
collateralSymbol?: string;
isOpen: boolean;
}> = ({ collateralSymbol, isOpen }) => {
const { poolId, networkId } = useParams();
const { data: pool } = usePool(Number(networkId), String(poolId));
const { data: collateral } = useCollateralType(collateralSymbol);
}) {
const params = useParams();

const { network } = useNetwork();
const navigate = useNavigate();
const { data: pool } = usePool(network?.id, String(params.poolId));

const poolName = pool?.poolInfo?.[0]?.pool?.name ?? '';

const navigate = useNavigate();
const { data: collateral } = useCollateralType(collateralSymbol);

return (
<Flex alignItems="center">
<Flex
Expand Down Expand Up @@ -54,7 +61,9 @@ export const PositionTitle: FC<{
alignItems="center"
_hover={{ cursor: 'pointer' }}
onClick={
poolId && networkId ? () => navigate(`/pools/${network?.id}/${poolId}`) : undefined
params.poolId && network?.id
? () => navigate(`/pools/${network?.id}/${params.poolId}`)
: undefined
}
>
<Text mr={2}>{poolName}</Text>
Expand All @@ -72,4 +81,4 @@ export const PositionTitle: FC<{
</Flex>
</Flex>
);
};
}
13 changes: 8 additions & 5 deletions liquidity/ui/src/components/Pools/PoolHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { Flex, Heading, Skeleton, Tag, Text } from '@chakra-ui/react';
import { ARBITRUM, MAINNET, NetworkIcon, NETWORKS } from '@snx-v3/useBlockchain';
import { ARBITRUM, MAINNET, NetworkIcon, NETWORKS, useNetwork } from '@snx-v3/useBlockchain';
import { useParams } from '@snx-v3/useParams';
import { usePool } from '@snx-v3/usePoolsList';

export function PoolHeader() {
const { poolId, networkId } = useParams();
const { data: pool, isPending } = usePool(Number(networkId), String(poolId));
const network = NETWORKS.find((n) => n.id === Number(networkId));
const params = useParams();

const { network: connectedNetwork } = useNetwork();
const networkId = params.networkId ? Number(params.networkId) : connectedNetwork?.id;
const { data: pool, isPending } = usePool(networkId, String(params.poolId));
const network = NETWORKS.find((n) => n.id === networkId);

const poolName = pool?.poolInfo?.[0]?.pool?.name ?? '';
const networkName = network?.name ?? '';
Expand All @@ -19,7 +22,7 @@ export function PoolHeader() {
{poolName ? poolName : 'Unknown Pool'}
</Heading>
</Skeleton>
{Number(networkId) === MAINNET.id || Number(networkId) === ARBITRUM.id ? (
{networkId === MAINNET.id || networkId === ARBITRUM.id ? (
<Tag size="sm" bg="purple.500" mr="auto" color="white" height="fit-content">
Borrow Interest-Free
</Tag>
Expand Down
18 changes: 11 additions & 7 deletions liquidity/ui/src/pages/Pool.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import { Box, Divider, Flex, Heading, Link } from '@chakra-ui/react';
import { Helmet } from 'react-helmet';
import { PoolHeader, CollateralSection } from '../components';
import { useParams } from '@snx-v3/useParams';
import { HomeLink } from '@snx-v3/HomeLink';
import { NETWORKS, useNetwork } from '@snx-v3/useBlockchain';
import { useParams } from '@snx-v3/useParams';
import { usePool } from '@snx-v3/usePoolsList';
import { NETWORKS } from '@snx-v3/useBlockchain';
import { Helmet } from 'react-helmet';
import { NavLink } from 'react-router-dom';
import { CollateralSection, PoolHeader } from '../components';

export const Pool = () => {
const { poolId, networkId } = useParams();
const { data: pool, isPending } = usePool(Number(networkId), String(poolId));
const network = NETWORKS.find((n) => n.id === Number(networkId));
const params = useParams();

const { network: connectedNetwork } = useNetwork();
const networkId = params.networkId ? Number(params.networkId) : connectedNetwork?.id;
const { data: pool, isPending } = usePool(networkId, String(params.poolId));
const network = NETWORKS.find((n) => n.id === networkId);

const title = pool
? `Pool #${pool.poolInfo?.[0]?.pool?.id} / ${pool.poolInfo?.[0]?.pool?.name}`
: 'Pool';
Expand Down

0 comments on commit 455074f

Please sign in to comment.