From b5536a2d3554349a09089321f18d2537e9e81902 Mon Sep 17 00:00:00 2001 From: mantikoros Date: Tue, 3 May 2022 11:21:25 -0400 Subject: [PATCH] use tags to store market category --- common/categories.ts | 23 ++-------- common/contract.ts | 2 - common/new-contract.ts | 3 -- functions/src/create-contract.ts | 11 +---- .../contract/contract-info-dialog.tsx | 12 +---- web/pages/create.tsx | 44 +++++++++---------- 6 files changed, 29 insertions(+), 66 deletions(-) diff --git a/common/categories.ts b/common/categories.ts index 2991135c..05fbf2b9 100644 --- a/common/categories.ts +++ b/common/categories.ts @@ -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) diff --git a/common/contract.ts b/common/contract.ts index 5d2736e6..82a330b5 100644 --- a/common/contract.ts +++ b/common/contract.ts @@ -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' diff --git a/common/new-contract.ts b/common/new-contract.ts index 9058d019..b86ebb71 100644 --- a/common/new-contract.ts +++ b/common/new-contract.ts @@ -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', diff --git a/functions/src/create-contract.ts b/functions/src/create-contract.ts index 931a5460..88970904 100644 --- a/functions/src/create-contract.ts +++ b/functions/src/create-contract.ts @@ -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 ?? [] ) diff --git a/web/components/contract/contract-info-dialog.tsx b/web/components/contract/contract-info-dialog.tsx index a3cc16c9..f0ed3311 100644 --- a/web/components/contract/contract-info-dialog.tsx +++ b/web/components/contract/contract-info-dialog.tsx @@ -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[] }) {
Stats
- {category && ( - - - - - )} - diff --git a/web/pages/create.tsx b/web/pages/create.tsx index 941fc0ee..c0d2cdac 100644 --- a/web/pages/create.tsx +++ b/web/pages/create.tsx @@ -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('BINARY') const [initialProb, setInitialProb] = useState(50) const [description, setDescription] = useState('') - const [category, setCategory] = useState(CATEGORY_LIST[0]) - const [tagText, setTagText] = useState(tag ?? '') - const tags = parseWordsAsTags(tagText) + + const [category, setCategory] = useState('') + // const [tagText, setTagText] = useState(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({ - question, - outcomeType, - description, - initialProb, - ante, - closeTime, - category, - tags, - }).then((r) => r.data || {}) + const result: any = await createContract( + removeUndefinedProps({ + question, + outcomeType, + description, + initialProb, + ante, + closeTime, + 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 }) {
Category{CATEGORIES[category]}
Market created {formatTime(createdTime)}