From 727cf5df66b0c358c674504bb5651220df7ec507 Mon Sep 17 00:00:00 2001 From: Milli Date: Sun, 29 May 2022 23:35:12 +0200 Subject: [PATCH] Auto resolution date editable --- common/contract.ts | 5 +-- common/new-contract.ts | 8 ++-- firestore.rules | 2 +- functions/src/create-contract.ts | 8 ++-- web/components/contract/contract-details.tsx | 39 ++++++------------- .../contract/contract-info-dialog.tsx | 15 ++++++- web/lib/firebase/contracts.ts | 6 +-- 7 files changed, 39 insertions(+), 44 deletions(-) diff --git a/common/contract.ts b/common/contract.ts index 5dceac84..a21dccb1 100644 --- a/common/contract.ts +++ b/common/contract.ts @@ -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 diff --git a/common/new-contract.ts b/common/new-contract.ts index 89fd4fb2..ff15467c 100644 --- a/common/new-contract.ts +++ b/common/new-contract.ts @@ -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, diff --git a/firestore.rules b/firestore.rules index feba35d9..2a0f84c8 100644 --- a/firestore.rules +++ b/firestore.rules @@ -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(); } diff --git a/functions/src/create-contract.ts b/functions/src/create-contract.ts index cc9d43b2..3f924ca1 100644 --- a/functions/src/create-contract.ts +++ b/functions/src/create-contract.ts @@ -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 diff --git a/web/components/contract/contract-details.tsx b/web/components/contract/contract-details.tsx index a67c702a..36916774 100644 --- a/web/components/contract/contract-details.tsx +++ b/web/components/contract/contract-details.tsx @@ -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: { {/* {' - '}{' '} */} @@ -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: { /> ) : ( - <> - Date.now() ? 'Trading ends:' : 'Trading ended:'} - time={closeTime} - > - {isSameYear - ? dayjs(closeTime).format('MMM D') - : dayjs(closeTime).format('MMM D, YYYY')} - {isSameDay && <> ({fromNow(closeTime)})} - - {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'"} - - )} - + Date.now() ? 'Trading ends:' : 'Trading ended:'} + time={closeTime} + > + {isSameYear + ? dayjs(closeTime).format('MMM D') + : dayjs(closeTime).format('MMM D, YYYY')} + {isSameDay && <> ({fromNow(closeTime)})} + )} {isCreator && diff --git a/web/components/contract/contract-info-dialog.tsx b/web/components/contract/contract-info-dialog.tsx index 28cd91f4..f5eabf27 100644 --- a/web/components/contract/contract-info-dialog.tsx +++ b/web/components/contract/contract-info-dialog.tsx @@ -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[] }) { )} + {autoResolutionTime && autoResolution && ( + <> + + Automatic resolution + {formatTime(autoResolutionTime)} + + + Default resolution + {autoResolution} + + + )} + {resolutionTime && ( Market resolved diff --git a/web/lib/firebase/contracts.ts b/web/lib/firebase/contracts.ts index 81767dcb..2acb3fc7 100644 --- a/web/lib/firebase/contracts.ts +++ b/web/lib/firebase/contracts.ts @@ -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) {