From 1b2aff170f6af4dc5e2e5fe77a4ffdc2136bf0e8 Mon Sep 17 00:00:00 2001 From: Milli Date: Tue, 31 May 2022 17:43:21 +0200 Subject: [PATCH 01/13] refactoring (cherry picked from commit 4de86d5b08f9bc1d960b51746260a5b8c5d9b1fd) --- web/hooks/use-measure-size.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web/hooks/use-measure-size.ts b/web/hooks/use-measure-size.ts index 6959e241..723c2fe4 100644 --- a/web/hooks/use-measure-size.ts +++ b/web/hooks/use-measure-size.ts @@ -16,7 +16,7 @@ export function useListenElemSize( debounceMs: number | undefined = undefined ) { const handleResize = useMemo(() => { - let updateSize = () => { + const updateSize = () => { if (elemRef.current) callback(getSize(elemRef.current)) } @@ -25,7 +25,7 @@ export function useListenElemSize( : updateSize }, [callback, elemRef, debounceMs]) - let elem = elemRef.current + const elem = elemRef.current useLayoutEffect(() => { if (!elemRef.current) return From 03a3726dd882ea93f12bf94c2b82f2819faaffc1 Mon Sep 17 00:00:00 2001 From: Milli Date: Sat, 28 May 2022 01:06:49 +0200 Subject: [PATCH 02/13] Added comments for leading semicolons (cherry picked from commit 60739c7853ce611a12227887f1a115f75e957d8e) --- functions/src/create-contract.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/functions/src/create-contract.ts b/functions/src/create-contract.ts index 805e4f6a..3fce71a6 100644 --- a/functions/src/create-contract.ts +++ b/functions/src/create-contract.ts @@ -56,11 +56,11 @@ export const createContract = newEndpoint(['POST'], async (req, [user, _]) => { let min, max, initialProb if (outcomeType === 'NUMERIC') { - ;({ min, max } = validate(numericSchema, req.body)) + ;({ min, max } = validate(numericSchema, req.body)) // leading ; intentional: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#assignment_separate_from_declaration_2 if (max - min <= 0.01) throw new APIError(400, 'Invalid range.') } if (outcomeType === 'BINARY') { - ;({ initialProb } = validate(binarySchema, req.body)) + ;({ initialProb } = validate(binarySchema, req.body)) // leading ; intentional: see abive } // Uses utc time on server: From 09aea5c207bcdc5ee2edb5db70223b5516abe415 Mon Sep 17 00:00:00 2001 From: Milli Date: Wed, 25 May 2022 17:26:11 +0200 Subject: [PATCH 03/13] Ignoring vs code files Should this be done in the repo or should everyone using VS Code do that himself globally on his machine(s)? (cherry picked from commit 944de9398a03ff9e5b2fccefa69935b4d9fa4b32) --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 10f5d982..4cd8acf1 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ .vercel node_modules yarn-error.log +.vscode \ No newline at end of file From 6dab3c4e29c1ee0ed432957327e2f30b80a2dde0 Mon Sep 17 00:00:00 2001 From: Milli Date: Thu, 2 Jun 2022 23:32:19 +0200 Subject: [PATCH 04/13] removed unused imports and variables --- web/components/contract/contract-details.tsx | 6 ------ web/components/contract/contract-info-dialog.tsx | 3 +-- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/web/components/contract/contract-details.tsx b/web/components/contract/contract-details.tsx index 0115c746..438eb3ec 100644 --- a/web/components/contract/contract-details.tsx +++ b/web/components/contract/contract-details.tsx @@ -1,13 +1,9 @@ -import clsx from 'clsx' import { ClockIcon, DatabaseIcon, PencilIcon, - CurrencyDollarIcon, TrendingUpIcon, - StarIcon, } from '@heroicons/react/outline' -import { StarIcon as SolidStarIcon } from '@heroicons/react/solid' import { Row } from '../layout/row' import { formatMoney } from 'common/util/format' import { UserLink } from '../user-page' @@ -17,7 +13,6 @@ import { contractPool, updateContract, } from 'web/lib/firebase/contracts' -import { Col } from '../layout/col' import dayjs from 'dayjs' import { DateTimeTooltip } from '../datetime-tooltip' import { fromNow } from 'web/lib/util/time' @@ -36,7 +31,6 @@ export function MiscDetails(props: { }) { const { contract, showHotVolume, showCloseTime } = props const { volume, volume24Hours, closeTime, tags } = contract - const { volumeLabel } = contractMetrics(contract) // Show at most one category that this contract is tagged by const categories = CATEGORY_LIST.filter((category) => tags.map((t) => t.toLowerCase()).includes(category) diff --git a/web/components/contract/contract-info-dialog.tsx b/web/components/contract/contract-info-dialog.tsx index 28cd91f4..446d04e7 100644 --- a/web/components/contract/contract-info-dialog.tsx +++ b/web/components/contract/contract-info-dialog.tsx @@ -1,14 +1,13 @@ import { DotsHorizontalIcon } from '@heroicons/react/outline' import clsx from 'clsx' import dayjs from 'dayjs' -import { uniqBy, sum } from 'lodash' +import { uniqBy } from 'lodash' import { useState } from 'react' import { Bet } from 'common/bet' import { Contract } from 'common/contract' import { formatMoney } from 'common/util/format' import { - contractMetrics, contractPath, contractPool, getBinaryProbPercent, From dfec5ed8fad2690404926f9e65cedc4fc1897128 Mon Sep 17 00:00:00 2001 From: Milli Date: Thu, 2 Jun 2022 23:35:58 +0200 Subject: [PATCH 05/13] added type for binary resolution --- common/contract.ts | 3 ++- web/components/outcome-label.tsx | 4 ++-- web/components/resolution-panel.tsx | 4 ++-- web/components/yes-no-selector.tsx | 5 +++-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/common/contract.ts b/common/contract.ts index cf4bae0b..f7cd1407 100644 --- a/common/contract.ts +++ b/common/contract.ts @@ -71,7 +71,7 @@ export type Binary = { outcomeType: 'BINARY' initialProbability: number resolutionProbability?: number // Used for BINARY markets resolved to MKT - resolution?: 'YES' | 'NO' | 'MKT' | 'CANCEL' + resolution?: resolution } export type FreeResponse = { @@ -91,6 +91,7 @@ export type Numeric = { } export type outcomeType = AnyOutcomeType['outcomeType'] +export type resolution = 'YES' | 'NO' | 'MKT' | 'CANCEL' export const OUTCOME_TYPES = ['BINARY', 'FREE_RESPONSE', 'NUMERIC'] as const export const MAX_QUESTION_LENGTH = 480 export const MAX_DESCRIPTION_LENGTH = 10000 diff --git a/web/components/outcome-label.tsx b/web/components/outcome-label.tsx index da8a0e80..eb789faa 100644 --- a/web/components/outcome-label.tsx +++ b/web/components/outcome-label.tsx @@ -3,13 +3,13 @@ import { ReactNode } from 'react' import { Answer } from 'common/answer' import { getProbability } from 'common/calculate' import { getValueFromBucket } from 'common/calculate-dpm' -import { BinaryContract, Contract, FreeResponseContract } from 'common/contract' +import { BinaryContract, Contract, FreeResponseContract, resolution } from 'common/contract' import { formatPercent } from 'common/util/format' import { ClientRender } from './client-render' export function OutcomeLabel(props: { contract: Contract - outcome: 'YES' | 'NO' | 'CANCEL' | 'MKT' | string + outcome: resolution | string truncate: 'short' | 'long' | 'none' value?: number }) { diff --git a/web/components/resolution-panel.tsx b/web/components/resolution-panel.tsx index fc031b22..6d0319b2 100644 --- a/web/components/resolution-panel.tsx +++ b/web/components/resolution-panel.tsx @@ -10,7 +10,7 @@ import { resolveMarket } from 'web/lib/firebase/fn-call' import { ProbabilitySelector } from './probability-selector' import { DPM_CREATOR_FEE } from 'common/fees' import { getProbability } from 'common/calculate' -import { BinaryContract } from 'common/contract' +import { BinaryContract, resolution } from 'common/contract' import { formatMoney } from 'common/util/format' export function ResolutionPanel(props: { @@ -31,7 +31,7 @@ export function ResolutionPanel(props: { : `${formatMoney(contract.collectedFees.creatorFee)} in fees` const [outcome, setOutcome] = useState< - 'YES' | 'NO' | 'MKT' | 'CANCEL' | undefined + resolution | undefined >() const [prob, setProb] = useState(getProbability(contract) * 100) diff --git a/web/components/yes-no-selector.tsx b/web/components/yes-no-selector.tsx index 25bdaaeb..1a5eabf5 100644 --- a/web/components/yes-no-selector.tsx +++ b/web/components/yes-no-selector.tsx @@ -3,6 +3,7 @@ import React, { ReactNode } from 'react' import { formatMoney } from 'common/util/format' import { Col } from './layout/col' import { Row } from './layout/row' +import { resolution } from 'common/contract' export function YesNoSelector(props: { selected?: 'YES' | 'NO' @@ -65,8 +66,8 @@ export function YesNoSelector(props: { } export function YesNoCancelSelector(props: { - selected: 'YES' | 'NO' | 'MKT' | 'CANCEL' | undefined - onSelect: (selected: 'YES' | 'NO' | 'MKT' | 'CANCEL') => void + selected: resolution | undefined + onSelect: (selected: resolution) => void className?: string btnClassName?: string }) { From fba083ceadde3e8e63becc2a67a1cd80e943192f Mon Sep 17 00:00:00 2001 From: Milli Date: Fri, 3 Jun 2022 00:09:02 +0200 Subject: [PATCH 06/13] Prettier --- web/components/outcome-label.tsx | 7 ++++++- web/components/resolution-panel.tsx | 4 +--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/web/components/outcome-label.tsx b/web/components/outcome-label.tsx index eb789faa..0ead4f94 100644 --- a/web/components/outcome-label.tsx +++ b/web/components/outcome-label.tsx @@ -3,7 +3,12 @@ import { ReactNode } from 'react' import { Answer } from 'common/answer' import { getProbability } from 'common/calculate' import { getValueFromBucket } from 'common/calculate-dpm' -import { BinaryContract, Contract, FreeResponseContract, resolution } from 'common/contract' +import { + BinaryContract, + Contract, + FreeResponseContract, + resolution, +} from 'common/contract' import { formatPercent } from 'common/util/format' import { ClientRender } from './client-render' diff --git a/web/components/resolution-panel.tsx b/web/components/resolution-panel.tsx index 6d0319b2..8b453765 100644 --- a/web/components/resolution-panel.tsx +++ b/web/components/resolution-panel.tsx @@ -30,9 +30,7 @@ export function ResolutionPanel(props: { ? `${DPM_CREATOR_FEE * 100}% of trader profits` : `${formatMoney(contract.collectedFees.creatorFee)} in fees` - const [outcome, setOutcome] = useState< - resolution | undefined - >() + const [outcome, setOutcome] = useState() const [prob, setProb] = useState(getProbability(contract) * 100) From 01adc91a67f7bb5bb9529bb44d22eb9989df486d Mon Sep 17 00:00:00 2001 From: Milli Date: Fri, 3 Jun 2022 00:31:05 +0200 Subject: [PATCH 07/13] const for binary resolutions --- common/contract.ts | 1 + functions/src/resolve-market.ts | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/common/contract.ts b/common/contract.ts index f7cd1407..f75cfa4b 100644 --- a/common/contract.ts +++ b/common/contract.ts @@ -92,6 +92,7 @@ export type Numeric = { export type outcomeType = AnyOutcomeType['outcomeType'] export type resolution = 'YES' | 'NO' | 'MKT' | 'CANCEL' +export const RESOLUTIONS = ['YES', 'NO', 'MKT', 'CANCEL'] as const export const OUTCOME_TYPES = ['BINARY', 'FREE_RESPONSE', 'NUMERIC'] as const export const MAX_QUESTION_LENGTH = 480 export const MAX_DESCRIPTION_LENGTH = 10000 diff --git a/functions/src/resolve-market.ts b/functions/src/resolve-market.ts index 183a5624..cf8c018f 100644 --- a/functions/src/resolve-market.ts +++ b/functions/src/resolve-market.ts @@ -2,7 +2,7 @@ import * as functions from 'firebase-functions' import * as admin from 'firebase-admin' import { difference, uniq, mapValues, groupBy, sumBy } from 'lodash' -import { Contract } from '../../common/contract' +import { Contract, resolution, RESOLUTIONS } from '../../common/contract' import { User } from '../../common/user' import { Bet } from '../../common/bet' import { getUser, isProd, payUser } from './utils' @@ -21,7 +21,7 @@ export const resolveMarket = functions .https.onCall( async ( data: { - outcome: string + outcome: resolution value?: number contractId: string probabilityInt?: number @@ -42,7 +42,7 @@ export const resolveMarket = functions const { creatorId, outcomeType, closeTime } = contract if (outcomeType === 'BINARY') { - if (!['YES', 'NO', 'MKT', 'CANCEL'].includes(outcome)) + if (!RESOLUTIONS.includes(outcome)) return { status: 'error', message: 'Invalid outcome' } } else if (outcomeType === 'FREE_RESPONSE') { if ( From 5315eb36005c8fe4da442a851a7b9f30810ef9bc Mon Sep 17 00:00:00 2001 From: Milli Date: Fri, 3 Jun 2022 00:36:24 +0200 Subject: [PATCH 08/13] using the type "resolution" --- web/components/contract/quick-bet.tsx | 4 ++-- web/components/outcome-label.tsx | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/web/components/contract/quick-bet.tsx b/web/components/contract/quick-bet.tsx index 8f642656..e1a2eead 100644 --- a/web/components/contract/quick-bet.tsx +++ b/web/components/contract/quick-bet.tsx @@ -6,7 +6,7 @@ import { } from 'common/calculate' import { getExpectedValue } from 'common/calculate-dpm' import { User } from 'common/user' -import { Contract, NumericContract } from 'common/contract' +import { Contract, NumericContract, resolution } from 'common/contract' import { formatLargeNumber, formatMoney, @@ -264,7 +264,7 @@ export function getColor(contract: Contract, previewProb?: number) { const { resolution } = contract if (resolution) { return ( - OUTCOME_TO_COLOR[resolution as 'YES' | 'NO' | 'CANCEL' | 'MKT'] ?? + OUTCOME_TO_COLOR[resolution as resolution] ?? // If resolved to a FR answer, use 'primary' 'primary' ) diff --git a/web/components/outcome-label.tsx b/web/components/outcome-label.tsx index 0ead4f94..f76b091b 100644 --- a/web/components/outcome-label.tsx +++ b/web/components/outcome-label.tsx @@ -41,7 +41,7 @@ export function OutcomeLabel(props: { } export function BinaryOutcomeLabel(props: { - outcome: 'YES' | 'NO' | 'CANCEL' | 'MKT' + outcome: resolution }) { const { outcome } = props @@ -53,7 +53,7 @@ export function BinaryOutcomeLabel(props: { export function BinaryContractOutcomeLabel(props: { contract: BinaryContract - resolution: 'YES' | 'NO' | 'CANCEL' | 'MKT' + resolution: resolution }) { const { contract, resolution } = props From 4be929fd8e78e6b95ff34fb79754be57c231ef8c Mon Sep 17 00:00:00 2001 From: Milli Date: Fri, 3 Jun 2022 00:39:15 +0200 Subject: [PATCH 09/13] Prettier --- web/components/outcome-label.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/web/components/outcome-label.tsx b/web/components/outcome-label.tsx index f76b091b..6daa855b 100644 --- a/web/components/outcome-label.tsx +++ b/web/components/outcome-label.tsx @@ -40,9 +40,7 @@ export function OutcomeLabel(props: { ) } -export function BinaryOutcomeLabel(props: { - outcome: resolution -}) { +export function BinaryOutcomeLabel(props: { outcome: resolution }) { const { outcome } = props if (outcome === 'YES') return From a416a2de6eaff7ecf0fe89452f74e5759babc475 Mon Sep 17 00:00:00 2001 From: TrueMilli <61841994+TrueMilli@users.noreply.github.com> Date: Fri, 3 Jun 2022 00:48:45 +0200 Subject: [PATCH 10/13] Update functions/src/create-contract.ts --- functions/src/create-contract.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/src/create-contract.ts b/functions/src/create-contract.ts index 3fce71a6..c93b715f 100644 --- a/functions/src/create-contract.ts +++ b/functions/src/create-contract.ts @@ -60,7 +60,7 @@ export const createContract = newEndpoint(['POST'], async (req, [user, _]) => { if (max - min <= 0.01) throw new APIError(400, 'Invalid range.') } if (outcomeType === 'BINARY') { - ;({ initialProb } = validate(binarySchema, req.body)) // leading ; intentional: see abive + ;({ initialProb } = validate(binarySchema, req.body)) // leading ; intentional: see above } // Uses utc time on server: From 776f7b73674e2669d1e49224c8b6ceb20a5896c4 Mon Sep 17 00:00:00 2001 From: Milli Date: Fri, 3 Jun 2022 01:03:10 +0200 Subject: [PATCH 11/13] Revert "Ignoring vs code files" This reverts commit 09aea5c207bcdc5ee2edb5db70223b5516abe415. --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 4cd8acf1..10f5d982 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,3 @@ .vercel node_modules yarn-error.log -.vscode \ No newline at end of file From 78969e4a414e5550520fa17aabcbb1a1e210cb39 Mon Sep 17 00:00:00 2001 From: Milli Date: Fri, 3 Jun 2022 01:06:24 +0200 Subject: [PATCH 12/13] launch config for debugging with vs code WIP * "Launch Chrome" does not work since login via google is not possible in debugger-chrome * Breakpoints are unbound when attached to chrome --- .vscode/launch.json | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..c35acf8d --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,23 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "chrome", + "request": "launch", + "name": "Launch Chrome against localhost", + "url": "http://localhost:3000", + "webRoot": "${workspaceRoot}" + }, + { + "type": "chrome", + "request": "attach", + "name": "Attach to Chrome", + "port": 9222, + "urlFilter": "http://localhost:3000/*", + "webRoot": "${workspaceFolder}" + } + ] +} \ No newline at end of file From 7f25a6da1a78df93f82d12766a8f525fab470d4c Mon Sep 17 00:00:00 2001 From: Milli Date: Fri, 3 Jun 2022 01:14:45 +0200 Subject: [PATCH 13/13] Revert "Added comments for leading semicolons" --- functions/src/create-contract.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/functions/src/create-contract.ts b/functions/src/create-contract.ts index c93b715f..805e4f6a 100644 --- a/functions/src/create-contract.ts +++ b/functions/src/create-contract.ts @@ -56,11 +56,11 @@ export const createContract = newEndpoint(['POST'], async (req, [user, _]) => { let min, max, initialProb if (outcomeType === 'NUMERIC') { - ;({ min, max } = validate(numericSchema, req.body)) // leading ; intentional: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#assignment_separate_from_declaration_2 + ;({ min, max } = validate(numericSchema, req.body)) if (max - min <= 0.01) throw new APIError(400, 'Invalid range.') } if (outcomeType === 'BINARY') { - ;({ initialProb } = validate(binarySchema, req.body)) // leading ; intentional: see above + ;({ initialProb } = validate(binarySchema, req.body)) } // Uses utc time on server: