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:
parent
8c2f3c56d3
commit
59565416b6
|
@ -135,7 +135,8 @@ Requires no authorization.
|
||||||
// Market attributes. All times are in milliseconds since epoch
|
// Market attributes. All times are in milliseconds since epoch
|
||||||
closeTime?: number // Min of creator's chosen date, and resolutionTime
|
closeTime?: number // Min of creator's chosen date, and resolutionTime
|
||||||
question: string
|
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.
|
// 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.
|
// This list also includes the predefined categories shown as filters on the home page.
|
||||||
|
@ -162,6 +163,8 @@ Requires no authorization.
|
||||||
resolutionTime?: number
|
resolutionTime?: number
|
||||||
resolution?: string
|
resolution?: string
|
||||||
resolutionProbability?: number // Used for BINARY markets resolved to MKT
|
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`.
|
- `outcomeType`: Required. One of `BINARY`, `FREE_RESPONSE`, or `NUMERIC`.
|
||||||
- `question`: Required. The headline question for the market.
|
- `question`: Required. The headline question for the market.
|
||||||
- `description`: Required. A long description describing the rules 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.
|
- `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.
|
- `tags`: Optional. An array of string tags for the market.
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ const descScehma: z.ZodType<JSONContent> = z.lazy(() =>
|
||||||
|
|
||||||
const bodySchema = z.object({
|
const bodySchema = z.object({
|
||||||
question: z.string().min(1).max(MAX_QUESTION_LENGTH),
|
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(),
|
tags: z.array(z.string().min(1).max(MAX_TAG_LENGTH)).optional(),
|
||||||
closeTime: zTimestamp().refine(
|
closeTime: zTimestamp().refine(
|
||||||
(date) => date.getTime() > new Date().getTime(),
|
(date) => date.getTime() > new Date().getTime(),
|
||||||
|
@ -165,13 +165,27 @@ export const createmarket = newEndpoint({}, async (req, auth) => {
|
||||||
ante || 0
|
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(
|
const contract = getNewContract(
|
||||||
contractRef.id,
|
contractRef.id,
|
||||||
slug,
|
slug,
|
||||||
user,
|
user,
|
||||||
question,
|
question,
|
||||||
outcomeType,
|
outcomeType,
|
||||||
description ?? {},
|
newDescription,
|
||||||
initialProb ?? 0,
|
initialProb ?? 0,
|
||||||
ante,
|
ante,
|
||||||
closeTime.getTime(),
|
closeTime.getTime(),
|
||||||
|
|
|
@ -5,6 +5,7 @@ module.exports = {
|
||||||
'plugin:@typescript-eslint/recommended',
|
'plugin:@typescript-eslint/recommended',
|
||||||
'plugin:react-hooks/recommended',
|
'plugin:react-hooks/recommended',
|
||||||
'plugin:@next/next/recommended',
|
'plugin:@next/next/recommended',
|
||||||
|
'prettier',
|
||||||
],
|
],
|
||||||
rules: {
|
rules: {
|
||||||
'@typescript-eslint/no-empty-function': 'off',
|
'@typescript-eslint/no-empty-function': 'off',
|
||||||
|
|
|
@ -74,6 +74,7 @@
|
||||||
"cross-env": "^7.0.3",
|
"cross-env": "^7.0.3",
|
||||||
"csstype": "^3.1.0",
|
"csstype": "^3.1.0",
|
||||||
"eslint-config-next": "12.1.6",
|
"eslint-config-next": "12.1.6",
|
||||||
|
"eslint-config-prettier": "8.5.0",
|
||||||
"next-sitemap": "^2.5.14",
|
"next-sitemap": "^2.5.14",
|
||||||
"postcss": "8.3.5",
|
"postcss": "8.3.5",
|
||||||
"prettier-plugin-tailwindcss": "^0.1.5",
|
"prettier-plugin-tailwindcss": "^0.1.5",
|
||||||
|
|
|
@ -7,6 +7,7 @@ import { User } from 'common/user'
|
||||||
import { removeUndefinedProps } from 'common/util/object'
|
import { removeUndefinedProps } from 'common/util/object'
|
||||||
import { ENV_CONFIG } from 'common/envs/constants'
|
import { ENV_CONFIG } from 'common/envs/constants'
|
||||||
import { JSONContent } from '@tiptap/core'
|
import { JSONContent } from '@tiptap/core'
|
||||||
|
import { richTextToString } from 'common/util/parse'
|
||||||
|
|
||||||
export type LiteMarket = {
|
export type LiteMarket = {
|
||||||
// Unique identifer for this market
|
// Unique identifer for this market
|
||||||
|
@ -22,6 +23,7 @@ export type LiteMarket = {
|
||||||
closeTime?: number
|
closeTime?: number
|
||||||
question: string
|
question: string
|
||||||
description: string | JSONContent
|
description: string | JSONContent
|
||||||
|
textDescription: string // string version of description
|
||||||
tags: string[]
|
tags: string[]
|
||||||
url: string
|
url: string
|
||||||
outcomeType: string
|
outcomeType: string
|
||||||
|
@ -40,6 +42,8 @@ export type LiteMarket = {
|
||||||
resolution?: string
|
resolution?: string
|
||||||
resolutionTime?: number
|
resolutionTime?: number
|
||||||
resolutionProbability?: number
|
resolutionProbability?: number
|
||||||
|
|
||||||
|
lastUpdatedTime?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ApiAnswer = Answer & {
|
export type ApiAnswer = Answer & {
|
||||||
|
@ -90,6 +94,7 @@ export function toLiteMarket(contract: Contract): LiteMarket {
|
||||||
resolution,
|
resolution,
|
||||||
resolutionTime,
|
resolutionTime,
|
||||||
resolutionProbability,
|
resolutionProbability,
|
||||||
|
lastUpdatedTime,
|
||||||
} = contract
|
} = contract
|
||||||
|
|
||||||
const { p, totalLiquidity } = contract as any
|
const { p, totalLiquidity } = contract as any
|
||||||
|
@ -97,6 +102,11 @@ export function toLiteMarket(contract: Contract): LiteMarket {
|
||||||
const probability =
|
const probability =
|
||||||
contract.outcomeType === 'BINARY' ? getProbability(contract) : undefined
|
contract.outcomeType === 'BINARY' ? getProbability(contract) : undefined
|
||||||
|
|
||||||
|
let min, max, isLogScale: any
|
||||||
|
if (contract.outcomeType === 'PSEUDO_NUMERIC') {
|
||||||
|
;({ min, max, isLogScale } = contract)
|
||||||
|
}
|
||||||
|
|
||||||
return removeUndefinedProps({
|
return removeUndefinedProps({
|
||||||
id,
|
id,
|
||||||
creatorUsername,
|
creatorUsername,
|
||||||
|
@ -109,6 +119,10 @@ export function toLiteMarket(contract: Contract): LiteMarket {
|
||||||
: closeTime,
|
: closeTime,
|
||||||
question,
|
question,
|
||||||
description,
|
description,
|
||||||
|
textDescription:
|
||||||
|
typeof description === 'string'
|
||||||
|
? description
|
||||||
|
: richTextToString(description),
|
||||||
tags,
|
tags,
|
||||||
url: `https://manifold.markets/${creatorUsername}/${slug}`,
|
url: `https://manifold.markets/${creatorUsername}/${slug}`,
|
||||||
pool,
|
pool,
|
||||||
|
@ -124,6 +138,10 @@ export function toLiteMarket(contract: Contract): LiteMarket {
|
||||||
resolution,
|
resolution,
|
||||||
resolutionTime,
|
resolutionTime,
|
||||||
resolutionProbability,
|
resolutionProbability,
|
||||||
|
lastUpdatedTime,
|
||||||
|
min,
|
||||||
|
max,
|
||||||
|
isLogScale,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5764,6 +5764,11 @@ eslint-config-next@12.1.6:
|
||||||
eslint-plugin-react "^7.29.4"
|
eslint-plugin-react "^7.29.4"
|
||||||
eslint-plugin-react-hooks "^4.5.0"
|
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:
|
eslint-import-resolver-node@^0.3.6:
|
||||||
version "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"
|
resolved "https://registry.yarnpkg.com/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.6.tgz#4048b958395da89668252001dbd9eca6b83bacbd"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user