Api fixes (#704)

* Add min, max, isLogScale to numeric market API return

* Add lastUpdatedTime to market API

* Return a string description in market API

* Accept string descriptions in market POST api

* install prettier eslint config. fix import

* fix another import
This commit is contained in:
Sinclair Chen 2022-08-16 15:01:03 -07:00 committed by GitHub
parent 8c2f3c56d3
commit 59565416b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 46 additions and 3 deletions

View File

@ -135,7 +135,8 @@ Requires no authorization.
// Market attributes. All times are in milliseconds since epoch
closeTime?: number // Min of creator's chosen date, and resolutionTime
question: string
description: string
description: JSONContent // Rich text content. See https://tiptap.dev/guide/output#option-1-json
textDescription: string // string description without formatting, images, or embeds
// A list of tags on each market. Any user can add tags to any market.
// This list also includes the predefined categories shown as filters on the home page.
@ -162,6 +163,8 @@ Requires no authorization.
resolutionTime?: number
resolution?: string
resolutionProbability?: number // Used for BINARY markets resolved to MKT
lastUpdatedTime?: number
}
```
@ -541,6 +544,7 @@ Parameters:
- `outcomeType`: Required. One of `BINARY`, `FREE_RESPONSE`, or `NUMERIC`.
- `question`: Required. The headline question for the market.
- `description`: Required. A long description describing the rules for the market.
- Note: string descriptions do **not** turn into links, mentions, formatted text. Instead, rich text descriptions must be in [TipTap json](https://tiptap.dev/guide/output#option-1-json).
- `closeTime`: Required. The time at which the market will close, represented as milliseconds since the epoch.
- `tags`: Optional. An array of string tags for the market.

View File

@ -59,7 +59,7 @@ const descScehma: z.ZodType<JSONContent> = z.lazy(() =>
const bodySchema = z.object({
question: z.string().min(1).max(MAX_QUESTION_LENGTH),
description: descScehma.optional(),
description: descScehma.or(z.string()).optional(),
tags: z.array(z.string().min(1).max(MAX_TAG_LENGTH)).optional(),
closeTime: zTimestamp().refine(
(date) => date.getTime() > new Date().getTime(),
@ -165,13 +165,27 @@ export const createmarket = newEndpoint({}, async (req, auth) => {
ante || 0
)
// convert string descriptions into JSONContent
const newDescription =
typeof description === 'string'
? {
type: 'doc',
content: [
{
type: 'paragraph',
content: [{ type: 'text', text: description }],
},
],
}
: description ?? {}
const contract = getNewContract(
contractRef.id,
slug,
user,
question,
outcomeType,
description ?? {},
newDescription,
initialProb ?? 0,
ante,
closeTime.getTime(),

View File

@ -5,6 +5,7 @@ module.exports = {
'plugin:@typescript-eslint/recommended',
'plugin:react-hooks/recommended',
'plugin:@next/next/recommended',
'prettier',
],
rules: {
'@typescript-eslint/no-empty-function': 'off',

View File

@ -74,6 +74,7 @@
"cross-env": "^7.0.3",
"csstype": "^3.1.0",
"eslint-config-next": "12.1.6",
"eslint-config-prettier": "8.5.0",
"next-sitemap": "^2.5.14",
"postcss": "8.3.5",
"prettier-plugin-tailwindcss": "^0.1.5",

View File

@ -7,6 +7,7 @@ import { User } from 'common/user'
import { removeUndefinedProps } from 'common/util/object'
import { ENV_CONFIG } from 'common/envs/constants'
import { JSONContent } from '@tiptap/core'
import { richTextToString } from 'common/util/parse'
export type LiteMarket = {
// Unique identifer for this market
@ -22,6 +23,7 @@ export type LiteMarket = {
closeTime?: number
question: string
description: string | JSONContent
textDescription: string // string version of description
tags: string[]
url: string
outcomeType: string
@ -40,6 +42,8 @@ export type LiteMarket = {
resolution?: string
resolutionTime?: number
resolutionProbability?: number
lastUpdatedTime?: number
}
export type ApiAnswer = Answer & {
@ -90,6 +94,7 @@ export function toLiteMarket(contract: Contract): LiteMarket {
resolution,
resolutionTime,
resolutionProbability,
lastUpdatedTime,
} = contract
const { p, totalLiquidity } = contract as any
@ -97,6 +102,11 @@ export function toLiteMarket(contract: Contract): LiteMarket {
const probability =
contract.outcomeType === 'BINARY' ? getProbability(contract) : undefined
let min, max, isLogScale: any
if (contract.outcomeType === 'PSEUDO_NUMERIC') {
;({ min, max, isLogScale } = contract)
}
return removeUndefinedProps({
id,
creatorUsername,
@ -109,6 +119,10 @@ export function toLiteMarket(contract: Contract): LiteMarket {
: closeTime,
question,
description,
textDescription:
typeof description === 'string'
? description
: richTextToString(description),
tags,
url: `https://manifold.markets/${creatorUsername}/${slug}`,
pool,
@ -124,6 +138,10 @@ export function toLiteMarket(contract: Contract): LiteMarket {
resolution,
resolutionTime,
resolutionProbability,
lastUpdatedTime,
min,
max,
isLogScale,
})
}

View File

@ -5764,6 +5764,11 @@ eslint-config-next@12.1.6:
eslint-plugin-react "^7.29.4"
eslint-plugin-react-hooks "^4.5.0"
eslint-config-prettier@8.5.0:
version "8.5.0"
resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-8.5.0.tgz#5a81680ec934beca02c7b1a61cf8ca34b66feab1"
integrity sha512-obmWKLUNCnhtQRKc+tmnYuQl0pFU1ibYJQ5BGhTVB08bHe9wC8qUeG7c08dj9XX+AuPj1YSGSQIHl1pnDHZR0Q==
eslint-import-resolver-node@^0.3.6:
version "0.3.6"
resolved "https://registry.yarnpkg.com/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.6.tgz#4048b958395da89668252001dbd9eca6b83bacbd"