This commit is contained in:
Milli 2022-06-03 01:37:37 +02:00
parent a19e6326a3
commit f3dfd81666
4 changed files with 59 additions and 26 deletions

View File

@ -106,7 +106,8 @@ export function ContractDetails(props: {
disabled?: boolean disabled?: boolean
}) { }) {
const { contract, bets, isCreator, disabled } = props const { contract, bets, isCreator, disabled } = props
const { closeTime, autoResolutionTime, creatorName, creatorUsername } = contract const { closeTime, autoResolutionTime, creatorName, creatorUsername } =
contract
const { volumeLabel, resolvedDate } = contractMetrics(contract) const { volumeLabel, resolvedDate } = contractMetrics(contract)
return ( return (
@ -167,7 +168,13 @@ export function ContractDetails(props: {
<div className="whitespace-nowrap">{volumeLabel}</div> <div className="whitespace-nowrap">{volumeLabel}</div>
</Row> </Row>
{!disabled && <ContractInfoDialog contract={contract} bets={bets} isCreator={isCreator ?? false}/>} {!disabled && (
<ContractInfoDialog
contract={contract}
bets={bets}
isCreator={isCreator ?? false}
/>
)}
</Row> </Row>
) )
} }
@ -215,14 +222,18 @@ function EditableCloseDate(props: {
const newAutoResolutionTime = newCloseTime + 7 * DAY_MS const newAutoResolutionTime = newCloseTime + 7 * DAY_MS
let newDescription = `${description}\n\nClose date updated to ${formattedCloseDate}` let newDescription = `${description}\n\nClose date updated to ${formattedCloseDate}`
const update : Partial<Contract> = { const update: Partial<Contract> = {
closeTime: newCloseTime closeTime: newCloseTime,
} }
if (newAutoResolutionTime >= autoResolutionTime) { if (newAutoResolutionTime >= autoResolutionTime) {
update.autoResolutionTime = newAutoResolutionTime update.autoResolutionTime = newAutoResolutionTime
const formattedNewAutoResolutionTime = dayjs(newAutoResolutionTime).format('YYYY-MM-DD h:mm a') const formattedNewAutoResolutionTime = dayjs(
newDescription = newDescription.concat(`\nAuto resolution date updated to ${formattedNewAutoResolutionTime}`) newAutoResolutionTime
).format('YYYY-MM-DD h:mm a')
newDescription = newDescription.concat(
`\nAuto resolution date updated to ${formattedNewAutoResolutionTime}`
)
} }
update.description = newDescription update.description = newDescription

View File

@ -1,4 +1,8 @@
import { DotsHorizontalIcon, PencilIcon, CheckIcon } from '@heroicons/react/outline' import {
DotsHorizontalIcon,
PencilIcon,
CheckIcon,
} from '@heroicons/react/outline'
import clsx from 'clsx' import clsx from 'clsx'
import dayjs from 'dayjs' import dayjs from 'dayjs'
import { uniqBy } from 'lodash' import { uniqBy } from 'lodash'
@ -25,12 +29,22 @@ import { TweetButton } from '../tweet-button'
const formatTime = (dt: number) => dayjs(dt).format('MMM DD, YYYY hh:mm a z') const formatTime = (dt: number) => dayjs(dt).format('MMM DD, YYYY hh:mm a z')
export function ContractInfoDialog(props: { contract: Contract; bets: Bet[]; isCreator: boolean }) { export function ContractInfoDialog(props: {
contract: Contract
bets: Bet[]
isCreator: boolean
}) {
const { contract, bets, isCreator } = props const { contract, bets, isCreator } = props
const [open, setOpen] = useState(false) const [open, setOpen] = useState(false)
const { createdTime, closeTime, resolutionTime, autoResolutionTime, autoResolution } = contract const {
createdTime,
closeTime,
resolutionTime,
autoResolutionTime,
autoResolution,
} = contract
const tradersCount = uniqBy(bets, 'userId').length const tradersCount = uniqBy(bets, 'userId').length
return ( return (
@ -89,9 +103,9 @@ export function ContractInfoDialog(props: { contract: Contract; bets: Bet[]; isC
isCreator={isCreator} isCreator={isCreator}
/> />
<tr> <tr>
<td>Auto resolution</td> <td>Auto resolution</td>
<td>{contract.autoResolution}</td> <td>{contract.autoResolution}</td>
</tr> </tr>
</> </>
)} )}
@ -176,10 +190,10 @@ export function EditableResolutionTime(props: {
const onSave = () => { const onSave = () => {
const newTime = dayjs(timeString).valueOf() const newTime = dayjs(timeString).valueOf()
if (newTime === time) setIsEditing(false) if (newTime === time) setIsEditing(false)
else if ( contract.closeTime && newTime > (contract.closeTime ?? Date.now)) { else if (contract.closeTime && newTime > (contract.closeTime ?? Date.now)) {
const formattedTime = dayjs(time).format('YYYY-MM-DD h:mm a') const formattedTime = dayjs(time).format('YYYY-MM-DD h:mm a')
const newDescription = `${contract.description}\n\nAuto resolution date updated to ${formattedTime}` const newDescription = `${contract.description}\n\nAuto resolution date updated to ${formattedTime}`
updateContract(contract.id, { updateContract(contract.id, {
autoResolutionTime: newTime, autoResolutionTime: newTime,
description: newDescription, description: newDescription,
@ -193,17 +207,19 @@ export function EditableResolutionTime(props: {
<tr> <tr>
<td> <td>
Market autoresolves Market autoresolves
{isCreator && ( {isCreator &&
isEditing ? ( (isEditing ? (
<button className="btn btn-xs btn-ghost" onClick={onSave}> <button className="btn btn-xs btn-ghost" onClick={onSave}>
<CheckIcon className="inline h-4 w-4" /> <CheckIcon className="inline h-4 w-4" />
</button> </button>
):( ) : (
<button className="btn btn-xs btn-ghost" <button
onClick={() => setIsEditing(true)} > className="btn btn-xs btn-ghost"
onClick={() => setIsEditing(true)}
>
<PencilIcon className="inline h-4 w-4" /> <PencilIcon className="inline h-4 w-4" />
</button> </button>
))} ))}
</td> </td>
<td> <td>
{isEditing ? ( {isEditing ? (
@ -218,7 +234,9 @@ export function EditableResolutionTime(props: {
/> />
</div> </div>
) : ( ) : (
<div className="form-control mr-1 items-start">{formatTime(time)}</div> <div className="form-control mr-1 items-start">
{formatTime(time)}
</div>
)} )}
</td> </td>
</tr> </tr>

View File

@ -3,7 +3,12 @@ import { ReactNode } from 'react'
import { Answer } from 'common/answer' import { Answer } from 'common/answer'
import { getProbability } from 'common/calculate' import { getProbability } from 'common/calculate'
import { getValueFromBucket } from 'common/calculate-dpm' import { getValueFromBucket } from 'common/calculate-dpm'
import { BinaryContract, Contract, FreeResponseContract, resolution } from 'common/contract' import {
BinaryContract,
Contract,
FreeResponseContract,
resolution,
} from 'common/contract'
import { formatPercent } from 'common/util/format' import { formatPercent } from 'common/util/format'
import { ClientRender } from './client-render' import { ClientRender } from './client-render'
@ -35,9 +40,7 @@ export function OutcomeLabel(props: {
) )
} }
export function BinaryOutcomeLabel(props: { export function BinaryOutcomeLabel(props: { outcome: resolution }) {
outcome: resolution
}) {
const { outcome } = props const { outcome } = props
if (outcome === 'YES') return <YesLabel /> if (outcome === 'YES') return <YesLabel />

View File

@ -42,7 +42,8 @@ export function contractUrl(contract: Contract) {
} }
export function contractMetrics(contract: Contract) { export function contractMetrics(contract: Contract) {
const { createdTime, resolutionTime, isResolved, autoResolutionTime } = contract const { createdTime, resolutionTime, isResolved, autoResolutionTime } =
contract
const createdDate = dayjs(createdTime).format('MMM D') const createdDate = dayjs(createdTime).format('MMM D')
const autoResolutionDate = dayjs(autoResolutionTime).format('MMM D') const autoResolutionDate = dayjs(autoResolutionTime).format('MMM D')