diff --git a/apps/hyperdrive-trading/src/ui/portfolio/Portfolio.tsx b/apps/hyperdrive-trading/src/ui/portfolio/Portfolio.tsx index 52fdcc51c..999df5b33 100644 --- a/apps/hyperdrive-trading/src/ui/portfolio/Portfolio.tsx +++ b/apps/hyperdrive-trading/src/ui/portfolio/Portfolio.tsx @@ -2,10 +2,10 @@ import { useNavigate, useSearch } from "@tanstack/react-router"; import { ReactElement } from "react"; import { Tabs } from "src/ui/base/components/Tabs/Tabs"; import { useFeatureFlag } from "src/ui/base/featureFlags/featureFlags"; -import { OpenLongsContainer } from "src/ui/portfolio/longs/OpenLongsTable/OpenLongsTableDesktop"; -import { LpAndWithdrawalSharesContainer } from "src/ui/portfolio/lp/LpAndWithdrawalSharesTable/LpAndWithdrawalSharesTable"; +import { OpenLongsContainer } from "src/ui/portfolio/longs/LongsContainer"; +import { LpAndWithdrawalSharesContainer } from "src/ui/portfolio/lp/LpAndWithdrawalSharesContainer"; import { PORTFOLIO_ROUTE } from "src/ui/portfolio/routes"; -import { OpenShortsContainer } from "src/ui/portfolio/shorts/OpenShortsTable/OpenShortsTableDesktop"; +import { OpenShortsContainer } from "src/ui/portfolio/shorts/ShortsContainer"; export function Portfolio(): ReactElement { const { position } = useSearch({ from: PORTFOLIO_ROUTE }); diff --git a/apps/hyperdrive-trading/src/ui/portfolio/PositionContainer.tsx b/apps/hyperdrive-trading/src/ui/portfolio/PositionContainer.tsx new file mode 100644 index 000000000..a2834a00c --- /dev/null +++ b/apps/hyperdrive-trading/src/ui/portfolio/PositionContainer.tsx @@ -0,0 +1,13 @@ +import classNames from "classnames"; +import { PropsWithChildren, ReactElement } from "react"; + +export function PositionContainer({ + className, + children, +}: PropsWithChildren<{ className?: string }>): ReactElement { + return ( +
+ {children} +
+ ); +} diff --git a/apps/hyperdrive-trading/src/ui/portfolio/PositionTableHeading.tsx b/apps/hyperdrive-trading/src/ui/portfolio/PositionTableHeading.tsx new file mode 100644 index 000000000..a48720639 --- /dev/null +++ b/apps/hyperdrive-trading/src/ui/portfolio/PositionTableHeading.tsx @@ -0,0 +1,29 @@ +import { HyperdriveConfig } from "@delvtech/hyperdrive-appconfig"; +import { ReactElement, ReactNode } from "react"; +import { AssetStack } from "src/ui/markets/AssetStack"; + +export function PositionTableHeading({ + hyperdrive, + hyperdriveName, + rightElement, +}: { + hyperdrive: HyperdriveConfig; + /** + * Optional name to override the name from the hyperdrive + */ + hyperdriveName?: string; + rightElement: ReactNode; +}): ReactElement { + return ( +
+
+ +

{hyperdriveName ?? hyperdrive.name}

+
+ {rightElement} +
+ ); +} diff --git a/apps/hyperdrive-trading/src/ui/portfolio/longs/LongsContainer.tsx b/apps/hyperdrive-trading/src/ui/portfolio/longs/LongsContainer.tsx new file mode 100644 index 000000000..619bc2113 --- /dev/null +++ b/apps/hyperdrive-trading/src/ui/portfolio/longs/LongsContainer.tsx @@ -0,0 +1,114 @@ +import { appConfig, HyperdriveConfig } from "@delvtech/hyperdrive-appconfig"; +import { Link } from "@tanstack/react-router"; +import { ReactElement } from "react"; +import { ExternalLink } from "src/ui/analytics/ExternalLink"; +import LoadingState from "src/ui/base/components/LoadingState"; +import { NonIdealState } from "src/ui/base/components/NonIdealState"; +import { ConnectWalletButton } from "src/ui/compliance/ConnectWallet"; +import { OpenLongsTableDesktop } from "src/ui/portfolio/longs/OpenLongsTable/OpenLongsTableDesktop"; +import { TotalOpenLongsValue } from "src/ui/portfolio/longs/TotalOpenLongsValue/TotalOpenLongsValue"; +import { + OpenLongPositionsData, + usePortfolioLongsData, +} from "src/ui/portfolio/longs/usePortfolioLongsData"; +import { PositionContainer } from "src/ui/portfolio/PositionContainer"; +import { PositionTableHeading } from "src/ui/portfolio/PositionTableHeading"; +import { useAccount } from "wagmi"; + +export function OpenLongsContainer(): ReactElement { + const { address: account } = useAccount(); + const { openLongPositions, openLongPositionsStatus } = + usePortfolioLongsData(); + if (!account) { + return ( + + } + /> + + ); + } + + if (openLongPositionsStatus === "loading") { + return ( + + + + ); + } + + if (openLongPositions?.every((position) => !position.openLongs.length)) { + return ( + + + Visit the{" "} + + documentation + {" "} + or explore pools to open your first Long position. +

+ } + action={ + + View Pools + + } + /> +
+ ); + } + + return ( + + {openLongPositions && + appConfig.hyperdrives + .filter((hyperdrive) => { + const openLongs = findOpenLongs( + openLongPositions, + hyperdrive, + )?.openLongs; + // Ensure this hyperdrive pool has open positions before rendering. + return openLongPositionsStatus === "success" && openLongs?.length; + }) + .map((hyperdrive) => { + const openLongs = findOpenLongs( + openLongPositions, + hyperdrive, + )?.openLongs; + return ( +
+ } + /> + +
+ ); + })} +
+ ); +} + +function findOpenLongs( + openLongPositions: OpenLongPositionsData, + hyperdrive: HyperdriveConfig, +) { + return openLongPositions.find( + (position) => + position.hyperdrive.address === hyperdrive.address && + position.hyperdrive.chainId === hyperdrive.chainId, + ); +} diff --git a/apps/hyperdrive-trading/src/ui/portfolio/longs/OpenLongsTable/OpenLongsTableDesktop.tsx b/apps/hyperdrive-trading/src/ui/portfolio/longs/OpenLongsTable/OpenLongsTableDesktop.tsx index 0cd1711d2..0b9d7a3c3 100644 --- a/apps/hyperdrive-trading/src/ui/portfolio/longs/OpenLongsTable/OpenLongsTableDesktop.tsx +++ b/apps/hyperdrive-trading/src/ui/portfolio/longs/OpenLongsTable/OpenLongsTableDesktop.tsx @@ -2,7 +2,6 @@ import { AppConfig, appConfig, getBaseToken, - getToken, HyperdriveConfig, } from "@delvtech/hyperdrive-appconfig"; import { @@ -10,7 +9,6 @@ import { OpenLongPositionReceived, } from "@delvtech/hyperdrive-js"; import { ChevronDownIcon, ChevronUpIcon } from "@heroicons/react/24/outline"; -import { Link } from "@tanstack/react-router"; import { createColumnHelper, flexRender, @@ -24,7 +22,6 @@ import { ReactElement } from "react"; import { calculateAnnualizedPercentageChange } from "src/base/calculateAnnualizedPercentageChange"; import { convertMillisecondsToDays } from "src/base/convertMillisecondsToDays"; import { formatRate } from "src/base/formatRate"; -import LoadingState from "src/ui/base/components/LoadingState"; import { NonIdealState } from "src/ui/base/components/NonIdealState"; import { Pagination } from "src/ui/base/components/Pagination"; import { formatBalance } from "src/ui/base/formatting/formatBalance"; @@ -33,126 +30,9 @@ import { MaturesOnCell } from "src/ui/hyperdrive/MaturesOnCell/MaturesOnCell"; import { CloseLongModalButton } from "src/ui/hyperdrive/longs/CloseLongModalButton/CloseLongModalButton"; import { StatusCell } from "src/ui/hyperdrive/longs/StatusCell"; import { CurrentValueCell } from "src/ui/portfolio/longs/OpenLongsTable/CurrentValueCell"; -import { TotalOpenLongsValue } from "src/ui/portfolio/longs/OpenLongsTable/TotalOpenLongsValue"; -import { usePortfolioLongsData } from "src/ui/portfolio/longs/usePortfolioLongsData"; import { useAccount } from "wagmi"; import { ManageLongsButton } from "./ManageLongsButton"; -export function OpenLongsContainer(): ReactElement { - const { address: account } = useAccount(); - const { openLongPositions, openLongPositionsStatus } = - usePortfolioLongsData(); - if (!account) { - return ( -
- } - /> -
- ); - } - - if (openLongPositionsStatus === "loading") { - return ( -
- -
- ); - } - - if (openLongPositions?.every((position) => position.openLongs.length === 0)) { - return ( -
- - Visit the{" "} - - documentation - {" "} - or explore pools to open your first Long position. -

- } - action={ - - View Pools - - } - /> -
- ); - } - - return ( -
- {appConfig.hyperdrives.map((hyperdrive) => { - const openLongs = openLongPositions?.find( - (position) => - position.hyperdrive.address === hyperdrive.address && - position.hyperdrive.chainId === hyperdrive.chainId, - )?.openLongs; - const baseToken = getBaseToken({ - hyperdriveChainId: hyperdrive.chainId, - hyperdriveAddress: hyperdrive.address, - appConfig, - }); - const sharesToken = getToken({ - chainId: hyperdrive.chainId, - tokenAddress: hyperdrive.poolConfig.vaultSharesToken, - appConfig, - }); - // Ensure this hyperdrive pool has open positions before rendering. - if (openLongPositionsStatus === "success" && !openLongs?.length) { - return null; - } - return ( -
-
-
-
- {hyperdrive.depositOptions.isBaseTokenDepositEnabled ? ( -
- -
- ) : null} - {sharesToken && - hyperdrive.depositOptions.isShareTokenDepositsEnabled ? ( -
- -
- ) : null} -
-

{hyperdrive.name}

-
- -
- -
- ); - })} -
- ); -} - export function OpenLongsTableDesktop({ hyperdrive, openLongs, diff --git a/apps/hyperdrive-trading/src/ui/portfolio/longs/OpenLongsTable/TotalOpenLongsValue.tsx b/apps/hyperdrive-trading/src/ui/portfolio/longs/TotalOpenLongsValue/TotalOpenLongsValue.tsx similarity index 100% rename from apps/hyperdrive-trading/src/ui/portfolio/longs/OpenLongsTable/TotalOpenLongsValue.tsx rename to apps/hyperdrive-trading/src/ui/portfolio/longs/TotalOpenLongsValue/TotalOpenLongsValue.tsx diff --git a/apps/hyperdrive-trading/src/ui/portfolio/longs/usePortfolioLongsData.ts b/apps/hyperdrive-trading/src/ui/portfolio/longs/usePortfolioLongsData.ts index 28ca65d92..b35e99c4a 100644 --- a/apps/hyperdrive-trading/src/ui/portfolio/longs/usePortfolioLongsData.ts +++ b/apps/hyperdrive-trading/src/ui/portfolio/longs/usePortfolioLongsData.ts @@ -9,7 +9,7 @@ import { getDrift } from "src/drift/getDrift"; import { useAppConfigForConnectedChain } from "src/ui/appconfig/useAppConfigForConnectedChain"; import { useAccount } from "wagmi"; -type OpenLongPositionsData = { +export type OpenLongPositionsData = { hyperdrive: HyperdriveConfig; openLongs: OpenLongPositionReceived[]; }[]; diff --git a/apps/hyperdrive-trading/src/ui/portfolio/lp/LpAndWithdrawalSharesContainer.tsx b/apps/hyperdrive-trading/src/ui/portfolio/lp/LpAndWithdrawalSharesContainer.tsx new file mode 100644 index 000000000..15ed190e0 --- /dev/null +++ b/apps/hyperdrive-trading/src/ui/portfolio/lp/LpAndWithdrawalSharesContainer.tsx @@ -0,0 +1,123 @@ +import { appConfig } from "@delvtech/hyperdrive-appconfig"; +import { Link } from "@tanstack/react-router"; +import { ReactElement } from "react"; +import { ExternalLink } from "src/ui/analytics/ExternalLink"; +import LoadingState from "src/ui/base/components/LoadingState"; +import { NonIdealState } from "src/ui/base/components/NonIdealState"; +import { ConnectWalletButton } from "src/ui/compliance/ConnectWallet"; +import { OpenLpTableDesktop } from "src/ui/portfolio/lp/LpAndWithdrawalSharesTable/LpAndWithdrawalSharesTable"; +import { TotalLpValue } from "src/ui/portfolio/lp/LpAndWithdrawalSharesTable/TotalLpValue"; +import { usePortfolioLpData } from "src/ui/portfolio/lp/usePortfolioLpData"; +import { PositionContainer } from "src/ui/portfolio/PositionContainer"; +import { PositionTableHeading } from "src/ui/portfolio/PositionTableHeading"; +import { useAccount } from "wagmi"; + +export function LpAndWithdrawalSharesContainer(): ReactElement { + const { openLpPositions, openLpPositionStatus } = usePortfolioLpData(); + const { address: account } = useAccount(); + if (!account) { + return ( + + } + /> + + ); + } + + if (openLpPositionStatus === "loading") { + return ( + + + + ); + } + if (openLpPositionStatus === "error") { + return ( + + + + ); + } + + const hasOpenPositions = openLpPositions?.some( + (position) => position.lpShares > 0n || position.withdrawalShares > 0n, + ); + + if (!hasOpenPositions) { + return ( + + + Visit the{" "} + + documentation + {" "} + or explore pools to open your first LP position. +

+ } + action={ + + View Pools + + } + /> +
+ ); + } + + return ( + + {appConfig.hyperdrives.map((hyperdrive) => { + const openLpPosition = openLpPositions?.find( + (position) => + position.hyperdrive.address === hyperdrive.address && + position.hyperdrive.chainId === hyperdrive.chainId, + ) ?? { + lpShares: 0n, + withdrawalShares: 0n, + }; + + // Check if this hyperdrive pool has open positions before rendering + if ( + openLpPosition.lpShares === 0n && + openLpPosition.withdrawalShares === 0n + ) { + return null; + } + + return ( +
+ } + hyperdriveName={ + // This regex removes the term (eg: "30d") from the hyperdrive + // name since it's already shown in the table. + // https://regex101.com/r/f4A3th/1 + hyperdrive.name.replace(/\d{1,3}d/, "") + } + /> + +
+ ); + })} +
+ ); +} diff --git a/apps/hyperdrive-trading/src/ui/portfolio/lp/LpAndWithdrawalSharesTable/LpAndWithdrawalSharesTable.tsx b/apps/hyperdrive-trading/src/ui/portfolio/lp/LpAndWithdrawalSharesTable/LpAndWithdrawalSharesTable.tsx index aaafc3d2d..1e22484ca 100644 --- a/apps/hyperdrive-trading/src/ui/portfolio/lp/LpAndWithdrawalSharesTable/LpAndWithdrawalSharesTable.tsx +++ b/apps/hyperdrive-trading/src/ui/portfolio/lp/LpAndWithdrawalSharesTable/LpAndWithdrawalSharesTable.tsx @@ -4,7 +4,6 @@ import { getBaseToken, HyperdriveConfig, } from "@delvtech/hyperdrive-appconfig"; -import { Link } from "@tanstack/react-router"; import { createColumnHelper, flexRender, @@ -17,135 +16,12 @@ import { convertMillisecondsToDays } from "src/base/convertMillisecondsToDays"; import LoadingState from "src/ui/base/components/LoadingState"; import { NonIdealState } from "src/ui/base/components/NonIdealState"; import { ConnectWalletButton } from "src/ui/compliance/ConnectWallet"; -import { AssetStack } from "src/ui/markets/AssetStack"; import { LpCurrentValueCell } from "src/ui/portfolio/lp/LpAndWithdrawalSharesTable/LpCurrentValueCell"; import { ManageLpAndWithdrawalSharesButton } from "src/ui/portfolio/lp/LpAndWithdrawalSharesTable/ManageLpAndWithdrawalSharesButton"; import { SizeAndPoolShareCell } from "src/ui/portfolio/lp/LpAndWithdrawalSharesTable/SizeAndPoolShareCell"; -import { TotalLpValue } from "src/ui/portfolio/lp/LpAndWithdrawalSharesTable/TotalLpValue"; import { WithdrawalQueueCell } from "src/ui/portfolio/lp/LpAndWithdrawalSharesTable/WithdrawalQueueCell"; -import { usePortfolioLpData } from "src/ui/portfolio/lp/usePortfolioLpData"; import { useAccount } from "wagmi"; -export function LpAndWithdrawalSharesContainer(): ReactElement { - const { openLpPositions, openLpPositionStatus } = usePortfolioLpData(); - const { address: account } = useAccount(); - if (!account) { - return ( -
- } - /> -
- ); - } - - if (openLpPositionStatus === "loading") { - return ( -
- -
- ); - } - if (openLpPositionStatus === "error") { - return ( -
- -
- ); - } - - const hasOpenPositions = openLpPositions?.some( - (position) => position.lpShares > 0n || position.withdrawalShares > 0n, - ); - - if (!hasOpenPositions) { - return ( -
- - Visit the{" "} - - documentation - {" "} - or explore pools to open your first LP position. -

- } - action={ - - View Pools - - } - /> -
- ); - } - - return ( -
- {appConfig.hyperdrives.map((hyperdrive) => { - const openLpPosition = openLpPositions?.find( - (position) => - position.hyperdrive.address === hyperdrive.address && - position.hyperdrive.chainId === hyperdrive.chainId, - ) ?? { - lpShares: 0n, - withdrawalShares: 0n, - }; - - // Check if this hyperdrive pool has open positions before rendering - if ( - openLpPosition.lpShares === 0n && - openLpPosition.withdrawalShares === 0n - ) { - return null; - } - - return ( -
-
-
- -

- {/* - This regex removes the term from the hyperdrive name since it's already shown in the table. - It matches: - - \d{1,3}: 1 to 3 digits - - d: Followed by the letter 'd' - */} - {hyperdrive.name.replace(/\d{1,3}d/, "")} -

-
- -
- -
- ); - })} -
- ); -} - export function OpenLpTableDesktop({ hyperdrive, openLpPosition, @@ -159,7 +35,7 @@ export function OpenLpTableDesktop({ const columns = useMemo( () => getColumns({ hyperdrive, appConfig }), - [hyperdrive, appConfig], + [hyperdrive], ); const data = useMemo(() => [openLpPosition], [openLpPosition]); const tableInstance = useReactTable({ diff --git a/apps/hyperdrive-trading/src/ui/portfolio/shorts/OpenShortsTable/OpenShortsTableDesktop.tsx b/apps/hyperdrive-trading/src/ui/portfolio/shorts/OpenShortsTable/OpenShortsTableDesktop.tsx index f1b42c4fb..a3f957edf 100644 --- a/apps/hyperdrive-trading/src/ui/portfolio/shorts/OpenShortsTable/OpenShortsTableDesktop.tsx +++ b/apps/hyperdrive-trading/src/ui/portfolio/shorts/OpenShortsTable/OpenShortsTableDesktop.tsx @@ -2,12 +2,10 @@ import { AppConfig, appConfig, getBaseToken, - getToken, HyperdriveConfig, } from "@delvtech/hyperdrive-appconfig"; import { OpenShort } from "@delvtech/hyperdrive-js"; import { ChevronDownIcon, ChevronUpIcon } from "@heroicons/react/24/outline"; -import { Link } from "@tanstack/react-router"; import { createColumnHelper, flexRender, @@ -18,7 +16,6 @@ import { } from "@tanstack/react-table"; import classNames from "classnames"; import { ReactElement } from "react"; -import LoadingState from "src/ui/base/components/LoadingState"; import { NonIdealState } from "src/ui/base/components/NonIdealState"; import { Pagination } from "src/ui/base/components/Pagination"; import { formatBalance } from "src/ui/base/formatting/formatBalance"; @@ -29,127 +26,8 @@ import { CloseShortModalButton } from "src/ui/hyperdrive/shorts/CloseShortModalB import { CurrentShortsValueCell } from "src/ui/portfolio/shorts/OpenShortsTable/CurrentShortsValueCell"; import { ManageShortButton } from "src/ui/portfolio/shorts/OpenShortsTable/ManageShortButton"; import { ShortRateAndSizeCell } from "src/ui/portfolio/shorts/OpenShortsTable/ShortRateAndSizeCell"; -import { TotalOpenShortValue } from "src/ui/portfolio/shorts/OpenShortsTable/TotalOpenShortsValue"; -import { usePortfolioShortsData } from "src/ui/portfolio/shorts/usePortfolioShortsData"; import { useAccount } from "wagmi"; -export function OpenShortsContainer(): ReactElement { - const { openShortPositions, openShortPositionsStatus } = - usePortfolioShortsData(); - const { address: account } = useAccount(); - if (!account) { - return ( -
- } - /> -
- ); - } - - if (openShortPositionsStatus === "loading") { - return ( -
- -
- ); - } - - if ( - openShortPositions?.every((position) => position.openShorts.length === 0) - ) { - return ( -
- - Visit the{" "} - - documentation - {" "} - or explore pools to open your first Short position. -

- } - action={ - - View Pools - - } - /> -
- ); - } - - return ( -
- {appConfig.hyperdrives.map((hyperdrive) => { - const baseToken = getBaseToken({ - hyperdriveChainId: hyperdrive.chainId, - hyperdriveAddress: hyperdrive.address, - appConfig, - }); - const sharesToken = getToken({ - chainId: hyperdrive.chainId, - tokenAddress: hyperdrive.poolConfig.vaultSharesToken, - appConfig, - }); - const openShorts = openShortPositions?.find( - (position) => - position.hyperdrive.address === hyperdrive.address && - position.hyperdrive.chainId === hyperdrive.chainId, - )?.openShorts; - // Ensure this hyperdrive pool has open positions before rendering. - if (openShortPositionsStatus === "success" && !openShorts?.length) { - return null; - } - return ( -
-
-
-
- {hyperdrive.depositOptions.isBaseTokenDepositEnabled ? ( -
- -
- ) : null} - {sharesToken && - hyperdrive.depositOptions.isShareTokenDepositsEnabled ? ( -
- -
- ) : null} -
-

{hyperdrive.name}

-
- -
- -
- ); - })} -
- ); -} - export function OpenShortsTableDesktop({ hyperdrive, openShorts, diff --git a/apps/hyperdrive-trading/src/ui/portfolio/shorts/ShortsContainer.tsx b/apps/hyperdrive-trading/src/ui/portfolio/shorts/ShortsContainer.tsx new file mode 100644 index 000000000..fc1ede8ac --- /dev/null +++ b/apps/hyperdrive-trading/src/ui/portfolio/shorts/ShortsContainer.tsx @@ -0,0 +1,117 @@ +import { appConfig, HyperdriveConfig } from "@delvtech/hyperdrive-appconfig"; +import { Link } from "@tanstack/react-router"; +import { ReactElement } from "react"; +import { ExternalLink } from "src/ui/analytics/ExternalLink"; +import LoadingState from "src/ui/base/components/LoadingState"; +import { NonIdealState } from "src/ui/base/components/NonIdealState"; +import { ConnectWalletButton } from "src/ui/compliance/ConnectWallet"; +import { PositionContainer } from "src/ui/portfolio/PositionContainer"; +import { PositionTableHeading } from "src/ui/portfolio/PositionTableHeading"; +import { OpenShortsTableDesktop } from "src/ui/portfolio/shorts/OpenShortsTable/OpenShortsTableDesktop"; +import { TotalOpenShortValue } from "src/ui/portfolio/shorts/OpenShortsTable/TotalOpenShortsValue"; +import { + OpenShortPositionsData, + usePortfolioShortsData, +} from "src/ui/portfolio/shorts/usePortfolioShortsData"; +import { useAccount } from "wagmi"; + +export function OpenShortsContainer(): ReactElement { + const { openShortPositions, openShortPositionsStatus } = + usePortfolioShortsData(); + const { address: account } = useAccount(); + if (!account) { + return ( + + } + /> + + ); + } + + if (openShortPositionsStatus === "loading") { + return ( + + + + ); + } + + if ( + openShortPositions?.every((position) => position.openShorts.length === 0) + ) { + return ( + + + Visit the{" "} + + documentation + {" "} + or explore pools to open your first Short position. +

+ } + action={ + + View Pools + + } + /> +
+ ); + } + + return ( + + {openShortPositions && + appConfig.hyperdrives + .filter((hyperdrive) => { + const openShorts = findOpenShorts( + openShortPositions, + hyperdrive, + )?.openShorts; + // Ensure this hyperdrive pool has open positions before rendering. + return openShortPositionsStatus === "success" && openShorts?.length; + }) + .map((hyperdrive) => { + const openShorts = findOpenShorts( + openShortPositions, + hyperdrive, + )?.openShorts; + + return ( +
+ } + /> + +
+ ); + })} +
+ ); +} + +function findOpenShorts( + openShortPositions: OpenShortPositionsData, + hyperdrive: HyperdriveConfig, +) { + return openShortPositions.find( + (position) => + position.hyperdrive.address === hyperdrive.address && + position.hyperdrive.chainId === hyperdrive.chainId, + ); +} diff --git a/apps/hyperdrive-trading/src/ui/portfolio/shorts/usePortfolioShortsData.ts b/apps/hyperdrive-trading/src/ui/portfolio/shorts/usePortfolioShortsData.ts index 3557e809b..6ec1845ef 100644 --- a/apps/hyperdrive-trading/src/ui/portfolio/shorts/usePortfolioShortsData.ts +++ b/apps/hyperdrive-trading/src/ui/portfolio/shorts/usePortfolioShortsData.ts @@ -6,7 +6,7 @@ import { getDrift } from "src/drift/getDrift"; import { useAppConfigForConnectedChain } from "src/ui/appconfig/useAppConfigForConnectedChain"; import { useAccount } from "wagmi"; -type OpenShortPositionsData = { +export type OpenShortPositionsData = { hyperdrive: HyperdriveConfig; openShorts: OpenShort[]; }[];