Setting of auto resolve date when changing close date

This commit is contained in:
Milli 2022-06-02 01:16:31 +02:00
parent 1c91cc984a
commit 4a1c8d52b7
2 changed files with 30 additions and 18 deletions

View File

@ -24,6 +24,7 @@ import { Bet } from 'common/bet'
import NewContractBadge from '../new-contract-badge' import NewContractBadge from '../new-contract-badge'
import { CATEGORY_LIST } from 'common/categories' import { CATEGORY_LIST } from 'common/categories'
import { TagsList } from '../tags-list' import { TagsList } from '../tags-list'
import { DAY_MS } from 'common/util/time'
export function MiscDetails(props: { export function MiscDetails(props: {
contract: Contract contract: Contract
@ -209,15 +210,24 @@ export function EditableCloseDate(props: {
const newCloseTime = dayjs(closeDate).valueOf() const newCloseTime = dayjs(closeDate).valueOf()
if (newCloseTime === closeTime) setIsEditingCloseTime(false) if (newCloseTime === closeTime) setIsEditingCloseTime(false)
else if (newCloseTime > Date.now()) { else if (newCloseTime > Date.now()) {
const { description } = contract const { description, autoResolutionTime } = contract
const formattedCloseDate = dayjs(newCloseTime).format('YYYY-MM-DD h:mm a') 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, { const update : Partial<Contract> = {
closeTime: newCloseTime, closeTime: newCloseTime
description: newDescription, }
})
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) setIsEditingCloseTime(false)
} }
} }

View File

@ -81,14 +81,12 @@ export function ContractInfoDialog(props: { contract: Contract; bets: Bet[]; isC
</tr> </tr>
)} )}
{autoResolutionTime && autoResolution && ( {autoResolutionTime && !resolutionTime && (
<> <>
<EditableTime <EditableResolutionTime
title ='Market autoresolves'
time={autoResolutionTime} time={autoResolutionTime}
contract={contract} contract={contract}
isCreator={isCreator} isCreator={isCreator}
dateType='autoResolutionTime'
/> />
<tr> <tr>
<td>Auto resolution</td> <td>Auto resolution</td>
@ -165,24 +163,28 @@ const getTweetText = (contract: Contract, isCreator: boolean) => {
return `${tweetQuestion}\n\n${tweetDescription}\n\n${url}` return `${tweetQuestion}\n\n${tweetDescription}\n\n${url}`
} }
export function EditableTime(props: { export function EditableResolutionTime(props: {
title: string
time: number time: number
contract: Contract contract: Contract
isCreator: boolean isCreator: boolean
dateType: contractField
}) { }) {
const { title, time, contract, isCreator, dateType } = props const { time, contract, isCreator } = props
const [isEditing, setIsEditing] = useState(false) const [isEditing, setIsEditing] = useState(false)
const [timeString, setTimeString] = useState(time && formatTime(time)) const [timeString, setTimeString] = useState(time && formatTime(time))
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 (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, { updateContract(contract.id, {
[dateType]: newTime autoResolutionTime: newTime,
description: newDescription,
}) })
setIsEditing(false) setIsEditing(false)
} }
} }
@ -190,7 +192,7 @@ export function EditableTime(props: {
return ( return (
<tr> <tr>
<td> <td>
{title} Market autoresolves
{isCreator && ( {isCreator && (
isEditing ? ( isEditing ? (
<button className="btn btn-xs btn-ghost" onClick={onSave}> <button className="btn btn-xs btn-ghost" onClick={onSave}>
@ -216,7 +218,7 @@ export function EditableTime(props: {
/> />
</div> </div>
) : ( ) : (
<div className="form-control mr-1 items-start">{timeString}</div> <div className="form-control mr-1 items-start">{formatTime(time)}</div>
)} )}
</td> </td>
</tr> </tr>