use tags to store market category

This commit is contained in:
mantikoros 2022-05-03 11:21:25 -04:00
parent 1d600037db
commit b5536a2d35
6 changed files with 29 additions and 66 deletions

View File

@ -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 = { export const CATEGORIES = {
politics: 'Politics', politics: 'Politics',
personal: 'Personal', personal: 'Personal',
@ -33,11 +15,12 @@ export const CATEGORIES = {
crypto: 'Crypto', crypto: 'Crypto',
health: 'Health', health: 'Health',
entertainment: 'Entertainment', entertainment: 'Entertainment',
charity: 'Charities / Non-profits',
other: 'Other', other: 'Other',
} } as { [category: string]: string }
export const TO_CATEGORY = Object.fromEntries( export const TO_CATEGORY = Object.fromEntries(
Object.entries(CATEGORIES).map(([k, v]) => [v, k]) Object.entries(CATEGORIES).map(([k, v]) => [v, k])
) )
export const CATEGORY_LIST = Object.keys(CATEGORIES) as category[] export const CATEGORY_LIST = Object.keys(CATEGORIES)

View File

@ -1,5 +1,4 @@
import { Answer } from './answer' import { Answer } from './answer'
import { category } from './categories'
import { Fees } from './fees' import { Fees } from './fees'
export type FullContract< export type FullContract<
@ -16,7 +15,6 @@ export type FullContract<
question: string question: string
description: string // More info about what the contract is about description: string // More info about what the contract is about
category: category
tags: string[] tags: string[]
lowercaseTags: string[] lowercaseTags: string[]
visibility: 'public' | 'unlisted' visibility: 'public' | 'unlisted'

View File

@ -11,7 +11,6 @@ import { User } from './user'
import { parseTags } from './util/parse' import { parseTags } from './util/parse'
import { removeUndefinedProps } from './util/object' import { removeUndefinedProps } from './util/object'
import { calcDpmInitialPool } from './calculate-dpm' import { calcDpmInitialPool } from './calculate-dpm'
import { category } from './categories'
export function getNewContract( export function getNewContract(
id: string, id: string,
@ -23,7 +22,6 @@ export function getNewContract(
initialProb: number, initialProb: number,
ante: number, ante: number,
closeTime: number, closeTime: number,
category: category,
extraTags: string[] extraTags: string[]
) { ) {
const tags = parseTags( const tags = parseTags(
@ -50,7 +48,6 @@ export function getNewContract(
question: question.trim(), question: question.trim(),
description: description.trim(), description: description.trim(),
category,
tags, tags,
lowercaseTags, lowercaseTags,
visibility: 'public', visibility: 'public',

View File

@ -1,6 +1,7 @@
import * as functions from 'firebase-functions' import * as functions from 'firebase-functions'
import * as admin from 'firebase-admin' import * as admin from 'firebase-admin'
import * as _ from 'lodash' import * as _ from 'lodash'
import { chargeUser, getUser } from './utils' import { chargeUser, getUser } from './utils'
import { import {
Binary, Binary,
@ -26,7 +27,6 @@ import {
MINIMUM_ANTE, MINIMUM_ANTE,
} from '../../common/antes' } from '../../common/antes'
import { getNoneAnswer } from '../../common/answer' import { getNoneAnswer } from '../../common/answer'
import { category, CATEGORY_LIST } from '../../common/categories'
export const createContract = functions export const createContract = functions
.runWith({ minInstances: 1 }) .runWith({ minInstances: 1 })
@ -36,7 +36,6 @@ export const createContract = functions
question: string question: string
outcomeType: outcomeType outcomeType: outcomeType
description: string description: string
category: category
initialProb: number initialProb: number
ante: number ante: number
closeTime: number closeTime: number
@ -50,8 +49,7 @@ export const createContract = functions
const creator = await getUser(userId) const creator = await getUser(userId)
if (!creator) return { status: 'error', message: 'User not found' } if (!creator) return { status: 'error', message: 'User not found' }
let { question, description, initialProb, closeTime, tags, category } = let { question, description, initialProb, closeTime, tags } = data
data
if (!question || typeof question != 'string') if (!question || typeof question != 'string')
return { status: 'error', message: 'Missing or invalid question field' } return { status: 'error', message: 'Missing or invalid question field' }
@ -61,10 +59,6 @@ export const createContract = functions
return { status: 'error', message: 'Invalid description field' } return { status: 'error', message: 'Invalid description field' }
description = description.slice(0, MAX_DESCRIPTION_LENGTH) 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)) if (tags !== undefined && !_.isArray(tags))
return { status: 'error', message: 'Invalid tags field' } return { status: 'error', message: 'Invalid tags field' }
tags = tags?.map((tag) => tag.toString().slice(0, MAX_TAG_LENGTH)) tags = tags?.map((tag) => tag.toString().slice(0, MAX_TAG_LENGTH))
@ -121,7 +115,6 @@ export const createContract = functions
initialProb, initialProb,
ante, ante,
closeTime, closeTime,
category,
tags ?? [] tags ?? []
) )

View File

@ -3,9 +3,8 @@ import clsx from 'clsx'
import dayjs from 'dayjs' import dayjs from 'dayjs'
import _ from 'lodash' import _ from 'lodash'
import { useState } from 'react' 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 { Contract } from '../../../common/contract'
import { formatMoney } from '../../../common/util/format' import { formatMoney } from '../../../common/util/format'
import { 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 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 const tradersCount = _.uniqBy(bets, 'userId').length
return ( return (
@ -65,13 +64,6 @@ export function ContractInfoDialog(props: { contract: Contract; bets: Bet[] }) {
<div>Stats</div> <div>Stats</div>
<table className="table-compact table-zebra table w-full text-gray-500"> <table className="table-compact table-zebra table w-full text-gray-500">
<tbody> <tbody>
{category && (
<tr>
<td>Category</td>
<td>{CATEGORIES[category]}</td>
</tr>
)}
<tr> <tr>
<td>Market created</td> <td>Market created</td>
<td>{formatTime(createdTime)}</td> <td>{formatTime(createdTime)}</td>

View File

@ -13,18 +13,12 @@ import { InfoTooltip } from '../components/info-tooltip'
import { Page } from '../components/page' import { Page } from '../components/page'
import { Title } from '../components/title' import { Title } from '../components/title'
import { ProbabilitySelector } from '../components/probability-selector' 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 { Row } from '../components/layout/row'
import { MAX_DESCRIPTION_LENGTH, outcomeType } from '../../common/contract' import { MAX_DESCRIPTION_LENGTH, outcomeType } from '../../common/contract'
import { formatMoney } from '../../common/util/format' import { formatMoney } from '../../common/util/format'
import { useHasCreatedContractToday } from '../hooks/use-has-created-contract-today' import { useHasCreatedContractToday } from '../hooks/use-has-created-contract-today'
import { import { CATEGORIES, CATEGORY_LIST, TO_CATEGORY } from '../../common/categories'
CATEGORIES, import { removeUndefinedProps } from '../../common/util/object'
category,
CATEGORY_LIST,
TO_CATEGORY,
} from '../../common/categories'
export default function Create() { export default function Create() {
const [question, setQuestion] = useState('') const [question, setQuestion] = useState('')
@ -73,9 +67,10 @@ export function NewContract(props: { question: string; tag?: string }) {
const [outcomeType, setOutcomeType] = useState<outcomeType>('BINARY') const [outcomeType, setOutcomeType] = useState<outcomeType>('BINARY')
const [initialProb, setInitialProb] = useState(50) const [initialProb, setInitialProb] = useState(50)
const [description, setDescription] = useState('') const [description, setDescription] = useState('')
const [category, setCategory] = useState<string>(CATEGORY_LIST[0])
const [tagText, setTagText] = useState<string>(tag ?? '') const [category, setCategory] = useState<string>('')
const tags = parseWordsAsTags(tagText) // const [tagText, setTagText] = useState<string>(tag ?? '')
// const tags = parseWordsAsTags(tagText)
const [ante, setAnte] = useState(FIXED_ANTE) const [ante, setAnte] = useState(FIXED_ANTE)
@ -117,16 +112,17 @@ export function NewContract(props: { question: string; tag?: string }) {
setIsSubmitting(true) setIsSubmitting(true)
const result: any = await createContract({ const result: any = await createContract(
question, removeUndefinedProps({
outcomeType, question,
description, outcomeType,
initialProb, description,
ante, initialProb,
closeTime, ante,
category, closeTime,
tags, tags: category ? [category] : undefined,
}).then((r) => r.data || {}) })
).then((r) => r.data || {})
if (result.status !== 'success') { if (result.status !== 'success') {
console.log('error creating contract', result) console.log('error creating contract', result)
@ -217,9 +213,13 @@ export function NewContract(props: { question: string; tag?: string }) {
<select <select
className="select select-bordered w-full max-w-xs" className="select select-bordered w-full max-w-xs"
onChange={(e) => 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) => ( {CATEGORY_LIST.map((cat) => (
<option selected={category === cat} value={CATEGORIES[cat]}> <option selected={category === cat} value={CATEGORIES[cat]}>
{CATEGORIES[cat]} {CATEGORIES[cat]}