diff --git a/web/components/contract-overview.tsx b/web/components/contract-overview.tsx
index 14ac0568..3add4ce4 100644
--- a/web/components/contract-overview.tsx
+++ b/web/components/contract-overview.tsx
@@ -1,42 +1,26 @@
import React from 'react'
-import dayjs from 'dayjs'
-import { Contract } from '../lib/firebase/contracts'
+import { compute, Contract } from '../lib/firebase/contracts'
import { Col } from './layout/col'
-import { Row } from './layout/row'
import { Spacer } from './layout/spacer'
-import { formatWithCommas } from '../lib/util/format'
import { ContractProbGraph } from './contract-prob-graph'
+import { ContractDetails } from '../pages/markets'
export const ContractOverview = (props: {
contract: Contract
className?: string
}) => {
const { contract, className } = props
- const { pot, seedAmounts, createdTime } = contract
-
- const volume = pot.YES + pot.NO - seedAmounts.YES - seedAmounts.NO
- const prob = pot.YES ** 2 / (pot.YES ** 2 + pot.NO ** 2)
- const probPercent = Math.round(prob * 100) + '%'
+ const { probPercent } = compute(contract)
return (
- {contract.question}
+
+ {contract.question}
+
-
-
- By {contract.creatorName}
-
- •
-
- {dayjs(createdTime).format('MMM D')}
-
- •
-
- {formatWithCommas(volume)} volume
-
-
+
diff --git a/web/lib/firebase/contracts.ts b/web/lib/firebase/contracts.ts
index 07313abb..12be8a0b 100644
--- a/web/lib/firebase/contracts.ts
+++ b/web/lib/firebase/contracts.ts
@@ -13,6 +13,7 @@ import {
getDoc,
limit,
} from 'firebase/firestore'
+import dayjs from 'dayjs'
export type Contract = {
id: string // Chosen by creator; must be unique
@@ -35,6 +36,15 @@ export type Contract = {
resolution?: 'YES' | 'NO' | 'CANCEL' // Chosen by creator; must be one of outcomes
}
+export function compute(contract: Contract) {
+ const { pot, seedAmounts, createdTime } = contract
+ const volume = pot.YES + pot.NO - seedAmounts.YES - seedAmounts.NO
+ const prob = pot.YES ** 2 / (pot.YES ** 2 + pot.NO ** 2)
+ const probPercent = Math.round(prob * 100) + '%'
+ const createdDate = dayjs(createdTime).format('MMM D')
+ return { volume, probPercent, createdDate }
+}
+
const db = getFirestore(app)
const contractCollection = collection(db, 'contracts')
diff --git a/web/pages/markets.tsx b/web/pages/markets.tsx
index e27cc87b..ff3315d2 100644
--- a/web/pages/markets.tsx
+++ b/web/pages/markets.tsx
@@ -1,23 +1,31 @@
-import dayjs from 'dayjs'
import Link from 'next/link'
import React, { useEffect, useState } from 'react'
import { Header } from '../components/header'
import { Col } from '../components/layout/col'
import { Row } from '../components/layout/row'
-import { Spacer } from '../components/layout/spacer'
import { Title } from '../components/title'
-import { listAllContracts } from '../lib/firebase/contracts'
+import { compute, listAllContracts } from '../lib/firebase/contracts'
import { Contract } from '../lib/firebase/contracts'
import { formatWithCommas } from '../lib/util/format'
+export function ContractDetails(props: { contract: Contract }) {
+ const { contract } = props
+ const { volume, createdDate } = compute(contract)
+
+ return (
+
+ By {contract.creatorName}
+ •
+ {createdDate}
+ •
+ {formatWithCommas(volume)} vol
+
+ )
+}
+
function ContractCard(props: { contract: Contract }) {
const { contract } = props
-
- // Copied from contract-overview.tsx
- const { pot, seedAmounts, createdTime } = contract
- const volume = pot.YES + pot.NO - seedAmounts.YES - seedAmounts.NO
- const prob = pot.YES ** 2 / (pot.YES ** 2 + pot.NO ** 2)
- const probPercent = Math.round(prob * 100) + '%'
+ const { probPercent } = compute(contract)
return (
@@ -28,28 +36,15 @@ function ContractCard(props: { contract: Contract }) {
{/* Left side of card */}
-
+
{contract.question}
-
- {/* Copied from contract-overview.tsx */}
-
-
- By {contract.creatorName}
-
- •
-
- {dayjs(createdTime).format('MMM D')}
-
- •
-
- {formatWithCommas(volume)} vol
-
-
+
+
{/* Right side of card */}
-
+
{contract.resolution || (
{probPercent}