diff --git a/web/pages/api/v0/_types.ts b/web/pages/api/v0/_types.ts index f63a0980..be1eaecd 100644 --- a/web/pages/api/v0/_types.ts +++ b/web/pages/api/v0/_types.ts @@ -3,16 +3,23 @@ import { getProbability } from '../../../../common/calculate' import { Comment } from '../../../../common/comment' import { Contract } from '../../../../common/contract' -export type LiteContract = { +export type LiteMarket = { + // Unique identifer for this market id: string + + // Attributes about the creator creatorUsername: string creatorName: string createdTime: number + creatorAvatarUrl?: string + + // Market attributes. All times are in milliseconds since epoch closeTime?: number question: string description: string tags: string[] url: string + pool: number probability: number volume7Days: number @@ -21,7 +28,7 @@ export type LiteContract = { resolution?: string } -export type FullContract = LiteContract & { +export type FullMarket = LiteMarket & { bets: Bet[] comments: Comment[] } @@ -30,11 +37,12 @@ export type ApiError = { error: string } -export function toLiteContract({ +export function toLiteMarket({ id, creatorUsername, creatorName, createdTime, + creatorAvatarUrl, closeTime, question, description, @@ -46,12 +54,13 @@ export function toLiteContract({ volume24Hours, isResolved, resolution, -}: Contract): LiteContract { +}: Contract): LiteMarket { return { id, creatorUsername, creatorName, createdTime, + creatorAvatarUrl, closeTime, question, description, diff --git a/web/pages/api/v0/market/[id].ts b/web/pages/api/v0/market/[id].ts index 48993866..7e1674ba 100644 --- a/web/pages/api/v0/market/[id].ts +++ b/web/pages/api/v0/market/[id].ts @@ -2,11 +2,11 @@ import { NextApiRequest, NextApiResponse } from 'next' import { listAllBets } from '../../../../lib/firebase/bets' import { listAllComments } from '../../../../lib/firebase/comments' import { getContractFromId } from '../../../../lib/firebase/contracts' -import { FullContract, ApiError, toLiteContract } from '../_types' +import { FullMarket, ApiError, toLiteMarket } from '../_types' export default async function handler( req: NextApiRequest, - res: NextApiResponse + res: NextApiResponse ) { const { id } = req.query const contractId = id as string @@ -25,7 +25,7 @@ export default async function handler( // Cache on Vercel edge servers for 2min res.setHeader('Cache-Control', 'max-age=0, s-maxage=120') return res.status(200).json({ - ...toLiteContract(contract), + ...toLiteMarket(contract), bets, comments, }) diff --git a/web/pages/api/v0/markets.ts b/web/pages/api/v0/markets.ts index 5106dde0..5bda56f6 100644 --- a/web/pages/api/v0/markets.ts +++ b/web/pages/api/v0/markets.ts @@ -1,7 +1,7 @@ // Next.js API route support: https://vercel.com/docs/concepts/functions/serverless-functions import type { NextApiRequest, NextApiResponse } from 'next' import { listAllContracts } from '../../../lib/firebase/contracts' -import { toLiteContract } from './_types' +import { toLiteMarket } from './_types' type Data = any[] @@ -12,5 +12,5 @@ export default async function handler( const contracts = await listAllContracts() // Serve from Vercel cache, then update. see https://vercel.com/docs/concepts/functions/edge-caching res.setHeader('Cache-Control', 's-maxage=1, stale-while-revalidate') - res.status(200).json(contracts.map(toLiteContract)) + res.status(200).json(contracts.map(toLiteMarket)) } diff --git a/web/pages/api/v0/slug/[slug].ts b/web/pages/api/v0/slug/[slug].ts index 122fa5c1..086cdf38 100644 --- a/web/pages/api/v0/slug/[slug].ts +++ b/web/pages/api/v0/slug/[slug].ts @@ -2,11 +2,11 @@ import { NextApiRequest, NextApiResponse } from 'next' import { listAllBets } from '../../../../lib/firebase/bets' import { listAllComments } from '../../../../lib/firebase/comments' import { getContractFromSlug } from '../../../../lib/firebase/contracts' -import { FullContract, ApiError, toLiteContract } from '../_types' +import { FullMarket, ApiError, toLiteMarket } from '../_types' export default async function handler( req: NextApiRequest, - res: NextApiResponse + res: NextApiResponse ) { const { slug } = req.query @@ -25,7 +25,7 @@ export default async function handler( // Cache on Vercel edge servers for 2min res.setHeader('Cache-Control', 'max-age=0, s-maxage=120') return res.status(200).json({ - ...toLiteContract(contract), + ...toLiteMarket(contract), bets, comments, })