rename path, compute to contractPath, contractMetrics
This commit is contained in:
parent
b2f50a438e
commit
be2989bbeb
|
@ -14,7 +14,11 @@ import {
|
||||||
} from '../lib/util/format'
|
} from '../lib/util/format'
|
||||||
import { Col } from './layout/col'
|
import { Col } from './layout/col'
|
||||||
import { Spacer } from './layout/spacer'
|
import { Spacer } from './layout/spacer'
|
||||||
import { Contract, getContractFromId, path } from '../lib/firebase/contracts'
|
import {
|
||||||
|
Contract,
|
||||||
|
getContractFromId,
|
||||||
|
contractPath,
|
||||||
|
} from '../lib/firebase/contracts'
|
||||||
import { Row } from './layout/row'
|
import { Row } from './layout/row'
|
||||||
import { UserLink } from './user-page'
|
import { UserLink } from './user-page'
|
||||||
import {
|
import {
|
||||||
|
@ -130,7 +134,7 @@ function MyContractBets(props: { contract: Contract; bets: Bet[] }) {
|
||||||
<Row className="flex-wrap gap-4">
|
<Row className="flex-wrap gap-4">
|
||||||
<Col className="flex-[2] gap-1">
|
<Col className="flex-[2] gap-1">
|
||||||
<Row className="mr-6">
|
<Row className="mr-6">
|
||||||
<Link href={path(contract)}>
|
<Link href={contractPath(contract)}>
|
||||||
<a
|
<a
|
||||||
className="font-medium text-indigo-700 hover:underline hover:decoration-indigo-400 hover:decoration-2"
|
className="font-medium text-indigo-700 hover:underline hover:decoration-indigo-400 hover:decoration-2"
|
||||||
onClick={(e) => e.stopPropagation()}
|
onClick={(e) => e.stopPropagation()}
|
||||||
|
|
|
@ -4,7 +4,11 @@ import { Row } from '../components/layout/row'
|
||||||
import { formatMoney } from '../lib/util/format'
|
import { formatMoney } from '../lib/util/format'
|
||||||
import { UserLink } from './user-page'
|
import { UserLink } from './user-page'
|
||||||
import { Linkify } from './linkify'
|
import { Linkify } from './linkify'
|
||||||
import { Contract, compute, path } from '../lib/firebase/contracts'
|
import {
|
||||||
|
Contract,
|
||||||
|
contractMetrics,
|
||||||
|
contractPath,
|
||||||
|
} from '../lib/firebase/contracts'
|
||||||
import { Col } from './layout/col'
|
import { Col } from './layout/col'
|
||||||
import { parseTags } from '../lib/util/parse'
|
import { parseTags } from '../lib/util/parse'
|
||||||
import dayjs from 'dayjs'
|
import dayjs from 'dayjs'
|
||||||
|
@ -15,10 +19,10 @@ export function ContractCard(props: {
|
||||||
}) {
|
}) {
|
||||||
const { contract, showHotVolume } = props
|
const { contract, showHotVolume } = props
|
||||||
const { question, resolution } = contract
|
const { question, resolution } = contract
|
||||||
const { probPercent } = compute(contract)
|
const { probPercent } = contractMetrics(contract)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Link href={path(contract)}>
|
<Link href={contractPath(contract)}>
|
||||||
<a>
|
<a>
|
||||||
<li className="col-span-1 bg-white hover:bg-gray-100 shadow-md rounded-lg divide-y divide-gray-200">
|
<li className="col-span-1 bg-white hover:bg-gray-100 shadow-md rounded-lg divide-y divide-gray-200">
|
||||||
<div className="card">
|
<div className="card">
|
||||||
|
@ -98,7 +102,7 @@ export function AbbrContractDetails(props: {
|
||||||
}) {
|
}) {
|
||||||
const { contract, showHotVolume } = props
|
const { contract, showHotVolume } = props
|
||||||
const { volume24Hours } = contract
|
const { volume24Hours } = contract
|
||||||
const { truePool } = compute(contract)
|
const { truePool } = contractMetrics(contract)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Col className={clsx('text-sm text-gray-500 gap-2')}>
|
<Col className={clsx('text-sm text-gray-500 gap-2')}>
|
||||||
|
@ -122,7 +126,7 @@ export function AbbrContractDetails(props: {
|
||||||
export function ContractDetails(props: { contract: Contract }) {
|
export function ContractDetails(props: { contract: Contract }) {
|
||||||
const { contract } = props
|
const { contract } = props
|
||||||
const { question, description, closeTime } = contract
|
const { question, description, closeTime } = contract
|
||||||
const { truePool, createdDate, resolvedDate } = compute(contract)
|
const { truePool, createdDate, resolvedDate } = contractMetrics(contract)
|
||||||
|
|
||||||
const tags = parseTags(`${question} ${description}`).map((tag) => `#${tag}`)
|
const tags = parseTags(`${question} ${description}`).map((tag) => `#${tag}`)
|
||||||
|
|
||||||
|
@ -169,7 +173,7 @@ export function ContractDetails(props: { contract: Contract }) {
|
||||||
// String version of the above, to send to the OpenGraph image generator
|
// String version of the above, to send to the OpenGraph image generator
|
||||||
export function contractTextDetails(contract: Contract) {
|
export function contractTextDetails(contract: Contract) {
|
||||||
const { question, description, closeTime } = contract
|
const { question, description, closeTime } = contract
|
||||||
const { truePool, createdDate, resolvedDate } = compute(contract)
|
const { truePool, createdDate, resolvedDate } = contractMetrics(contract)
|
||||||
|
|
||||||
const tags = parseTags(`${question} ${description}`).map((tag) => `#${tag}`)
|
const tags = parseTags(`${question} ${description}`).map((tag) => `#${tag}`)
|
||||||
|
|
||||||
|
|
|
@ -17,9 +17,9 @@ import dayjs from 'dayjs'
|
||||||
import relativeTime from 'dayjs/plugin/relativeTime'
|
import relativeTime from 'dayjs/plugin/relativeTime'
|
||||||
import { OutcomeLabel } from './outcome-label'
|
import { OutcomeLabel } from './outcome-label'
|
||||||
import {
|
import {
|
||||||
compute,
|
contractMetrics,
|
||||||
Contract,
|
Contract,
|
||||||
path,
|
contractPath,
|
||||||
updateContract,
|
updateContract,
|
||||||
} from '../lib/firebase/contracts'
|
} from '../lib/firebase/contracts'
|
||||||
import { useUser } from '../hooks/use-user'
|
import { useUser } from '../hooks/use-user'
|
||||||
|
@ -201,7 +201,7 @@ export function ContractDescription(props: {
|
||||||
|
|
||||||
function FeedQuestion(props: { contract: Contract }) {
|
function FeedQuestion(props: { contract: Contract }) {
|
||||||
const { contract } = props
|
const { contract } = props
|
||||||
const { probPercent } = compute(contract)
|
const { probPercent } = contractMetrics(contract)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
@ -218,7 +218,10 @@ function FeedQuestion(props: { contract: Contract }) {
|
||||||
<Timestamp time={contract.createdTime} />
|
<Timestamp time={contract.createdTime} />
|
||||||
</div>
|
</div>
|
||||||
<Row className="justify-between gap-4 mb-2">
|
<Row className="justify-between gap-4 mb-2">
|
||||||
<SiteLink href={path(contract)} className="text-xl text-indigo-700">
|
<SiteLink
|
||||||
|
href={contractPath(contract)}
|
||||||
|
className="text-xl text-indigo-700"
|
||||||
|
>
|
||||||
{contract.question}
|
{contract.question}
|
||||||
</SiteLink>
|
</SiteLink>
|
||||||
<ResolutionOrChance
|
<ResolutionOrChance
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import {
|
import {
|
||||||
compute,
|
contractMetrics,
|
||||||
Contract,
|
Contract,
|
||||||
deleteContract,
|
deleteContract,
|
||||||
path,
|
contractPath,
|
||||||
} from '../lib/firebase/contracts'
|
} from '../lib/firebase/contracts'
|
||||||
import { Col } from './layout/col'
|
import { Col } from './layout/col'
|
||||||
import { Spacer } from './layout/spacer'
|
import { Spacer } from './layout/spacer'
|
||||||
|
@ -22,7 +22,7 @@ export const ContractOverview = (props: {
|
||||||
}) => {
|
}) => {
|
||||||
const { contract, className } = props
|
const { contract, className } = props
|
||||||
const { resolution, creatorId, creatorName } = contract
|
const { resolution, creatorId, creatorName } = contract
|
||||||
const { probPercent, truePool } = compute(contract)
|
const { probPercent, truePool } = contractMetrics(contract)
|
||||||
|
|
||||||
const user = useUser()
|
const user = useUser()
|
||||||
const isCreator = user?.id === creatorId
|
const isCreator = user?.id === creatorId
|
||||||
|
@ -35,7 +35,7 @@ export const ContractOverview = (props: {
|
||||||
? `Resolved ${resolution}!`
|
? `Resolved ${resolution}!`
|
||||||
: `Resolved ${resolution} by ${creatorName}:`
|
: `Resolved ${resolution} by ${creatorName}:`
|
||||||
: `Currently ${probPercent} chance, place your bets here:`
|
: `Currently ${probPercent} chance, place your bets here:`
|
||||||
const url = `https://manifold.markets${path(contract)}`
|
const url = `https://manifold.markets${contractPath(contract)}`
|
||||||
const tweetText = `${tweetQuestion}\n\n${tweetDescription}\n\n${url}`
|
const tweetText = `${tweetQuestion}\n\n${tweetDescription}\n\n${url}`
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -3,7 +3,11 @@ import Link from 'next/link'
|
||||||
import clsx from 'clsx'
|
import clsx from 'clsx'
|
||||||
import { useEffect, useState } from 'react'
|
import { useEffect, useState } from 'react'
|
||||||
|
|
||||||
import { compute, Contract, listContracts } from '../lib/firebase/contracts'
|
import {
|
||||||
|
contractMetrics,
|
||||||
|
Contract,
|
||||||
|
listContracts,
|
||||||
|
} from '../lib/firebase/contracts'
|
||||||
import { User } from '../lib/firebase/users'
|
import { User } from '../lib/firebase/users'
|
||||||
import { Col } from './layout/col'
|
import { Col } from './layout/col'
|
||||||
import { SiteLink } from './site-link'
|
import { SiteLink } from './site-link'
|
||||||
|
@ -189,7 +193,9 @@ export function SearchableGrid(props: {
|
||||||
if (sort === 'newest' || sort === 'resolved' || sort === 'all') {
|
if (sort === 'newest' || sort === 'resolved' || sort === 'all') {
|
||||||
matches.sort((a, b) => b.createdTime - a.createdTime)
|
matches.sort((a, b) => b.createdTime - a.createdTime)
|
||||||
} else if (sort === 'most-traded') {
|
} else if (sort === 'most-traded') {
|
||||||
matches.sort((a, b) => compute(b).truePool - compute(a).truePool)
|
matches.sort(
|
||||||
|
(a, b) => contractMetrics(b).truePool - contractMetrics(a).truePool
|
||||||
|
)
|
||||||
} else if (sort === 'creator' || sort === 'tag') {
|
} else if (sort === 'creator' || sort === 'tag') {
|
||||||
matches.sort((a, b) => b.volume7Days - a.volume7Days)
|
matches.sort((a, b) => b.volume7Days - a.volume7Days)
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,24 +18,36 @@ import {
|
||||||
import { app } from './init'
|
import { app } from './init'
|
||||||
import { getValues, listenForValues } from './utils'
|
import { getValues, listenForValues } from './utils'
|
||||||
import { Contract } from '../../../common/contract'
|
import { Contract } from '../../../common/contract'
|
||||||
|
import { getProbability } from '../../../common/calculate'
|
||||||
export type { Contract }
|
export type { Contract }
|
||||||
|
|
||||||
export function path(contract: Contract) {
|
export function contractPath(contract: Contract) {
|
||||||
// For now, derive username from creatorName
|
// For now, derive username from creatorName
|
||||||
return `/${contract.creatorUsername}/${contract.slug}`
|
return `/${contract.creatorUsername}/${contract.slug}`
|
||||||
}
|
}
|
||||||
|
|
||||||
export function compute(contract: Contract) {
|
export function contractMetrics(contract: Contract) {
|
||||||
const { pool, startPool, createdTime, resolutionTime, isResolved } = contract
|
const {
|
||||||
const truePool = pool.YES + pool.NO - startPool.YES - startPool.NO
|
pool,
|
||||||
const prob = pool.YES ** 2 / (pool.YES ** 2 + pool.NO ** 2)
|
startPool,
|
||||||
|
totalShares,
|
||||||
|
createdTime,
|
||||||
|
resolutionTime,
|
||||||
|
isResolved,
|
||||||
|
} = contract
|
||||||
|
|
||||||
|
const truePool = pool.YES + pool.NO
|
||||||
|
const prob = getProbability(totalShares)
|
||||||
const probPercent = Math.round(prob * 100) + '%'
|
const probPercent = Math.round(prob * 100) + '%'
|
||||||
const startProb =
|
|
||||||
startPool.YES ** 2 / (startPool.YES ** 2 + startPool.NO ** 2)
|
const startProb = getProbability(startPool)
|
||||||
|
|
||||||
const createdDate = dayjs(createdTime).format('MMM D')
|
const createdDate = dayjs(createdTime).format('MMM D')
|
||||||
|
|
||||||
const resolvedDate = isResolved
|
const resolvedDate = isResolved
|
||||||
? dayjs(resolutionTime).format('MMM D')
|
? dayjs(resolutionTime).format('MMM D')
|
||||||
: undefined
|
: undefined
|
||||||
|
|
||||||
return { truePool, probPercent, startProb, createdDate, resolvedDate }
|
return { truePool, probPercent, startProb, createdDate, resolvedDate }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ import { Title } from '../../components/title'
|
||||||
import { Spacer } from '../../components/layout/spacer'
|
import { Spacer } from '../../components/layout/spacer'
|
||||||
import { User } from '../../lib/firebase/users'
|
import { User } from '../../lib/firebase/users'
|
||||||
import {
|
import {
|
||||||
compute,
|
contractMetrics,
|
||||||
Contract,
|
Contract,
|
||||||
getContractFromSlug,
|
getContractFromSlug,
|
||||||
} from '../../lib/firebase/contracts'
|
} from '../../lib/firebase/contracts'
|
||||||
|
@ -58,7 +58,7 @@ export default function ContractPage(props: {
|
||||||
!isResolved && (!contract.closeTime || contract.closeTime > Date.now())
|
!isResolved && (!contract.closeTime || contract.closeTime > Date.now())
|
||||||
const allowResolve = !isResolved && isCreator && !!user
|
const allowResolve = !isResolved && isCreator && !!user
|
||||||
|
|
||||||
const { probPercent } = compute(contract)
|
const { probPercent } = contractMetrics(contract)
|
||||||
|
|
||||||
const description = resolution
|
const description = resolution
|
||||||
? `Resolved ${resolution}. ${contract.description}`
|
? `Resolved ${resolution}. ${contract.description}`
|
||||||
|
|
|
@ -8,7 +8,7 @@ import { CreatorContractsList } from '../components/contracts-list'
|
||||||
import { Spacer } from '../components/layout/spacer'
|
import { Spacer } from '../components/layout/spacer'
|
||||||
import { Title } from '../components/title'
|
import { Title } from '../components/title'
|
||||||
import { useUser } from '../hooks/use-user'
|
import { useUser } from '../hooks/use-user'
|
||||||
import { Contract, path } from '../lib/firebase/contracts'
|
import { Contract, contractPath } from '../lib/firebase/contracts'
|
||||||
import { Page } from '../components/page'
|
import { Page } from '../components/page'
|
||||||
import { AdvancedPanel } from '../components/advanced-panel'
|
import { AdvancedPanel } from '../components/advanced-panel'
|
||||||
import { createContract } from '../lib/firebase/api-call'
|
import { createContract } from '../lib/firebase/api-call'
|
||||||
|
@ -73,7 +73,7 @@ export default function NewContract() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
await router.push(path(result.contract as Contract))
|
await router.push(contractPath(result.contract as Contract))
|
||||||
}
|
}
|
||||||
|
|
||||||
const descriptionPlaceholder = `e.g. This market will resolve to “Yes” if, by June 2, 2021, 11:59:59 PM ET, Paxlovid (also known under PF-07321332)...`
|
const descriptionPlaceholder = `e.g. This market will resolve to “Yes” if, by June 2, 2021, 11:59:59 PM ET, Paxlovid (also known under PF-07321332)...`
|
||||||
|
|
|
@ -10,7 +10,11 @@ import { Page } from '../components/page'
|
||||||
import { Title } from '../components/title'
|
import { Title } from '../components/title'
|
||||||
import { useUser } from '../hooks/use-user'
|
import { useUser } from '../hooks/use-user'
|
||||||
import { createContract } from '../lib/firebase/api-call'
|
import { createContract } from '../lib/firebase/api-call'
|
||||||
import { compute, Contract, path } from '../lib/firebase/contracts'
|
import {
|
||||||
|
contractMetrics,
|
||||||
|
Contract,
|
||||||
|
contractPath,
|
||||||
|
} from '../lib/firebase/contracts'
|
||||||
|
|
||||||
type Prediction = {
|
type Prediction = {
|
||||||
question: string
|
question: string
|
||||||
|
@ -20,12 +24,12 @@ type Prediction = {
|
||||||
}
|
}
|
||||||
|
|
||||||
function toPrediction(contract: Contract): Prediction {
|
function toPrediction(contract: Contract): Prediction {
|
||||||
const { startProb } = compute(contract)
|
const { startProb } = contractMetrics(contract)
|
||||||
return {
|
return {
|
||||||
question: contract.question,
|
question: contract.question,
|
||||||
description: contract.description,
|
description: contract.description,
|
||||||
initialProb: startProb * 100,
|
initialProb: startProb * 100,
|
||||||
createdUrl: path(contract),
|
createdUrl: contractPath(contract),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user