@@ -55,6 +55,19 @@ function OrgPage() {
5555 chainId,
5656 } ) ;
5757
58+ // Prepare poolId for the query - extract it before early returns to prevent hook order issues
59+ const poolId = org ?. lps && org . lps . length > 0 && org . lps [ 0 ] ?. poolId ? org . lps [ 0 ] . poolId : undefined ;
60+
61+ // Check if any swaps have occurred by fetching price points
62+ // IMPORTANT: This hook must be called before any early returns to maintain consistent hook order
63+ const { data : pricePoints } = useQuery ( {
64+ queryKey : [ "poolPricePoints" , poolId ] ,
65+ queryFn : ( ) => fetchPoolPricePoints ( poolId ! , undefined , undefined , 1 ) ,
66+ enabled : ! ! poolId ,
67+ staleTime : 60_000 ,
68+ retry : false ,
69+ } ) ;
70+
5871 const chainName = chainId === 1 ? "Mainnet" : chainId === 11155111 ? "Sepolia" : `Chain ${ chainId } ` ;
5972 const explorerUrl = chainId === 11155111 ? "https://sepolia.etherscan.io" : "https://etherscan.io" ;
6073
@@ -87,24 +100,12 @@ function OrgPage() {
87100 console . log ( "LPs:" , org . lps ) ;
88101 console . log ( "Pool ID:" , org . lps && org . lps . length > 0 ? org . lps [ 0 ] . poolId : "No LP" ) ;
89102
90- const hasPool = org . lps && org . lps . length > 0 && org . lps [ 0 ] ?. poolId ;
91- const poolId = hasPool ? org . lps [ 0 ] . poolId : undefined ;
92-
93103 // Get token address from the first sale (this is the DAO's Share or Loot token being sold)
94104 const tokenAddress = org . sales && org . sales . length > 0 ? org . sales [ 0 ] . forTkn : undefined ;
95105
96106 // Create swap link with pre-filled token
97107 const swapLink = tokenAddress ? `/swap?buyToken=${ tokenAddress } ` : undefined ;
98108
99- // Check if any swaps have occurred by fetching price points
100- const { data : pricePoints } = useQuery ( {
101- queryKey : [ "poolPricePoints" , poolId ] ,
102- queryFn : ( ) => fetchPoolPricePoints ( poolId ! , undefined , undefined , 1 ) ,
103- enabled : ! ! poolId ,
104- staleTime : 60_000 ,
105- retry : false ,
106- } ) ;
107-
108109 const hasSwaps = pricePoints && pricePoints . length > 0 ;
109110
110111 return (
@@ -122,6 +123,7 @@ function OrgPage() {
122123 explorerUrl = { explorerUrl }
123124 shortenAddress = { shortenAddress }
124125 tokenAddress = { tokenAddress }
126+ chainId = { chainId }
125127 />
126128
127129 { /* Stats Overview */ }
0 commit comments