diff --git a/web/components/contract-overview.tsx b/web/components/contract-overview.tsx index 8f025ed2..9a5ff475 100644 --- a/web/components/contract-overview.tsx +++ b/web/components/contract-overview.tsx @@ -1,17 +1,31 @@ import React from 'react' -import { compute, Contract } from '../lib/firebase/contracts' +import { compute, Contract, deleteContract } from '../lib/firebase/contracts' import { Col } from './layout/col' import { Spacer } from './layout/spacer' import { ContractProbGraph } from './contract-prob-graph' import { ContractDetails } from './contracts-list' +import router from 'next/router' +import { useUser } from '../hooks/use-user' export const ContractOverview = (props: { contract: Contract className?: string }) => { const { contract, className } = props - const { probPercent } = compute(contract) + const { resolution, creatorId, isResolved } = contract + const { probPercent, volume } = compute(contract) + const user = useUser() + const isCreator = user?.id === creatorId + + const resolutionColor = + resolution === 'YES' + ? 'text-primary' + : resolution === 'NO' + ? 'text-red-400' + : resolution === 'CANCEL' + ? 'text-yellow-400' + : '' return ( @@ -23,12 +37,17 @@ export const ContractOverview = (props: { - {!contract.resolution && + {resolution ? ( + +
Resolved:
+
{resolution}
+ + ) : ( {probPercent}
chance
- } + )} @@ -40,6 +59,23 @@ export const ContractOverview = (props: {
{contract.description}
+ + {/* Show a delete button for contracts without any trading */} + {isCreator && (volume === 0 || isResolved) && ( + <> + + + + )} ) } diff --git a/web/components/contracts-list.tsx b/web/components/contracts-list.tsx index c6f51fa9..a627a738 100644 --- a/web/components/contracts-list.tsx +++ b/web/components/contracts-list.tsx @@ -4,19 +4,21 @@ import { Row } from '../components/layout/row' import { useEffect, useState } from 'react' import { useUser } from '../hooks/use-user' import { compute, Contract, listContracts } from '../lib/firebase/contracts' -import { formatWithCommas } from '../lib/util/format' +import { formatMoney } from '../lib/util/format' export function ContractDetails(props: { contract: Contract }) { const { contract } = props - const { volume, createdDate } = compute(contract) + const { volume, createdDate, resolvedDate } = compute(contract) return (
By {contract.creatorName}
-
{createdDate}
+
+ {resolvedDate ? `${createdDate} - ${resolvedDate}` : createdDate} +
-
{formatWithCommas(volume)} vol
+
{formatMoney(volume)} pot
) } @@ -26,15 +28,14 @@ function ContractCard(props: { contract: Contract }) { const { probPercent } = compute(contract) const { resolution } = contract - const resolutionColor = ( + const resolutionColor = resolution === 'YES' ? 'text-primary' : resolution === 'NO' - ? 'text-red-400' - : resolution === 'CANCEL' - ? 'text-yellow-400' - : '' - ) + ? 'text-red-400' + : resolution === 'CANCEL' + ? 'text-yellow-400' + : '' return ( @@ -53,7 +54,9 @@ function ContractCard(props: { contract: Contract }) { {/* Right side of card */} - + {contract.resolution || (
{probPercent} diff --git a/web/components/resolved-panel.tsx b/web/components/resolved-panel.tsx deleted file mode 100644 index 35e41896..00000000 --- a/web/components/resolved-panel.tsx +++ /dev/null @@ -1,74 +0,0 @@ -import clsx from 'clsx' -import dayjs from 'dayjs' -import { useRouter } from 'next/router' -import React from 'react' - -import { Contract, deleteContract } from '../lib/firebase/contracts' -import { formatMoney } from '../lib/util/format' -import { Col } from './layout/col' -import { Spacer } from './layout/spacer' - -export function ResolvedPanel(props: { - contract: Contract - className?: string -}) { - const router = useRouter() - - const { contract, className } = props - - const { resolution, resolutionTime, pot, seedAmounts } = contract - - const total = pot.YES + pot.NO - seedAmounts.YES - seedAmounts.NO - - const color = - resolution === 'YES' - ? 'text-primary' - : resolution === 'NO' - ? 'text-red-400' - : resolution === 'CANCEL' - ? 'text-yellow-400' - : 'text-gray-500' - - return ( - -
- Resolved: {resolution} -
- - -
- {dayjs(resolutionTime).format('MMM D, HH:mma')} -
- - -
- {resolution === 'YES' ? ( - <>Yes bettors have collectively won {formatMoney(total)}. - ) : resolution === 'NO' ? ( - <>No bettors have collectively won {formatMoney(total)}. - ) : ( - <>All bets have been returned. - )} -
- - {/* Show a delete button for contracts without any trading */} - {total === 0 && ( - - )} - - ) -} diff --git a/web/lib/firebase/contracts.ts b/web/lib/firebase/contracts.ts index 12be8a0b..ef7a46a0 100644 --- a/web/lib/firebase/contracts.ts +++ b/web/lib/firebase/contracts.ts @@ -37,12 +37,13 @@ export type Contract = { } export function compute(contract: Contract) { - const { pot, seedAmounts, createdTime } = contract + const { pot, seedAmounts, createdTime, resolutionTime, isResolved } = 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 resolvedDate = isResolved ? dayjs(resolutionTime).format('MMM D') : undefined + return { volume, probPercent, createdDate, resolvedDate } } const db = getFirestore(app) diff --git a/web/pages/contract/[contractId].tsx b/web/pages/contract/[contractId].tsx index 0bf354e4..52f9cf4a 100644 --- a/web/pages/contract/[contractId].tsx +++ b/web/pages/contract/[contractId].tsx @@ -7,7 +7,7 @@ import { BetPanel } from '../../components/bet-panel' import { Col } from '../../components/layout/col' import { useUser } from '../../hooks/use-user' import { ResolutionPanel } from '../../components/resolution-panel' -import { ResolvedPanel } from '../../components/resolved-panel' +import clsx from 'clsx' export default function ContractPage() { const user = useUser() @@ -29,25 +29,32 @@ export default function ContractPage() { const isCreator = user?.id === creatorId return ( -
+
- + -
+ {!isResolved && ( + <> +
- {isResolved ? ( - - ) : isCreator ? ( - - ) : ( - + {isCreator ? ( + + ) : ( + + )} + )} -
+ ) }