From dc0c9cf1d441984b0cca64729e85fd927a935cbf Mon Sep 17 00:00:00 2001 From: James Grugett Date: Thu, 10 Feb 2022 17:06:27 -0600 Subject: [PATCH] Filter undefined contracts --- web/pages/activity.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/web/pages/activity.tsx b/web/pages/activity.tsx index be5a9809..c118b9ee 100644 --- a/web/pages/activity.tsx +++ b/web/pages/activity.tsx @@ -5,6 +5,7 @@ import { Contract } from '../lib/firebase/contracts' import { Comment } from '../lib/firebase/comments' import { Col } from '../components/layout/col' import { Bet } from '../../common/bet' +import { filterDefined } from '../../common/util/array' const MAX_ACTIVE_CONTRACTS = 75 const MAX_HOT_MARKETS = 10 @@ -64,12 +65,13 @@ export function findActiveContracts( const contractTotalBets = _.mapValues(contractBets, (bets) => _.sumBy(bets, (bet) => bet.amount) ) - const topTradedContracts = _.sortBy( + const sortedPairs = _.sortBy( _.toPairs(contractTotalBets), ([_, total]) => -1 * total ) - .map(([id]) => contractsById.get(id) as Contract) - .slice(0, MAX_HOT_MARKETS) + const topTradedContracts = filterDefined( + sortedPairs.map(([id]) => contractsById.get(id)) + ).slice(0, MAX_HOT_MARKETS) for (const contract of topTradedContracts) { const bet = recentBets.find((bet) => bet.contractId === contract.id)