diff --git a/web/lib/firebase/groups.ts b/web/lib/firebase/groups.ts index 36bfe7cc..0366fe0b 100644 --- a/web/lib/firebase/groups.ts +++ b/web/lib/firebase/groups.ts @@ -86,9 +86,10 @@ export async function listGroupContracts(groupId: string) { contractId: string createdTime: number }>(groupContracts(groupId)) - return Promise.all( + const contracts = await Promise.all( contractDocs.map((doc) => getContractFromId(doc.contractId)) ) + return filterDefined(contracts) } export function listenForOpenGroups(setGroups: (groups: Group[]) => void) { diff --git a/web/pages/api/v0/group/by-id/[id]/markets.ts b/web/pages/api/v0/group/by-id/[id]/markets.ts index f7538277..e9610a20 100644 --- a/web/pages/api/v0/group/by-id/[id]/markets.ts +++ b/web/pages/api/v0/group/by-id/[id]/markets.ts @@ -1,6 +1,7 @@ import { NextApiRequest, NextApiResponse } from 'next' import { applyCorsHeaders, CORS_UNRESTRICTED } from 'web/lib/api/cors' import { listGroupContracts } from 'web/lib/firebase/groups' +import { toLiteMarket } from 'web/pages/api/v0/_types' export default async function handler( req: NextApiRequest, @@ -8,7 +9,9 @@ export default async function handler( ) { await applyCorsHeaders(req, res, CORS_UNRESTRICTED) const { id } = req.query - const contracts = await listGroupContracts(id as string) + const contracts = (await listGroupContracts(id as string)).map((contract) => + toLiteMarket(contract) + ) if (!contracts) { res.status(404).json({ error: 'Group not found' }) return