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 { 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<Contract> = {
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)
}
}

View File

@ -81,14 +81,12 @@ export function ContractInfoDialog(props: { contract: Contract; bets: Bet[]; isC
</tr>
)}
{autoResolutionTime && autoResolution && (
{autoResolutionTime && !resolutionTime && (
<>
<EditableTime
title ='Market autoresolves'
<EditableResolutionTime
time={autoResolutionTime}
contract={contract}
isCreator={isCreator}
dateType='autoResolutionTime'
/>
<tr>
<td>Auto resolution</td>
@ -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 (
<tr>
<td>
{title}
Market autoresolves
{isCreator && (
isEditing ? (
<button className="btn btn-xs btn-ghost" onClick={onSave}>
@ -216,7 +218,7 @@ export function EditableTime(props: {
/>
</div>
) : (
<div className="form-control mr-1 items-start">{timeString}</div>
<div className="form-control mr-1 items-start">{formatTime(time)}</div>
)}
</td>
</tr>