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[]>([])
|
const [algoFeed, setAlgoFeed] = useState<Contract[]>([])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (initialContracts && initialBets && initialComments) {
|
if (
|
||||||
|
initialContracts &&
|
||||||
|
initialBets &&
|
||||||
|
initialComments &&
|
||||||
|
yourBetContractIds
|
||||||
|
) {
|
||||||
const eligibleContracts = initialContracts.filter(
|
const eligibleContracts = initialContracts.filter(
|
||||||
(c) => !c.isResolved && (c.closeTime ?? Infinity) > Date.now()
|
(c) => !c.isResolved && (c.closeTime ?? Infinity) > Date.now()
|
||||||
)
|
)
|
||||||
|
|
|
@ -6,6 +6,7 @@ import {
|
||||||
listenForContracts,
|
listenForContracts,
|
||||||
listenForHotContracts,
|
listenForHotContracts,
|
||||||
listenForInactiveContracts,
|
listenForInactiveContracts,
|
||||||
|
listenForNewContracts,
|
||||||
} from '../lib/firebase/contracts'
|
} from '../lib/firebase/contracts'
|
||||||
import { listenForTaggedContracts } from '../lib/firebase/folds'
|
import { listenForTaggedContracts } from '../lib/firebase/folds'
|
||||||
|
|
||||||
|
@ -20,13 +21,22 @@ export const useContracts = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useActiveContracts = () => {
|
export const useActiveContracts = () => {
|
||||||
const [contracts, setContracts] = useState<Contract[] | undefined>()
|
const [activeContracts, setActiveContracts] = useState<
|
||||||
|
Contract[] | undefined
|
||||||
|
>()
|
||||||
|
const [newContracts, setNewContracts] = useState<Contract[] | undefined>()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
return listenForActiveContracts(setContracts)
|
return listenForActiveContracts(setActiveContracts)
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
return contracts
|
useEffect(() => {
|
||||||
|
return listenForNewContracts(setNewContracts)
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
if (!activeContracts || !newContracts) return undefined
|
||||||
|
|
||||||
|
return [...activeContracts, ...newContracts]
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useInactiveContracts = () => {
|
export const useInactiveContracts = () => {
|
||||||
|
|
|
@ -54,14 +54,16 @@ export const useUserBetContracts = (userId: string | undefined) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useGetUserBetContractIds = (userId: string | undefined) => {
|
export const useGetUserBetContractIds = (userId: string | undefined) => {
|
||||||
const [contractIds, setContractIds] = useState<string[]>([])
|
const [contractIds, setContractIds] = useState<string[] | undefined>()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (userId) {
|
||||||
const key = `user-bet-contractIds-${userId}`
|
const key = `user-bet-contractIds-${userId}`
|
||||||
const userBetContractJson = localStorage.getItem(key)
|
const userBetContractJson = localStorage.getItem(key)
|
||||||
if (userBetContractJson) {
|
if (userBetContractJson) {
|
||||||
setContractIds(JSON.parse(userBetContractJson))
|
setContractIds(JSON.parse(userBetContractJson))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}, [userId])
|
}, [userId])
|
||||||
|
|
||||||
return contractIds
|
return contractIds
|
||||||
|
|
|
@ -22,6 +22,7 @@ import { getDpmProbability } from '../../../common/calculate-dpm'
|
||||||
import { createRNG, shuffle } from '../../../common/util/random'
|
import { createRNG, shuffle } from '../../../common/util/random'
|
||||||
import { getCpmmProbability } from '../../../common/calculate-cpmm'
|
import { getCpmmProbability } from '../../../common/calculate-cpmm'
|
||||||
import { formatMoney, formatPercent } from '../../../common/util/format'
|
import { formatMoney, formatPercent } from '../../../common/util/format'
|
||||||
|
import { DAY_MS } from '../../../common/util/time'
|
||||||
export type { Contract }
|
export type { Contract }
|
||||||
|
|
||||||
export function contractPath(contract: Contract) {
|
export function contractPath(contract: Contract) {
|
||||||
|
@ -162,6 +163,19 @@ export function listenForInactiveContracts(
|
||||||
return listenForValues<Contract>(inactiveContractsQuery, setContracts)
|
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(
|
export function listenForContract(
|
||||||
contractId: string,
|
contractId: string,
|
||||||
setContract: (contract: Contract | null) => void
|
setContract: (contract: Contract | null) => void
|
||||||
|
|
Loading…
Reference in New Issue
Block a user