diff --git a/web/hooks/use-contracts.ts b/web/hooks/use-contracts.ts index fb71ca60..053e2386 100644 --- a/web/hooks/use-contracts.ts +++ b/web/hooks/use-contracts.ts @@ -9,12 +9,10 @@ import { getUserBetContractsQuery, listAllContracts, trendingContractsQuery, - getContractsQuery, } from 'web/lib/firebase/contracts' import { QueryClient, useQuery, useQueryClient } from 'react-query' import { MINUTE_MS } from 'common/util/time' import { query, limit } from 'firebase/firestore' -import { Sort } from 'web/components/contract-search' import { dailyScoreIndex } from 'web/lib/service/algolia' import { CPMMBinaryContract } from 'common/contract' import { zipObject } from 'lodash' @@ -66,19 +64,6 @@ export const useTrendingContracts = (maxContracts: number) => { return result.data } -export const useContractsQuery = ( - sort: Sort, - maxContracts: number, - filters: { groupSlug?: string } = {}, - visibility?: 'public' -) => { - const result = useFirestoreQueryData( - ['contracts-query', sort, maxContracts, filters], - getContractsQuery(sort, maxContracts, filters, visibility) - ) - return result.data -} - export const useInactiveContracts = () => { const [contracts, setContracts] = useState() diff --git a/web/lib/firebase/contracts.ts b/web/lib/firebase/contracts.ts index 927f7187..d7f6cd88 100644 --- a/web/lib/firebase/contracts.ts +++ b/web/lib/firebase/contracts.ts @@ -24,7 +24,6 @@ import { Bet } from 'common/bet' import { Comment } from 'common/comment' import { ENV_CONFIG } from 'common/envs/constants' import { getBinaryProb } from 'common/contract-details' -import { Sort } from 'web/components/contract-search' export const contracts = coll('contracts') @@ -321,51 +320,6 @@ export const getTopGroupContracts = async ( return await getValues(creatorContractsQuery) } -const sortToField = { - newest: 'createdTime', - score: 'popularityScore', - 'most-traded': 'volume', - '24-hour-vol': 'volume24Hours', - 'prob-change-day': 'probChanges.day', - 'last-updated': 'lastUpdated', - liquidity: 'totalLiquidity', - 'close-date': 'closeTime', - 'resolve-date': 'resolutionTime', - 'prob-descending': 'prob', - 'prob-ascending': 'prob', -} as const - -const sortToDirection = { - newest: 'desc', - score: 'desc', - 'most-traded': 'desc', - '24-hour-vol': 'desc', - 'prob-change-day': 'desc', - 'last-updated': 'desc', - liquidity: 'desc', - 'close-date': 'asc', - 'resolve-date': 'desc', - 'prob-ascending': 'asc', - 'prob-descending': 'desc', -} as const - -export const getContractsQuery = ( - sort: Sort, - maxItems: number, - filters: { groupSlug?: string } = {}, - visibility?: 'public' -) => { - const { groupSlug } = filters - return query( - contracts, - where('isResolved', '==', false), - ...(visibility ? [where('visibility', '==', visibility)] : []), - ...(groupSlug ? [where('groupSlugs', 'array-contains', groupSlug)] : []), - orderBy(sortToField[sort], sortToDirection[sort]), - limit(maxItems) - ) -} - export const getRecommendedContracts = async ( contract: Contract, excludeBettorId: string,