Merge branch 'main' into separate-free-response-answers-comments
This commit is contained in:
commit
9199b99fd0
|
@ -174,17 +174,19 @@ export function calculateCpmmSale(
|
||||||
throw new Error('Cannot sell non-positive shares')
|
throw new Error('Cannot sell non-positive shares')
|
||||||
}
|
}
|
||||||
|
|
||||||
const rawSaleValue = calculateCpmmShareValue(
|
const saleValue = calculateCpmmShareValue(
|
||||||
contract,
|
contract,
|
||||||
shares,
|
shares,
|
||||||
outcome as 'YES' | 'NO'
|
outcome as 'YES' | 'NO'
|
||||||
)
|
)
|
||||||
|
|
||||||
const { fees, remainingBet: saleValue } = getCpmmLiquidityFee(
|
const fees = noFees
|
||||||
contract,
|
|
||||||
rawSaleValue,
|
// const { fees, remainingBet: saleValue } = getCpmmLiquidityFee(
|
||||||
outcome === 'YES' ? 'NO' : 'YES'
|
// contract,
|
||||||
)
|
// rawSaleValue,
|
||||||
|
// outcome === 'YES' ? 'NO' : 'YES'
|
||||||
|
// )
|
||||||
|
|
||||||
const { pool } = contract
|
const { pool } = contract
|
||||||
const { YES: y, NO: n } = pool
|
const { YES: y, NO: n } = pool
|
||||||
|
|
1
functions/.gitignore
vendored
1
functions/.gitignore
vendored
|
@ -15,4 +15,5 @@ node_modules/
|
||||||
package-lock.json
|
package-lock.json
|
||||||
ui-debug.log
|
ui-debug.log
|
||||||
firebase-debug.log
|
firebase-debug.log
|
||||||
|
firestore-debug.log
|
||||||
firestore_export/
|
firestore_export/
|
||||||
|
|
|
@ -19,14 +19,33 @@ Adapted from https://firebase.google.com/docs/functions/get-started
|
||||||
2. `$ yarn` to install JS dependencies
|
2. `$ yarn` to install JS dependencies
|
||||||
3. `$ firebase login` to authenticate the CLI tools to Firebase
|
3. `$ firebase login` to authenticate the CLI tools to Firebase
|
||||||
4. `$ firebase use dev` to choose the dev project
|
4. `$ firebase use dev` to choose the dev project
|
||||||
5. `$ firebase functions:config:get > .runtimeconfig.json` to cache secrets for local dev (TODO: maybe not for Manifold)
|
|
||||||
|
### For local development
|
||||||
|
|
||||||
|
0. `$ firebase functions:config:get > .runtimeconfig.json` to cache secrets for local dev
|
||||||
|
1. [Install](https://cloud.google.com/sdk/docs/install) gcloud CLI
|
||||||
|
2. `$ brew install java` to install java if you don't already have it
|
||||||
|
1. `$ echo 'export PATH="/usr/local/opt/openjdk/bin:$PATH"' >> ~/.zshrc` to add java to your path
|
||||||
|
3. `$ gcloud auth login` to authenticate the CLI tools to Google Cloud
|
||||||
|
4. `$ gcloud config set project <project-id>` to choose the project (`$ gcloud projects list` to see options)
|
||||||
|
5. `$ mkdir firestore_export` to create a folder to store the exported database
|
||||||
|
6. `$ yarn db:update-local-from-remote` to pull the remote db from Firestore to local
|
||||||
|
1. TODO: this won't work when open source, we'll have to point to the public db
|
||||||
|
|
||||||
## Developing locally
|
## Developing locally
|
||||||
|
|
||||||
0. `$ yarn dev` to spin up the emulators
|
1. `$ yarn serve` to spin up the emulators
|
||||||
The Emulator UI is at http://localhost:4000; the functions are hosted on :5001.
|
The Emulator UI is at http://localhost:4000; the functions are hosted on :5001.
|
||||||
Note: You have to kill and restart emulators when you change code; no hot reload =(
|
Note: You have to kill and restart emulators when you change code; no hot reload =(
|
||||||
1. Connect to emulators by enabling `functions.useEmulator('localhost', 5001)`
|
2. `$ yarn dev:emulate` in `/web` to connect to emulators with the frontend
|
||||||
|
1. Note: emulated database is cleared after every shutdown
|
||||||
|
|
||||||
|
## Firestore Commands
|
||||||
|
|
||||||
|
- `db:update-local-from-remote` - Pull the remote db from Firestore to local, also calls:
|
||||||
|
- `db:backup-remote` - Exports the remote dev db to the backup folder on Google Cloud Storage (called on every `db:update-local-from-remote`)
|
||||||
|
- `db:rename-remote-backup-folder` - Renames the remote backup folder (called on every `db:backup-remote` to preserve the previous db backup)
|
||||||
|
- `db:backup-local` - Save the local db changes to the disk (overwrites existing)
|
||||||
|
|
||||||
## Debugging
|
## Debugging
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,21 @@
|
||||||
{
|
{
|
||||||
"name": "functions",
|
"name": "functions",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
|
"config": {
|
||||||
|
"firestore": "dev-mantic-markets.appspot.com"
|
||||||
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
"watch": "tsc -w",
|
"watch": "tsc -w",
|
||||||
"serve": "yarn build && firebase emulators:start --only functions",
|
|
||||||
"shell": "yarn build && firebase functions:shell",
|
"shell": "yarn build && firebase functions:shell",
|
||||||
"start": "yarn shell",
|
"start": "yarn shell",
|
||||||
"deploy": "firebase deploy --only functions",
|
"deploy": "firebase deploy --only functions",
|
||||||
"logs": "firebase functions:log"
|
"logs": "firebase functions:log",
|
||||||
|
"serve": "yarn build && firebase emulators:start --only functions,firestore --import=./firestore_export",
|
||||||
|
"db:update-local-from-remote": "yarn db:backup-remote && gsutil rsync -r gs://$npm_package_config_firestore/firestore_export ./firestore_export",
|
||||||
|
"db:backup-local": "firebase emulators:export --force ./firestore_export",
|
||||||
|
"db:rename-remote-backup-folder": "gsutil mv gs://$npm_package_config_firestore/firestore_export gs://$npm_package_config_firestore/firestore_export_$(date +%d-%m-%Y-%H-%M)",
|
||||||
|
"db:backup-remote": "yarn db:rename-remote-backup-folder && gcloud firestore export gs://$npm_package_config_firestore/firestore_export/"
|
||||||
},
|
},
|
||||||
"main": "lib/functions/src/index.js",
|
"main": "lib/functions/src/index.js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
2100
functions/yarn.lock
2100
functions/yarn.lock
File diff suppressed because it is too large
Load Diff
|
@ -8,6 +8,11 @@
|
||||||
|
|
||||||
(`yarn dev` will point you to prod database)
|
(`yarn dev` will point you to prod database)
|
||||||
|
|
||||||
|
### Running with local emulated database and functions
|
||||||
|
|
||||||
|
1. `yarn serve` first in `/functions` and wait for it to start
|
||||||
|
2. `yarn dev:emulate` will point you to the emulated database
|
||||||
|
|
||||||
## Formatting
|
## Formatting
|
||||||
|
|
||||||
Before committing, run `yarn format` to format your code.
|
Before committing, run `yarn format` to format your code.
|
||||||
|
|
|
@ -213,7 +213,7 @@ const NoBets = () => {
|
||||||
return (
|
return (
|
||||||
<div className="mx-4 text-gray-500">
|
<div className="mx-4 text-gray-500">
|
||||||
You have not made any bets yet.{' '}
|
You have not made any bets yet.{' '}
|
||||||
<SiteLink href="/" className="underline">
|
<SiteLink href="/home" className="underline">
|
||||||
Find a prediction market!
|
Find a prediction market!
|
||||||
</SiteLink>
|
</SiteLink>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { SparklesIcon, XIcon } from '@heroicons/react/solid'
|
import { SparklesIcon, XIcon } from '@heroicons/react/solid'
|
||||||
import { Avatar } from './avatar'
|
import { Avatar } from './avatar'
|
||||||
import { useRef, useState } from 'react'
|
import { useEffect, useRef, useState } from 'react'
|
||||||
import { Spacer } from './layout/spacer'
|
import { Spacer } from './layout/spacer'
|
||||||
import { NewContract } from '../pages/create'
|
import { NewContract } from '../pages/create'
|
||||||
import { firebaseLogin, User } from '../lib/firebase/users'
|
import { firebaseLogin, User } from '../lib/firebase/users'
|
||||||
|
@ -10,6 +10,7 @@ import { Col } from './layout/col'
|
||||||
import clsx from 'clsx'
|
import clsx from 'clsx'
|
||||||
import { Row } from './layout/row'
|
import { Row } from './layout/row'
|
||||||
import { ENV_CONFIG } from '../../common/envs/constants'
|
import { ENV_CONFIG } from '../../common/envs/constants'
|
||||||
|
import _ from 'lodash'
|
||||||
|
|
||||||
export function FeedPromo(props: { hotContracts: Contract[] }) {
|
export function FeedPromo(props: { hotContracts: Contract[] }) {
|
||||||
const { hotContracts } = props
|
const { hotContracts } = props
|
||||||
|
@ -71,14 +72,19 @@ export default function FeedCreate(props: {
|
||||||
const [isExpanded, setIsExpanded] = useState(false)
|
const [isExpanded, setIsExpanded] = useState(false)
|
||||||
const inputRef = useRef<HTMLTextAreaElement | null>()
|
const inputRef = useRef<HTMLTextAreaElement | null>()
|
||||||
|
|
||||||
const placeholders = ENV_CONFIG.newQuestionPlaceholders
|
|
||||||
// Rotate through a new placeholder each day
|
// Rotate through a new placeholder each day
|
||||||
// Easter egg idea: click your own name to shuffle the placeholder
|
// Easter egg idea: click your own name to shuffle the placeholder
|
||||||
// const daysSinceEpoch = Math.floor(Date.now() / 1000 / 60 / 60 / 24)
|
// const daysSinceEpoch = Math.floor(Date.now() / 1000 / 60 / 60 / 24)
|
||||||
const [randIndex] = useState(
|
|
||||||
Math.floor(Math.random() * 1e10) % placeholders.length
|
// Take care not to produce a different placeholder on the server and client
|
||||||
|
const [defaultPlaceholder, setDefaultPlaceholder] = useState('')
|
||||||
|
useEffect(() => {
|
||||||
|
setDefaultPlaceholder(
|
||||||
|
`e.g. ${_.sample(ENV_CONFIG.newQuestionPlaceholders)}`
|
||||||
)
|
)
|
||||||
const placeholder = props.placeholder ?? `e.g. ${placeholders[randIndex]}`
|
}, [])
|
||||||
|
|
||||||
|
const placeholder = props.placeholder ?? defaultPlaceholder
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
import { getFunctions, httpsCallable } from 'firebase/functions'
|
import { httpsCallable } from 'firebase/functions'
|
||||||
import { Fold } from '../../../common/fold'
|
import { Fold } from '../../../common/fold'
|
||||||
import { User } from '../../../common/user'
|
import { User } from '../../../common/user'
|
||||||
import { randomString } from '../../../common/util/random'
|
import { randomString } from '../../../common/util/random'
|
||||||
import './init'
|
import './init'
|
||||||
|
import { functions } from './init'
|
||||||
const functions = getFunctions()
|
|
||||||
|
|
||||||
export const cloudFunction = <RequestData, ResponseData>(name: string) =>
|
export const cloudFunction = <RequestData, ResponseData>(name: string) =>
|
||||||
httpsCallable<RequestData, ResponseData>(functions, name)
|
httpsCallable<RequestData, ResponseData>(functions, name)
|
||||||
|
|
|
@ -1,8 +1,26 @@
|
||||||
import { getFirestore } from '@firebase/firestore'
|
import { getFirestore } from '@firebase/firestore'
|
||||||
import { initializeApp, getApps, getApp } from 'firebase/app'
|
import { initializeApp, getApps, getApp } from 'firebase/app'
|
||||||
import { FIREBASE_CONFIG } from '../../../common/envs/constants'
|
import { FIREBASE_CONFIG } from '../../../common/envs/constants'
|
||||||
|
import { connectFirestoreEmulator } from 'firebase/firestore'
|
||||||
|
import { connectFunctionsEmulator, getFunctions } from 'firebase/functions'
|
||||||
|
|
||||||
// Initialize Firebase
|
// Initialize Firebase
|
||||||
export const app = getApps().length ? getApp() : initializeApp(FIREBASE_CONFIG)
|
export const app = getApps().length ? getApp() : initializeApp(FIREBASE_CONFIG)
|
||||||
|
export const db = getFirestore()
|
||||||
|
export const functions = getFunctions()
|
||||||
|
|
||||||
export const db = getFirestore(app)
|
const EMULATORS_STARTED = 'EMULATORS_STARTED'
|
||||||
|
function startEmulators() {
|
||||||
|
// I don't like this but this is the only way to reconnect to the emulators without error, see: https://stackoverflow.com/questions/65066963/firebase-firestore-emulator-error-host-has-been-set-in-both-settings-and-usee
|
||||||
|
// @ts-ignore
|
||||||
|
if (!global[EMULATORS_STARTED]) {
|
||||||
|
// @ts-ignore
|
||||||
|
global[EMULATORS_STARTED] = true
|
||||||
|
connectFirestoreEmulator(db, 'localhost', 8080)
|
||||||
|
connectFunctionsEmulator(functions, 'localhost', 5001)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (process.env.NEXT_PUBLIC_FIREBASE_EMULATE) {
|
||||||
|
startEmulators()
|
||||||
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
"devdev": "NEXT_PUBLIC_FIREBASE_ENV=DEV concurrently -n NEXT,TS -c magenta,cyan \"FIREBASE_ENV=DEV next dev -p 3000\" \"FIREBASE_ENV=DEV yarn ts --watch\" # see https://github.com/vercel/next.js/discussions/33634",
|
"devdev": "NEXT_PUBLIC_FIREBASE_ENV=DEV concurrently -n NEXT,TS -c magenta,cyan \"FIREBASE_ENV=DEV next dev -p 3000\" \"FIREBASE_ENV=DEV yarn ts --watch\" # see https://github.com/vercel/next.js/discussions/33634",
|
||||||
"dev:dev": "yarn devdev",
|
"dev:dev": "yarn devdev",
|
||||||
"dev:the": "NEXT_PUBLIC_FIREBASE_ENV=THEOREMONE concurrently -n NEXT,TS -c magenta,cyan \"FIREBASE_ENV=THEOREMONE next dev -p 3000\" \"FIREBASE_ENV=THEOREMONE yarn ts --watch\"",
|
"dev:the": "NEXT_PUBLIC_FIREBASE_ENV=THEOREMONE concurrently -n NEXT,TS -c magenta,cyan \"FIREBASE_ENV=THEOREMONE next dev -p 3000\" \"FIREBASE_ENV=THEOREMONE yarn ts --watch\"",
|
||||||
|
"dev:emulate": "NEXT_PUBLIC_FIREBASE_EMULATE=TRUE yarn devdev",
|
||||||
"ts": "tsc --noEmit --incremental --preserveWatchOutput --pretty",
|
"ts": "tsc --noEmit --incremental --preserveWatchOutput --pretty",
|
||||||
"build": "next build",
|
"build": "next build",
|
||||||
"start": "next start",
|
"start": "next start",
|
||||||
|
@ -52,7 +53,7 @@
|
||||||
"pretty-quick": "3.1.2",
|
"pretty-quick": "3.1.2",
|
||||||
"tailwindcss": "3.0.1",
|
"tailwindcss": "3.0.1",
|
||||||
"tsc-files": "1.1.3",
|
"tsc-files": "1.1.3",
|
||||||
"typescript": "4.5.2"
|
"typescript": "4.5.3"
|
||||||
},
|
},
|
||||||
"lint-staged": {
|
"lint-staged": {
|
||||||
"*.{ts,tsx}": "tsc-files --noEmit --incremental false"
|
"*.{ts,tsx}": "tsc-files --noEmit --incremental false"
|
||||||
|
|
|
@ -15,6 +15,10 @@
|
||||||
"jsx": "preserve",
|
"jsx": "preserve",
|
||||||
"incremental": true
|
"incremental": true
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"watchOptions": {
|
||||||
|
"excludeDirectories": [".next"]
|
||||||
|
},
|
||||||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "../common/**/*.ts"],
|
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "../common/**/*.ts"],
|
||||||
"exclude": ["node_modules", ".next"]
|
"exclude": ["node_modules"]
|
||||||
}
|
}
|
||||||
|
|
4905
web/yarn.lock
4905
web/yarn.lock
File diff suppressed because it is too large
Load Diff
|
@ -5193,11 +5193,6 @@ typedarray-to-buffer@^3.1.5:
|
||||||
dependencies:
|
dependencies:
|
||||||
is-typedarray "^1.0.0"
|
is-typedarray "^1.0.0"
|
||||||
|
|
||||||
typescript@4.5.2:
|
|
||||||
version "4.5.2"
|
|
||||||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.5.2.tgz#8ac1fba9f52256fdb06fb89e4122fa6a346c2998"
|
|
||||||
integrity sha512-5BlMof9H1yGt0P8/WF+wPNw6GfctgGjXp5hkblpyT+8rkASSmkUKMXrxR0Xg8ThVCi/JnHQiKXeBaEwCeQwMFw==
|
|
||||||
|
|
||||||
typescript@4.5.3:
|
typescript@4.5.3:
|
||||||
version "4.5.3"
|
version "4.5.3"
|
||||||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.5.3.tgz#afaa858e68c7103317d89eb90c5d8906268d353c"
|
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.5.3.tgz#afaa858e68c7103317d89eb90c5d8906268d353c"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user