Also get new contracts for feed with 0 volume.
This commit is contained in:
parent
01e43abd17
commit
e1b5b595e7
|
@ -36,7 +36,12 @@ export const useAlgoFeed = (
|
|||
const [algoFeed, setAlgoFeed] = useState<Contract[]>([])
|
||||
|
||||
useEffect(() => {
|
||||
if (initialContracts && initialBets && initialComments) {
|
||||
if (
|
||||
initialContracts &&
|
||||
initialBets &&
|
||||
initialComments &&
|
||||
yourBetContractIds
|
||||
) {
|
||||
const eligibleContracts = initialContracts.filter(
|
||||
(c) => !c.isResolved && (c.closeTime ?? Infinity) > Date.now()
|
||||
)
|
||||
|
|
|
@ -6,6 +6,7 @@ import {
|
|||
listenForContracts,
|
||||
listenForHotContracts,
|
||||
listenForInactiveContracts,
|
||||
listenForNewContracts,
|
||||
} from '../lib/firebase/contracts'
|
||||
import { listenForTaggedContracts } from '../lib/firebase/folds'
|
||||
|
||||
|
@ -20,13 +21,22 @@ export const useContracts = () => {
|
|||
}
|
||||
|
||||
export const useActiveContracts = () => {
|
||||
const [contracts, setContracts] = useState<Contract[] | undefined>()
|
||||
const [activeContracts, setActiveContracts] = useState<
|
||||
Contract[] | undefined
|
||||
>()
|
||||
const [newContracts, setNewContracts] = useState<Contract[] | undefined>()
|
||||
|
||||
useEffect(() => {
|
||||
return listenForActiveContracts(setContracts)
|
||||
return listenForActiveContracts(setActiveContracts)
|
||||
}, [])
|
||||
|
||||
return contracts
|
||||
useEffect(() => {
|
||||
return listenForNewContracts(setNewContracts)
|
||||
}, [])
|
||||
|
||||
if (!activeContracts || !newContracts) return undefined
|
||||
|
||||
return [...activeContracts, ...newContracts]
|
||||
}
|
||||
|
||||
export const useInactiveContracts = () => {
|
||||
|
|
|
@ -54,13 +54,15 @@ export const useUserBetContracts = (userId: string | undefined) => {
|
|||
}
|
||||
|
||||
export const useGetUserBetContractIds = (userId: string | undefined) => {
|
||||
const [contractIds, setContractIds] = useState<string[]>([])
|
||||
const [contractIds, setContractIds] = useState<string[] | undefined>()
|
||||
|
||||
useEffect(() => {
|
||||
const key = `user-bet-contractIds-${userId}`
|
||||
const userBetContractJson = localStorage.getItem(key)
|
||||
if (userBetContractJson) {
|
||||
setContractIds(JSON.parse(userBetContractJson))
|
||||
if (userId) {
|
||||
const key = `user-bet-contractIds-${userId}`
|
||||
const userBetContractJson = localStorage.getItem(key)
|
||||
if (userBetContractJson) {
|
||||
setContractIds(JSON.parse(userBetContractJson))
|
||||
}
|
||||
}
|
||||
}, [userId])
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ import { getDpmProbability } from '../../../common/calculate-dpm'
|
|||
import { createRNG, shuffle } from '../../../common/util/random'
|
||||
import { getCpmmProbability } from '../../../common/calculate-cpmm'
|
||||
import { formatMoney, formatPercent } from '../../../common/util/format'
|
||||
import { DAY_MS } from '../../../common/util/time'
|
||||
export type { Contract }
|
||||
|
||||
export function contractPath(contract: Contract) {
|
||||
|
@ -162,6 +163,19 @@ export function listenForInactiveContracts(
|
|||
return listenForValues<Contract>(inactiveContractsQuery, setContracts)
|
||||
}
|
||||
|
||||
const newContractsQuery = query(
|
||||
contractCollection,
|
||||
where('isResolved', '==', false),
|
||||
where('volume7Days', '==', 0),
|
||||
where('createdTime', '>', Date.now() - 7 * DAY_MS)
|
||||
)
|
||||
|
||||
export function listenForNewContracts(
|
||||
setContracts: (contracts: Contract[]) => void
|
||||
) {
|
||||
return listenForValues<Contract>(newContractsQuery, setContracts)
|
||||
}
|
||||
|
||||
export function listenForContract(
|
||||
contractId: string,
|
||||
setContract: (contract: Contract | null) => void
|
||||
|
|
Loading…
Reference in New Issue
Block a user