30 lines
794 B
TypeScript
30 lines
794 B
TypeScript
import { useEffect, useState } from 'react'
|
|
import { Contract } from '../../common/contract'
|
|
import { Bet, listenForBets, 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).sort(
|
|
(bet1, bet2) => bet1.createdTime - bet2.createdTime
|
|
)
|
|
)
|
|
|
|
useEffect(() => {
|
|
return listenForBets(contract.id, (bets) => {
|
|
setBets(withoutAnteBets(contract, bets))
|
|
})
|
|
}, [contract])
|
|
|
|
return bets
|
|
}
|