2022-01-05 06:32:52 +00:00
|
|
|
import _ from 'lodash'
|
2021-12-17 04:44:48 +00:00
|
|
|
import { useEffect, useState } from 'react'
|
2022-01-05 06:32:52 +00:00
|
|
|
import { Bet, listenForRecentBets } from '../lib/firebase/bets'
|
|
|
|
import {
|
|
|
|
computeHotContracts,
|
|
|
|
Contract,
|
|
|
|
listenForContracts,
|
|
|
|
} from '../lib/firebase/contracts'
|
2021-12-17 04:44:48 +00:00
|
|
|
|
|
|
|
export const useContracts = () => {
|
|
|
|
const [contracts, setContracts] = useState<Contract[] | 'loading'>('loading')
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
return listenForContracts(setContracts)
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
return contracts
|
|
|
|
}
|
2022-01-05 06:32:52 +00:00
|
|
|
|
|
|
|
export const useHotContracts = () => {
|
|
|
|
const [recentBets, setRecentBets] = useState<Bet[] | 'loading'>('loading')
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const oneDay = 1000 * 60 * 60 * 24
|
|
|
|
return listenForRecentBets(oneDay, setRecentBets)
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
if (recentBets === 'loading') return 'loading'
|
|
|
|
|
|
|
|
return computeHotContracts(recentBets)
|
|
|
|
}
|