ec49a73c74
* Implement algo feed * Remove 'See more...' from feed items * Fix problem with useUpdatedContracts. * Tweak some params
39 lines
940 B
TypeScript
39 lines
940 B
TypeScript
import { useEffect, useState } from 'react'
|
|
import { Contract } from '../../common/contract'
|
|
import {
|
|
Bet,
|
|
listenForBets,
|
|
listenForRecentBets,
|
|
withoutAnteBets,
|
|
} from '../lib/firebase/bets'
|
|
|
|
export const useBets = (contractId: string) => {
|
|
const [bets, setBets] = useState<Bet[] | undefined>()
|
|
|
|
useEffect(() => {
|
|
if (contractId) return listenForBets(contractId, setBets)
|
|
}, [contractId])
|
|
|
|
return bets
|
|
}
|
|
|
|
export const useBetsWithoutAntes = (contract: Contract, initialBets: Bet[]) => {
|
|
const [bets, setBets] = useState<Bet[]>(
|
|
withoutAnteBets(contract, initialBets)
|
|
)
|
|
|
|
useEffect(() => {
|
|
return listenForBets(contract.id, (bets) => {
|
|
setBets(withoutAnteBets(contract, bets))
|
|
})
|
|
}, [contract])
|
|
|
|
return bets
|
|
}
|
|
|
|
export const useRecentBets = () => {
|
|
const [recentBets, setRecentBets] = useState<Bet[] | undefined>()
|
|
useEffect(() => listenForRecentBets(setRecentBets), [])
|
|
return recentBets
|
|
}
|