use tags to store market category
This commit is contained in:
parent
1d600037db
commit
b5536a2d35
|
@ -1,21 +1,3 @@
|
|||
export type category =
|
||||
| 'sports'
|
||||
| 'politics'
|
||||
| 'technology'
|
||||
| 'science'
|
||||
| 'manifold'
|
||||
| 'geopolitics'
|
||||
| 'personal'
|
||||
| 'fun'
|
||||
| 'business'
|
||||
| 'finance'
|
||||
| 'society'
|
||||
| 'entertainment'
|
||||
| 'gaming'
|
||||
| 'crypto'
|
||||
| 'health'
|
||||
| 'other'
|
||||
|
||||
export const CATEGORIES = {
|
||||
politics: 'Politics',
|
||||
personal: 'Personal',
|
||||
|
@ -33,11 +15,12 @@ export const CATEGORIES = {
|
|||
crypto: 'Crypto',
|
||||
health: 'Health',
|
||||
entertainment: 'Entertainment',
|
||||
charity: 'Charities / Non-profits',
|
||||
other: 'Other',
|
||||
}
|
||||
} as { [category: string]: string }
|
||||
|
||||
export const TO_CATEGORY = Object.fromEntries(
|
||||
Object.entries(CATEGORIES).map(([k, v]) => [v, k])
|
||||
)
|
||||
|
||||
export const CATEGORY_LIST = Object.keys(CATEGORIES) as category[]
|
||||
export const CATEGORY_LIST = Object.keys(CATEGORIES)
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import { Answer } from './answer'
|
||||
import { category } from './categories'
|
||||
import { Fees } from './fees'
|
||||
|
||||
export type FullContract<
|
||||
|
@ -16,7 +15,6 @@ export type FullContract<
|
|||
|
||||
question: string
|
||||
description: string // More info about what the contract is about
|
||||
category: category
|
||||
tags: string[]
|
||||
lowercaseTags: string[]
|
||||
visibility: 'public' | 'unlisted'
|
||||
|
|
|
@ -11,7 +11,6 @@ import { User } from './user'
|
|||
import { parseTags } from './util/parse'
|
||||
import { removeUndefinedProps } from './util/object'
|
||||
import { calcDpmInitialPool } from './calculate-dpm'
|
||||
import { category } from './categories'
|
||||
|
||||
export function getNewContract(
|
||||
id: string,
|
||||
|
@ -23,7 +22,6 @@ export function getNewContract(
|
|||
initialProb: number,
|
||||
ante: number,
|
||||
closeTime: number,
|
||||
category: category,
|
||||
extraTags: string[]
|
||||
) {
|
||||
const tags = parseTags(
|
||||
|
@ -50,7 +48,6 @@ export function getNewContract(
|
|||
|
||||
question: question.trim(),
|
||||
description: description.trim(),
|
||||
category,
|
||||
tags,
|
||||
lowercaseTags,
|
||||
visibility: 'public',
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import * as functions from 'firebase-functions'
|
||||
import * as admin from 'firebase-admin'
|
||||
import * as _ from 'lodash'
|
||||
|
||||
import { chargeUser, getUser } from './utils'
|
||||
import {
|
||||
Binary,
|
||||
|
@ -26,7 +27,6 @@ import {
|
|||
MINIMUM_ANTE,
|
||||
} from '../../common/antes'
|
||||
import { getNoneAnswer } from '../../common/answer'
|
||||
import { category, CATEGORY_LIST } from '../../common/categories'
|
||||
|
||||
export const createContract = functions
|
||||
.runWith({ minInstances: 1 })
|
||||
|
@ -36,7 +36,6 @@ export const createContract = functions
|
|||
question: string
|
||||
outcomeType: outcomeType
|
||||
description: string
|
||||
category: category
|
||||
initialProb: number
|
||||
ante: number
|
||||
closeTime: number
|
||||
|
@ -50,8 +49,7 @@ export const createContract = functions
|
|||
const creator = await getUser(userId)
|
||||
if (!creator) return { status: 'error', message: 'User not found' }
|
||||
|
||||
let { question, description, initialProb, closeTime, tags, category } =
|
||||
data
|
||||
let { question, description, initialProb, closeTime, tags } = data
|
||||
|
||||
if (!question || typeof question != 'string')
|
||||
return { status: 'error', message: 'Missing or invalid question field' }
|
||||
|
@ -61,10 +59,6 @@ export const createContract = functions
|
|||
return { status: 'error', message: 'Invalid description field' }
|
||||
description = description.slice(0, MAX_DESCRIPTION_LENGTH)
|
||||
|
||||
if (category !== undefined && !CATEGORY_LIST.includes(category))
|
||||
return { status: 'error', message: 'Invalid category' }
|
||||
|
||||
// deprecated:
|
||||
if (tags !== undefined && !_.isArray(tags))
|
||||
return { status: 'error', message: 'Invalid tags field' }
|
||||
tags = tags?.map((tag) => tag.toString().slice(0, MAX_TAG_LENGTH))
|
||||
|
@ -121,7 +115,6 @@ export const createContract = functions
|
|||
initialProb,
|
||||
ante,
|
||||
closeTime,
|
||||
category,
|
||||
tags ?? []
|
||||
)
|
||||
|
||||
|
|
|
@ -3,9 +3,8 @@ import clsx from 'clsx'
|
|||
import dayjs from 'dayjs'
|
||||
import _ from 'lodash'
|
||||
import { useState } from 'react'
|
||||
import { Bet } from '../../../common/bet'
|
||||
import { CATEGORIES } from '../../../common/categories'
|
||||
|
||||
import { Bet } from '../../../common/bet'
|
||||
import { Contract } from '../../../common/contract'
|
||||
import { formatMoney } from '../../../common/util/format'
|
||||
import {
|
||||
|
@ -29,7 +28,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, category } = contract
|
||||
const { createdTime, closeTime, resolutionTime } = contract
|
||||
const tradersCount = _.uniqBy(bets, 'userId').length
|
||||
|
||||
return (
|
||||
|
@ -65,13 +64,6 @@ export function ContractInfoDialog(props: { contract: Contract; bets: Bet[] }) {
|
|||
<div>Stats</div>
|
||||
<table className="table-compact table-zebra table w-full text-gray-500">
|
||||
<tbody>
|
||||
{category && (
|
||||
<tr>
|
||||
<td>Category</td>
|
||||
<td>{CATEGORIES[category]}</td>
|
||||
</tr>
|
||||
)}
|
||||
|
||||
<tr>
|
||||
<td>Market created</td>
|
||||
<td>{formatTime(createdTime)}</td>
|
||||
|
|
|
@ -13,18 +13,12 @@ import { InfoTooltip } from '../components/info-tooltip'
|
|||
import { Page } from '../components/page'
|
||||
import { Title } from '../components/title'
|
||||
import { ProbabilitySelector } from '../components/probability-selector'
|
||||
import { parseWordsAsTags } from '../../common/util/parse'
|
||||
import { TagsList } from '../components/tags-list'
|
||||
import { Row } from '../components/layout/row'
|
||||
import { MAX_DESCRIPTION_LENGTH, outcomeType } from '../../common/contract'
|
||||
import { formatMoney } from '../../common/util/format'
|
||||
import { useHasCreatedContractToday } from '../hooks/use-has-created-contract-today'
|
||||
import {
|
||||
CATEGORIES,
|
||||
category,
|
||||
CATEGORY_LIST,
|
||||
TO_CATEGORY,
|
||||
} from '../../common/categories'
|
||||
import { CATEGORIES, CATEGORY_LIST, TO_CATEGORY } from '../../common/categories'
|
||||
import { removeUndefinedProps } from '../../common/util/object'
|
||||
|
||||
export default function Create() {
|
||||
const [question, setQuestion] = useState('')
|
||||
|
@ -73,9 +67,10 @@ export function NewContract(props: { question: string; tag?: string }) {
|
|||
const [outcomeType, setOutcomeType] = useState<outcomeType>('BINARY')
|
||||
const [initialProb, setInitialProb] = useState(50)
|
||||
const [description, setDescription] = useState('')
|
||||
const [category, setCategory] = useState<string>(CATEGORY_LIST[0])
|
||||
const [tagText, setTagText] = useState<string>(tag ?? '')
|
||||
const tags = parseWordsAsTags(tagText)
|
||||
|
||||
const [category, setCategory] = useState<string>('')
|
||||
// const [tagText, setTagText] = useState<string>(tag ?? '')
|
||||
// const tags = parseWordsAsTags(tagText)
|
||||
|
||||
const [ante, setAnte] = useState(FIXED_ANTE)
|
||||
|
||||
|
@ -117,16 +112,17 @@ export function NewContract(props: { question: string; tag?: string }) {
|
|||
|
||||
setIsSubmitting(true)
|
||||
|
||||
const result: any = await createContract({
|
||||
const result: any = await createContract(
|
||||
removeUndefinedProps({
|
||||
question,
|
||||
outcomeType,
|
||||
description,
|
||||
initialProb,
|
||||
ante,
|
||||
closeTime,
|
||||
category,
|
||||
tags,
|
||||
}).then((r) => r.data || {})
|
||||
tags: category ? [category] : undefined,
|
||||
})
|
||||
).then((r) => r.data || {})
|
||||
|
||||
if (result.status !== 'success') {
|
||||
console.log('error creating contract', result)
|
||||
|
@ -217,9 +213,13 @@ export function NewContract(props: { question: string; tag?: string }) {
|
|||
<select
|
||||
className="select select-bordered w-full max-w-xs"
|
||||
onChange={(e) =>
|
||||
setCategory(TO_CATEGORY[e.currentTarget.value] as category)
|
||||
setCategory(
|
||||
e.currentTarget.value || TO_CATEGORY[e.currentTarget.value]
|
||||
)
|
||||
}
|
||||
>
|
||||
<option selected={category === ''}></option>
|
||||
|
||||
{CATEGORY_LIST.map((cat) => (
|
||||
<option selected={category === cat} value={CATEGORIES[cat]}>
|
||||
{CATEGORIES[cat]}
|
||||
|
|
Loading…
Reference in New Issue
Block a user