Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 1 addition & 16 deletions apps/hyperdrive-trading/src/ui/landing/Landing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,7 @@ export function Landing(): ReactElement | null {
<div className="flex flex-col items-center gap-4 lg:w-[900px]">
<Hero />
<div className="flex w-full flex-col items-center">
<div className="flex flex-col gap-4">
{/* TODO: Implement filter buttons
<div className="flex items-center gap-3">
<button className="daisy-btn daisy-btn-sm gap-1.5 rounded-full">
All Terms
<ChevronDownIcon className="ml-1 size-4 text-neutral-content" />
</button>
<button className="daisy-btn daisy-btn-sm gap-1.5 rounded-full">
All Assets
<ChevronDownIcon className="ml-1 size-4 text-neutral-content" />
</button>
<button className="daisy-btn daisy-btn-sm gap-1.5 rounded-full">
All Chains
<ChevronDownIcon className="ml-1 size-4 text-neutral-content" />
</button>
</div> */}
<div className="flex w-full flex-col gap-4">
<PoolsList />
</div>
</div>
Expand Down
64 changes: 37 additions & 27 deletions apps/hyperdrive-trading/src/ui/markets/PoolsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import {
BarsArrowDownIcon,
} from "@heroicons/react/20/solid";
import { QueryStatus, useQuery } from "@tanstack/react-query";
import { useNavigate, useSearch } from "@tanstack/react-router";
import { getPublicClient } from "@wagmi/core";
import { ReactElement, ReactNode, useMemo, useRef, useState } from "react";
import { ReactElement, ReactNode, useMemo, useState } from "react";
import { ZERO_ADDRESS } from "src/base/constants";
import { isTestnetChain } from "src/chains/isTestnetChain";
import { calculateMarketYieldMultiplier } from "src/hyperdrive/calculateMarketYieldMultiplier";
Expand All @@ -25,6 +26,7 @@ import LoadingState from "src/ui/base/components/LoadingState";
import { MultiSelect } from "src/ui/base/components/MultiSelect";
import { NonIdealState } from "src/ui/base/components/NonIdealState";
import { Well } from "src/ui/base/components/Well/Well";
import { LANDING_ROUTE } from "src/ui/landing/routes";
import { PoolRow, PoolRowProps } from "src/ui/markets/PoolRow";
import { PublicClient } from "viem";
import { useChainId } from "wagmi";
Expand All @@ -41,6 +43,10 @@ type SortOption = (typeof sortOptions)[number];

export function PoolsList(): ReactElement {
const { pools: allPools, status } = usePoolsList();
const { chains: selectedChains, assets: selectedAssets } = useSearch({
from: LANDING_ROUTE,
});
const navigate = useNavigate({ from: LANDING_ROUTE });
const [sort, setSort] = useState<SortOption>("TVL");

// Sync filters with pools
Expand Down Expand Up @@ -88,21 +94,18 @@ export function PoolsList(): ReactElement {
};
}, [allPools]);

const [selectedChains, setSelectedChains] = useState<number[]>([]);
const [selectedAssets, setSelectedAssets] = useState<string[]>([]);

// Filter and sort pools
const selectedPools = allPools
?.filter((pool) => {
if (
selectedChains.length &&
selectedChains?.length &&
!selectedChains.includes(pool.hyperdrive.chainId)
) {
return false;
}

if (
selectedAssets.length &&
selectedAssets?.length &&
!pool.depositAssets.some(({ symbol }) =>
selectedAssets.includes(symbol),
)
Expand Down Expand Up @@ -136,14 +139,8 @@ export function PoolsList(): ReactElement {
}
});

// To prevent jarring layout shifts when no pools match the selected filters,
// the NonIdealState is wrapped in a div with a width set to match the outer
// container's width, which will be the width it rendered at before the
// filter's were changed.
const containerRef = useRef<HTMLDivElement>(null);

return (
<div className="flex w-full flex-col gap-5" ref={containerRef}>
<div className="flex w-full flex-col gap-5">
{status === "loading" && !selectedPools ? (
<LoadingState />
) : selectedPools ? (
Expand All @@ -157,13 +154,22 @@ export function PoolsList(): ReactElement {
{filters && filters.chains.length > 1 && (
<MultiSelect
title="Filter by chain"
selected={selectedChains}
onChange={setSelectedChains}
selected={selectedChains || []}
onChange={(chains) =>
navigate({
search: (current) => {
return {
...current,
chains,
};
},
})
}
displayValue={
selectedChains.length === 1
selectedChains?.length === 1
? appConfig.chains[selectedChains[0]].name
: `${
selectedChains.length || filters?.chains.length
selectedChains?.length || filters?.chains.length
} chains`
}
searchEnabled
Expand All @@ -185,13 +191,22 @@ export function PoolsList(): ReactElement {
{filters && filters.assets.length > 1 && (
<MultiSelect
title="Filter by deposit asset"
selected={selectedAssets}
onChange={setSelectedAssets}
selected={selectedAssets || []}
onChange={(assets) =>
navigate({
search: (current) => {
return {
...current,
assets,
};
},
})
}
displayValue={
selectedAssets.length === 1
selectedAssets?.length === 1
? selectedAssets[0]
: `${
selectedAssets.length || filters.assets.length
selectedAssets?.length || filters.assets.length
} assets`
}
searchEnabled
Expand Down Expand Up @@ -248,12 +263,7 @@ export function PoolsList(): ReactElement {
</div>

{!selectedPools.length ? (
<Well
className="max-w-[90vw]"
style={{
width: containerRef.current?.offsetWidth,
}}
>
<Well className="max-w-[90vw]">
{allPools?.length ? (
<NonIdealState
heading={"No pools found"}
Expand Down
5 changes: 5 additions & 0 deletions apps/hyperdrive-trading/src/ui/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@ import { createFileRoute } from "@tanstack/react-router";
import { Page } from "src/ui/app/Page";
import { Landing } from "src/ui/landing/Landing";
import { LANDING_ROUTE } from "src/ui/landing/routes";
import { z } from "zod";

export const Route = createFileRoute(LANDING_ROUTE)({
component: () => (
<Page>
<Landing />
</Page>
),
validateSearch: z.object({
chains: z.array(z.number()).optional(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add the sorting as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, will do in a followup PR

assets: z.array(z.string()).optional(),
}),
});
Loading