@@ -24,20 +24,29 @@ import { NonIdealState } from "src/ui/base/components/NonIdealState";
2424import { Pagination } from "src/ui/base/components/Pagination" ;
2525import { formatBalance } from "src/ui/base/formatting/formatBalance" ;
2626import { MaturesOnCellTwo } from "src/ui/hyperdrive/MaturesOnCell/MaturesOnCell" ;
27- import { useMarketState } from "src/ui/hyperdrive/hooks/useMarketState" ;
2827import { StatusCell } from "src/ui/hyperdrive/longs/OpenLongsTable/StatusCell" ;
2928import { CloseShortModalButton } from "src/ui/hyperdrive/shorts/CloseShortModalButton/CloseShortModalButton" ;
3029import { CurrentShortsValueCell } from "src/ui/hyperdrive/shorts/OpenShortsTable/CurrentShortsValueCell" ;
3130import { ShortRateAndSizeCell } from "src/ui/hyperdrive/shorts/OpenShortsTable/ShortRateAndSizeCell" ;
3231import { TotalOpenShortValue } from "src/ui/hyperdrive/shorts/OpenShortsTable/TotalOpenShortsValue" ;
33- import { useOpenShorts } from "src/ui/hyperdrive/shorts/hooks/useOpenShorts" ;
3432import { usePortfolioShortsData } from "src/ui/portfolio/usePortfolioShortsData" ;
3533import { useAccount } from "wagmi" ;
3634
3735export function OpenShortsContainer ( ) : ReactElement {
3836 const { openShortPositions, openShortPositionsStatus } =
3937 usePortfolioShortsData ( ) ;
4038 const appConfig = useAppConfig ( ) ;
39+
40+ if ( openShortPositionsStatus === "loading" ) {
41+ return (
42+ < div className = "mt-10 flex w-[1036px] flex-col gap-10" >
43+ < LoadingState
44+ heading = "Loading your Shorts..."
45+ text = "Searching for Shorts events, calculating current value and PnL..."
46+ />
47+ </ div >
48+ ) ;
49+ }
4150 return (
4251 < div className = "mt-10 flex w-[1036px] flex-col gap-10" >
4352 { appConfig . hyperdrives . map ( ( hyperdrive ) => {
@@ -51,11 +60,13 @@ export function OpenShortsContainer(): ReactElement {
5160 tokens : appConfig . tokens ,
5261 tokenAddress : hyperdrive . poolConfig . vaultSharesToken ,
5362 } ) ;
63+ const openShorts = openShortPositions ?. find (
64+ ( position ) =>
65+ position . hyperdrive . address === hyperdrive . address &&
66+ position . hyperdrive . chainId === hyperdrive . chainId ,
67+ ) ?. openShorts ;
5468 // Ensure this hyperdrive pool has open positions before rendering.
55- if (
56- openShortPositionsStatus === "success" &&
57- ! openShortPositions ?. [ hyperdrive . address ] ?. length
58- ) {
69+ if ( openShortPositionsStatus === "success" && ! openShorts ?. length ) {
5970 return null ;
6071 }
6172 return (
@@ -87,7 +98,7 @@ export function OpenShortsContainer(): ReactElement {
8798 </ div >
8899 < OpenShortsTableDesktopTwo
89100 hyperdrive = { hyperdrive }
90- openShortPositionsStatus = { openShortPositionsStatus }
101+ openShorts = { openShorts }
91102 />
92103 </ div >
93104 ) ;
@@ -98,22 +109,14 @@ export function OpenShortsContainer(): ReactElement {
98109
99110export function OpenShortsTableDesktopTwo ( {
100111 hyperdrive,
101- openShortPositionsStatus ,
112+ openShorts ,
102113} : {
103114 hyperdrive : HyperdriveConfig ;
104- openShortPositionsStatus ?: "loading" | "success" | "error" ;
115+ openShorts : OpenShort [ ] | undefined ;
105116} ) : ReactElement {
106117 const { address : account } = useAccount ( ) ;
107118 const appConfig = useAppConfig ( ) ;
108- const { marketState } = useMarketState ( {
109- hyperdriveAddress : hyperdrive . address ,
110- chainId : hyperdrive . chainId ,
111- } ) ;
112- const { openShorts, openShortsStatus } = useOpenShorts ( {
113- account,
114- chainId : hyperdrive . chainId ,
115- hyperdriveAddress : hyperdrive . address ,
116- } ) ;
119+
117120 const tableInstance = useReactTable ( {
118121 columns : getColumns ( { hyperdrive, appConfig } ) ,
119122 data : openShorts || [ ] ,
@@ -141,17 +144,6 @@ export function OpenShortsTableDesktopTwo({
141144 </ div >
142145 ) ;
143146 }
144- if (
145- openShortsStatus === "loading" ||
146- openShortPositionsStatus === "loading"
147- ) {
148- return (
149- < LoadingState
150- heading = "Loading your Shorts..."
151- text = "Searching for Shorts events, calculating current value and PnL..."
152- />
153- ) ;
154- }
155147
156148 return (
157149 < div className = "daisy-card overflow-x-clip rounded-box bg-gray-750 pt-3" >
0 commit comments