1+ import { TokenValue } from "@/classes/TokenValue" ;
2+ import { PODS } from "@/constants/internalTokens" ;
13import { subgraphs } from "@/constants/subgraph" ;
4+ import { PINTO } from "@/constants/tokens" ;
25import { AllPodListingsDocument } from "@/generated/gql/pintostalk/graphql" ;
36import { useQuery } from "@tanstack/react-query" ;
47import request from "graphql-request" ;
8+ import { useMemo } from "react" ;
59import { useChainId } from "wagmi" ;
610import { useHarvestableIndex } from "../useFieldData" ;
711import { useQueryKeys } from "../useQueryKeys" ;
@@ -22,8 +26,32 @@ export default function usePodListings() {
2226 enabled : harvestableIndex . gt ( 0 ) ,
2327 } ) ;
2428
29+ // Filter out listings that cannot be purchased (pricePerPod * remainingAmount < minFillAmount)
30+ const filteredData = useMemo ( ( ) => {
31+ if ( ! podListings . data ?. podListings ) {
32+ return podListings . data ;
33+ }
34+
35+ const filtered = podListings . data . podListings . filter ( ( listing ) => {
36+ const pricePerPod = TokenValue . fromBlockchain ( listing . pricePerPod , PINTO . decimals ) ;
37+ const remainingAmount = TokenValue . fromBlockchain ( listing . remainingAmount , PODS . decimals ) ;
38+ const minFillAmount = TokenValue . fromBlockchain ( listing . minFillAmount , PINTO . decimals ) ;
39+
40+ // Calculate total value: pricePerPod * remainingAmount
41+ const totalValue = pricePerPod . mul ( remainingAmount ) ;
42+
43+ // Keep only listings where totalValue >= minFillAmount
44+ return totalValue . gte ( minFillAmount ) ;
45+ } ) ;
46+
47+ return {
48+ ...podListings . data ,
49+ podListings : filtered ,
50+ } ;
51+ } , [ podListings . data ] ) ;
52+
2553 return {
26- data : podListings . data ,
54+ data : filteredData ,
2755 isLoaded : ! ! podListings . data ,
2856 isFetching : podListings . isFetching ,
2957 queryKey : queryKey ,
0 commit comments