diff --git a/web/components/contract-feed.tsx b/web/components/contract-feed.tsx index 1be52158..58dd5f01 100644 --- a/web/components/contract-feed.tsx +++ b/web/components/contract-feed.tsx @@ -747,7 +747,7 @@ export function ContractFeed(props: {
{items.map((activityItem, activityItemIdx) => ( -
+
{activityItemIdx !== items.length - 1 ? ( { let [contracts, folds] = await Promise.all([ - listAllContracts().catch((_) => []), + getActiveContracts().catch((_) => []), listAllFolds().catch(() => []), ]) @@ -28,7 +28,7 @@ export const getAllContractInfo = async () => { return { contracts, recentBets, recentComments, folds } } -export const useActiveContracts = ( +export const useFindActiveContracts = ( props: { contracts: Contract[] folds: Fold[] @@ -38,7 +38,7 @@ export const useActiveContracts = ( user: User | undefined | null ) => { const { recentBets, recentComments } = props - const contracts = useContracts() ?? props.contracts + const contracts = useActiveContracts() ?? props.contracts const followedFoldIds = useFollowedFolds(user) diff --git a/web/hooks/use-contracts.ts b/web/hooks/use-contracts.ts index 41137f33..60744c33 100644 --- a/web/hooks/use-contracts.ts +++ b/web/hooks/use-contracts.ts @@ -2,6 +2,7 @@ import _ from 'lodash' import { useEffect, useState } from 'react' import { Contract, + listenForActiveContracts, listenForContracts, listenForHotContracts, } from '../lib/firebase/contracts' @@ -17,6 +18,16 @@ export const useContracts = () => { return contracts } +export const useActiveContracts = () => { + const [contracts, setContracts] = useState() + + useEffect(() => { + return listenForActiveContracts(setContracts) + }, []) + + return contracts +} + export const useUpdatedContracts = (initialContracts: Contract[]) => { const [contracts, setContracts] = useState(initialContracts) diff --git a/web/lib/firebase/contracts.ts b/web/lib/firebase/contracts.ts index 88470a89..b22a547f 100644 --- a/web/lib/firebase/contracts.ts +++ b/web/lib/firebase/contracts.ts @@ -115,6 +115,23 @@ export function listenForContracts( return listenForValues(q, setContracts) } +const activeContracts = query( + contractCollection, + where('isResolved', '==', false), + where('visibility', '==', 'public'), + where('volume24Hours', '>', 0) +) + +export function getActiveContracts() { + return getValues(activeContracts) +} + +export function listenForActiveContracts( + setContracts: (contracts: Contract[]) => void +) { + return listenForValues(activeContracts, setContracts) +} + export function listenForContract( contractId: string, setContract: (contract: Contract | null) => void diff --git a/web/pages/home.tsx b/web/pages/home.tsx index ec21e62f..7bd305df 100644 --- a/web/pages/home.tsx +++ b/web/pages/home.tsx @@ -17,7 +17,7 @@ import { SparklesIcon } from '@heroicons/react/solid' import { FastFoldFollowing } from '../components/fast-fold-following' import { getAllContractInfo, - useActiveContracts, + useFindActiveContracts, } from '../hooks/use-active-contracts' import { useGetRecentBets } from '../hooks/use-bets' @@ -46,7 +46,7 @@ const Home = (props: { activeBets, activeComments, initialFollowedFoldSlugs, - } = useActiveContracts( + } = useFindActiveContracts( { contracts, folds, recentBets: recentBets ?? [], recentComments }, user )