2021-12-12 22:14:52 +00:00
|
|
|
import { useEffect, useState } from 'react'
|
2022-02-10 20:36:15 +00:00
|
|
|
import { Contract } from '../../common/contract'
|
|
|
|
import { Bet, listenForBets, withoutAnteBets } from '../lib/firebase/bets'
|
2021-12-12 22:14:52 +00:00
|
|
|
|
|
|
|
export const useBets = (contractId: string) => {
|
2022-01-15 00:16:25 +00:00
|
|
|
const [bets, setBets] = useState<Bet[] | undefined>()
|
2021-12-12 22:14:52 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (contractId) return listenForBets(contractId, setBets)
|
|
|
|
}, [contractId])
|
|
|
|
|
|
|
|
return bets
|
|
|
|
}
|
2022-02-10 20:36:15 +00:00
|
|
|
|
2022-02-17 23:39:18 +00:00
|
|
|
export const useBetsWithoutAntes = (contract: Contract, initialBets: Bet[]) => {
|
|
|
|
const [bets, setBets] = useState<Bet[]>(
|
|
|
|
withoutAnteBets(contract, initialBets).sort(
|
|
|
|
(bet1, bet2) => bet1.createdTime - bet2.createdTime
|
|
|
|
)
|
2022-02-10 20:36:15 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
return listenForBets(contract.id, (bets) => {
|
|
|
|
setBets(withoutAnteBets(contract, bets))
|
|
|
|
})
|
|
|
|
}, [contract])
|
|
|
|
|
|
|
|
return bets
|
|
|
|
}
|