Add lowercaseTags field to contracts. ante / closeTime non-optional in new contract code

This commit is contained in:
jahooma 2022-01-24 16:33:02 -06:00
parent 7534847e8d
commit 705d5cada7
5 changed files with 15 additions and 8 deletions

View File

@ -10,6 +10,7 @@ export type Contract = {
question: string question: string
description: string // More info about what the contract is about description: string // More info about what the contract is about
tags: string[] tags: string[]
lowercaseTags: string[]
outcomeType: 'BINARY' // | 'MULTI' | 'interval' | 'date' outcomeType: 'BINARY' // | 'MULTI' | 'interval' | 'date'
visibility: 'public' | 'unlisted' visibility: 'public' | 'unlisted'

View File

@ -11,12 +11,15 @@ export function getNewContract(
question: string, question: string,
description: string, description: string,
initialProb: number, initialProb: number,
ante?: number, ante: number,
closeTime?: number closeTime: number
) { ) {
const { sharesYes, sharesNo, poolYes, poolNo, phantomYes, phantomNo } = const { sharesYes, sharesNo, poolYes, poolNo, phantomYes, phantomNo } =
calcStartPool(initialProb, ante) calcStartPool(initialProb, ante)
const tags = parseTags(`${question} ${description}`)
const lowercaseTags = tags.map((tag) => tag.toLowerCase())
const contract: Contract = { const contract: Contract = {
id, id,
slug, slug,
@ -29,7 +32,8 @@ export function getNewContract(
question: question.trim(), question: question.trim(),
description: description.trim(), description: description.trim(),
tags: parseTags(`${question} ${description}`), tags,
lowercaseTags,
visibility: 'public', visibility: 'public',
mechanism: 'dpm-2', mechanism: 'dpm-2',

View File

@ -16,8 +16,8 @@ export const createContract = functions
question: string question: string
description: string description: string
initialProb: number initialProb: number
ante?: number ante: number
closeTime?: number closeTime: number
}, },
context context
) => { ) => {

View File

@ -30,6 +30,7 @@ async function updateContractTags() {
...parseTags(contract.question + contract.description), ...parseTags(contract.question + contract.description),
...(contract.tags ?? []), ...(contract.tags ?? []),
]) ])
const lowercaseTags = tags.map((tag) => tag.toLowerCase())
console.log( console.log(
'Updating tags', 'Updating tags',
@ -42,6 +43,7 @@ async function updateContractTags() {
await contractRef.update({ await contractRef.update({
tags, tags,
lowercaseTags,
} as Partial<Contract>) } as Partial<Contract>)
} }
} }

View File

@ -77,7 +77,7 @@ export function NewContract(props: { question: string }) {
const [isSubmitting, setIsSubmitting] = useState(false) const [isSubmitting, setIsSubmitting] = useState(false)
const closeTime = dateToMillis(closeDate) || undefined const closeTime = dateToMillis(closeDate)
const balance = creator?.balance || 0 const balance = creator?.balance || 0
@ -88,7 +88,7 @@ export function NewContract(props: { question: string }) {
ante !== undefined && ante !== undefined &&
ante >= MINIMUM_ANTE && ante >= MINIMUM_ANTE &&
ante <= balance && ante <= balance &&
// If set, closeTime must be in the future // closeTime must be in the future
closeTime && closeTime &&
closeTime > Date.now() closeTime > Date.now()
@ -103,7 +103,7 @@ export function NewContract(props: { question: string }) {
description, description,
initialProb, initialProb,
ante, ante,
closeTime: closeTime || undefined, closeTime,
}).then((r) => r.data || {}) }).then((r) => r.data || {})
if (result.status !== 'success') { if (result.status !== 'success') {