diff --git a/web/components/contract/contract-details.tsx b/web/components/contract/contract-details.tsx index d1706520..37fafa55 100644 --- a/web/components/contract/contract-details.tsx +++ b/web/components/contract/contract-details.tsx @@ -24,6 +24,7 @@ import { Bet } from 'common/bet' import NewContractBadge from '../new-contract-badge' import { CATEGORY_LIST } from 'common/categories' import { TagsList } from '../tags-list' +import { DAY_MS } from 'common/util/time' export function MiscDetails(props: { contract: Contract @@ -209,15 +210,24 @@ export function EditableCloseDate(props: { const newCloseTime = dayjs(closeDate).valueOf() if (newCloseTime === closeTime) setIsEditingCloseTime(false) else if (newCloseTime > Date.now()) { - const { description } = contract + const { description, autoResolutionTime } = contract const formattedCloseDate = dayjs(newCloseTime).format('YYYY-MM-DD h:mm a') - const newDescription = `${description}\n\nClose date updated to ${formattedCloseDate}` + const newAutoResolutionTime = newCloseTime + 7 * DAY_MS + let newDescription = `${description}\n\nClose date updated to ${formattedCloseDate}` - updateContract(contract.id, { - closeTime: newCloseTime, - description: newDescription, - }) + const update : Partial = { + closeTime: newCloseTime + } + if (newAutoResolutionTime >= autoResolutionTime) { + update.autoResolutionTime = newAutoResolutionTime + const formattedNewAutoResolutionTime = dayjs(newAutoResolutionTime).format('YYYY-MM-DD h:mm a') + newDescription = newDescription.concat(`\nAuto resolution date updated to ${formattedNewAutoResolutionTime}`) + } + + update.description = newDescription + + updateContract(contract.id, update) setIsEditingCloseTime(false) } } diff --git a/web/components/contract/contract-info-dialog.tsx b/web/components/contract/contract-info-dialog.tsx index 4cec9ab5..ae7cccc2 100644 --- a/web/components/contract/contract-info-dialog.tsx +++ b/web/components/contract/contract-info-dialog.tsx @@ -81,14 +81,12 @@ export function ContractInfoDialog(props: { contract: Contract; bets: Bet[]; isC )} - {autoResolutionTime && autoResolution && ( + {autoResolutionTime && !resolutionTime && ( <> - Auto resolution @@ -165,24 +163,28 @@ const getTweetText = (contract: Contract, isCreator: boolean) => { return `${tweetQuestion}\n\n${tweetDescription}\n\n${url}` } -export function EditableTime(props: { - title: string +export function EditableResolutionTime(props: { time: number contract: Contract isCreator: boolean - dateType: contractField }) { - const { title, time, contract, isCreator, dateType } = props + const { time, contract, isCreator } = props const [isEditing, setIsEditing] = useState(false) const [timeString, setTimeString] = useState(time && formatTime(time)) + const onSave = () => { const newTime = dayjs(timeString).valueOf() if (newTime === time) setIsEditing(false) - else if (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 newDescription = `${contract.description}\n\nAuto resolution date updated to ${formattedTime}` + updateContract(contract.id, { - [dateType]: newTime + autoResolutionTime: newTime, + description: newDescription, }) + setIsEditing(false) } } @@ -190,7 +192,7 @@ export function EditableTime(props: { return ( - {title} + Market autoresolves {isCreator && ( isEditing ? (