Auto resolution date editable

This commit is contained in:
Milli 2022-05-29 23:35:12 +02:00
parent 9c6c082de7
commit 727cf5df66
7 changed files with 39 additions and 44 deletions

View File

@ -28,9 +28,8 @@ export type FullContract<
isResolved: boolean
resolutionTime?: number // When the market is resolved
resolution?: string
automaticResolution: resolution
automaticResolutionTime?: number
autoResolution: resolution
autoResolutionTime: number // When the market will be resolved automatically
closeEmailsSent?: number
volume: number

View File

@ -24,8 +24,8 @@ export function getNewContract(
ante: number,
closeTime: number,
extraTags: string[],
automaticResolution: resolution,
automaticResolutionTime: number,
autoResolution: resolution,
autoResolutionTime: number,
// used for numeric markets
bucketCount: number,
@ -62,8 +62,8 @@ export function getNewContract(
isResolved: false,
createdTime: Date.now(),
closeTime,
automaticResolution,
automaticResolutionTime,
autoResolution,
autoResolutionTime,
volume: 0,
volume24Hours: 0,

View File

@ -45,7 +45,7 @@ service cloud.firestore {
match /contracts/{contractId} {
allow read;
allow update: if request.resource.data.diff(resource.data).affectedKeys()
.hasOnly(['description', 'closeTime', 'tags', 'lowercaseTags']);
.hasOnly(['description', 'closeTime', 'tags', 'lowercaseTags', 'autoResolutionTime']);
allow update: if isAdmin();
}

View File

@ -67,8 +67,8 @@ export const createContract = newEndpoint(['POST'], async (req, [user, _]) => {
;({ initialProb } = validate(binarySchema, req.body)) // leading ; intentional: see above
}
const automaticResolution = outcomeType == 'BINARY' ? 'MKT' : 'CANCEL'
const automaticResolutionTime = closeTime.setDate(closeTime.getDate() + 7)
const autoResolution = outcomeType == 'BINARY' ? 'MKT' : 'CANCEL'
const autoResolutionTime = closeTime.setDate(closeTime.getDate() + 7)
// Uses utc time on server:
const today = new Date()
@ -109,8 +109,8 @@ export const createContract = newEndpoint(['POST'], async (req, [user, _]) => {
ante,
closeTime.getTime(),
tags ?? [],
automaticResolution,
automaticResolutionTime,
autoResolution,
autoResolutionTime,
NUMERIC_BUCKET_COUNT,
min ?? 0,
max ?? 0

View File

@ -109,7 +109,7 @@ export function ContractDetails(props: {
disabled?: boolean
}) {
const { contract, bets, isCreator, disabled } = props
const { closeTime, automaticResolutionTime, creatorName, creatorUsername } = contract
const { closeTime, autoResolutionTime, creatorName, creatorUsername } = contract
const { volumeLabel, resolvedDate } = contractMetrics(contract)
return (
@ -157,7 +157,6 @@ export function ContractDetails(props: {
{/* {' - '}{' '} */}
<EditableCloseDate
closeTime={closeTime}
resolveTime={automaticResolutionTime}
contract={contract}
isCreator={isCreator ?? false}
/>
@ -197,11 +196,10 @@ export function contractTextDetails(contract: Contract) {
function EditableCloseDate(props: {
closeTime: number
resolveTime: number | undefined
contract: Contract
isCreator: boolean
}) {
const { closeTime, resolveTime, contract, isCreator } = props
const { closeTime, contract, isCreator } = props
const [isEditingCloseTime, setIsEditingCloseTime] = useState(false)
const [closeDate, setCloseDate] = useState(
@ -242,30 +240,15 @@ function EditableCloseDate(props: {
/>
</div>
) : (
<>
<DateTimeTooltip
text={closeTime > Date.now() ? 'Trading ends:' : 'Trading ended:'}
time={closeTime}
>
{isSameYear
? dayjs(closeTime).format('MMM D')
: dayjs(closeTime).format('MMM D, YYYY')}
{isSameDay && <> ({fromNow(closeTime)})</>}
</DateTimeTooltip>
{resolveTime && (
<DateTimeTooltip
text={resolveTime > Date.now() ? 'Market resolves as \'MKT\':' : ''}
time={resolveTime}
>
{"/ "}
{isSameYear
? dayjs(resolveTime).format('MMM D')
: dayjs(resolveTime).format('MMM D, YYYY')}
{isSameDay && <> ({fromNow(resolveTime)})</>}
{": 'MKT'"}
</DateTimeTooltip>
)}
</>
<DateTimeTooltip
text={closeTime > Date.now() ? 'Trading ends:' : 'Trading ended:'}
time={closeTime}
>
{isSameYear
? dayjs(closeTime).format('MMM D')
: dayjs(closeTime).format('MMM D, YYYY')}
{isSameDay && <> ({fromNow(closeTime)})</>}
</DateTimeTooltip>
)}
{isCreator &&

View File

@ -30,7 +30,7 @@ export function ContractInfoDialog(props: { contract: Contract; bets: Bet[] }) {
const formatTime = (dt: number) => dayjs(dt).format('MMM DD, YYYY hh:mm a z')
const { createdTime, closeTime, resolutionTime } = contract
const { createdTime, closeTime, resolutionTime, autoResolutionTime, autoResolution } = contract
const tradersCount = uniqBy(bets, 'userId').length
return (
@ -81,6 +81,19 @@ export function ContractInfoDialog(props: { contract: Contract; bets: Bet[] }) {
</tr>
)}
{autoResolutionTime && autoResolution && (
<>
<tr>
<td>Automatic resolution</td>
<td>{formatTime(autoResolutionTime)}</td>
</tr>
<tr>
<td>Default resolution</td>
<td>{autoResolution}</td>
</tr>
</>
)}
{resolutionTime && (
<tr>
<td>Market resolved</td>

View File

@ -42,10 +42,10 @@ export function contractUrl(contract: Contract) {
}
export function contractMetrics(contract: Contract) {
const { createdTime, resolutionTime, isResolved, automaticResolutionTime } = contract
const { createdTime, resolutionTime, isResolved, autoResolutionTime } = contract
const createdDate = dayjs(createdTime).format('MMM D')
const automaticResolutionDate = dayjs(automaticResolutionTime).format('MMM D')
const autoResolutionDate = dayjs(autoResolutionTime).format('MMM D')
const resolvedDate = isResolved
? dayjs(resolutionTime).format('MMM D')
@ -53,7 +53,7 @@ export function contractMetrics(contract: Contract) {
const volumeLabel = `${formatMoney(contract.volume)} bet`
return { volumeLabel, createdDate, automaticResolutionDate, resolvedDate }
return { volumeLabel, createdDate, autoResolutionDate, resolvedDate }
}
export function contractPool(contract: Contract) {