Skip to content

Commit

Permalink
Create SportsContract type
Browse files Browse the repository at this point in the history
  • Loading branch information
IanPhilips committed Jan 14, 2025
1 parent 27af447 commit 0b2ee4a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 15 deletions.
4 changes: 2 additions & 2 deletions backend/shared/src/supabase/search-contracts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Contract } from 'common/contract'
import { Contract, isSportsContract } from 'common/contract'
import { createSupabaseDirectClient } from 'shared/supabase/init'
import {
from,
Expand Down Expand Up @@ -454,7 +454,7 @@ export const sortFields: SortFields = {
// sql: `close_time`,
sql: `coalesce((data->>'sportsStartTimestamp')::timestamp with time zone, close_time)`,
sortCallback: (c: Contract) =>
c.sportsStartTimestamp
isSportsContract(c)
? tsToMillis(c.sportsStartTimestamp)
: c.closeTime ?? Infinity,
order: 'ASC',
Expand Down
16 changes: 10 additions & 6 deletions common/src/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,6 @@ export type Contract<T extends AnyContractType = AnyContractType> = {
token: ContractToken
siblingContractId?: string

sportsStartTimestamp?: string
sportsEventId?: string
sportsLeague?: string

takerAPIOrdersDisabled?: boolean

// Manifold.love
Expand Down Expand Up @@ -145,7 +141,7 @@ export type QuadraticFundingContract = Contract & QuadraticFunding
export type StonkContract = Contract & Stonk
export type BountiedQuestionContract = Contract & BountiedQuestion
export type PollContract = Contract & Poll

export type SportsContract = Contract & Sports
export type BinaryOrPseudoNumericContract =
| BinaryContract
| PseudoNumericContract
Expand Down Expand Up @@ -283,6 +279,12 @@ export type Poll = {
resolutions?: string[]
}

export type Sports = {
sportsStartTimestamp: string
sportsEventId: string
sportsLeague: string
}

export type MultiContract = CPMMMultiContract | CPMMNumericContract

type AnyOutcomeType =
Expand Down Expand Up @@ -359,7 +361,9 @@ export const isBinaryMulti = (contract: Contract) =>
contract.shouldAnswersSumToOne
// contract.createdTime > 1708574059795 // In case we don't want to convert pre-commit contracts

export const isSportsContract = (contract: Contract) => contract.sportsEventId
export const isSportsContract = (
contract: Contract
): contract is SportsContract => 'sportsEventId' in contract

export const getMainBinaryMCAnswer = (contract: Contract) =>
isBinaryMulti(contract) && contract.mechanism === 'cpmm-multi-1'
Expand Down
8 changes: 5 additions & 3 deletions common/src/new-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ export function getNewContract(
| 'isTwitchContract'
| 'marketTier'
| 'token'
| 'sportsStartTimestamp'
| 'sportsEventId'
| 'sportsLeague'
| 'takerAPIOrdersDisabled'
| 'siblingContractId'
| 'coverImageUrl'
Expand All @@ -60,6 +57,11 @@ export function getNewContract(

// Bountied
isAutoBounty?: boolean | undefined

// Sports
sportsStartTimestamp?: string
sportsEventId?: string
sportsLeague?: string
}
) {
const {
Expand Down
6 changes: 4 additions & 2 deletions common/src/sports-info.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Contract } from './contract'
import { Contract, isSportsContract } from './contract'
import { HOUR_MS } from './util/time'

export interface TeamMetadata {
Expand All @@ -25,7 +25,9 @@ export interface SportsGames {

export const getIsLive = (contract: Contract) => {
const now = Date.now()
const sportsStartTimestamp = contract.sportsStartTimestamp
const sportsStartTimestamp = isSportsContract(contract)
? contract.sportsStartTimestamp
: undefined
if (!sportsStartTimestamp) return false
const start = new Date(sportsStartTimestamp + 'Z').getTime()
return now >= start && now < (contract.closeTime ?? start + 3 * HOUR_MS)
Expand Down
4 changes: 2 additions & 2 deletions web/pages/explore/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { LoadingIndicator } from 'web/components/widgets/loading-indicator'
import { User } from 'common/user'
import { FaBaseballBall } from 'react-icons/fa'
import { AiContent } from 'web/components/ai-content'
import { Contract } from 'common/contract'
import { Contract, isSportsContract } from 'common/contract'
import { tsToMillis } from 'common/supabase/utils'
import { ENV } from 'common/envs/constants'

Expand All @@ -54,7 +54,7 @@ function LiveSoonContent() {
gids: isProd ? ALL_IDS : SPORTS_ID,
}}
sortCallback={(c: Contract) =>
c.sportsStartTimestamp
isSportsContract(c)
? tsToMillis(c.sportsStartTimestamp)
: c.closeTime ?? Infinity
}
Expand Down

0 comments on commit 0b2ee4a

Please sign in to comment.