Filter undefined contracts

This commit is contained in:
James Grugett 2022-02-10 17:06:27 -06:00
parent d02611a37a
commit dc0c9cf1d4

View File

@ -5,6 +5,7 @@ import { Contract } from '../lib/firebase/contracts'
import { Comment } from '../lib/firebase/comments' import { Comment } from '../lib/firebase/comments'
import { Col } from '../components/layout/col' import { Col } from '../components/layout/col'
import { Bet } from '../../common/bet' import { Bet } from '../../common/bet'
import { filterDefined } from '../../common/util/array'
const MAX_ACTIVE_CONTRACTS = 75 const MAX_ACTIVE_CONTRACTS = 75
const MAX_HOT_MARKETS = 10 const MAX_HOT_MARKETS = 10
@ -64,12 +65,13 @@ export function findActiveContracts(
const contractTotalBets = _.mapValues(contractBets, (bets) => const contractTotalBets = _.mapValues(contractBets, (bets) =>
_.sumBy(bets, (bet) => bet.amount) _.sumBy(bets, (bet) => bet.amount)
) )
const topTradedContracts = _.sortBy( const sortedPairs = _.sortBy(
_.toPairs(contractTotalBets), _.toPairs(contractTotalBets),
([_, total]) => -1 * total ([_, total]) => -1 * total
) )
.map(([id]) => contractsById.get(id) as Contract) const topTradedContracts = filterDefined(
.slice(0, MAX_HOT_MARKETS) sortedPairs.map(([id]) => contractsById.get(id))
).slice(0, MAX_HOT_MARKETS)
for (const contract of topTradedContracts) { for (const contract of topTradedContracts) {
const bet = recentBets.find((bet) => bet.contractId === contract.id) const bet = recentBets.find((bet) => bet.contractId === contract.id)