Point client at new v2 versions of createmarket
and placebet
(#433)
* Kill 'warmup spam' for createContract and placeBet * Point v2 function calls at v2 endpoints * Add real prod placebet and createmarket endpoints
This commit is contained in:
parent
13826b5759
commit
d9eb9798e5
|
@ -12,4 +12,8 @@ export const DEV_CONFIG: EnvConfig = {
|
||||||
appId: '1:134303100058:web:27f9ea8b83347251f80323',
|
appId: '1:134303100058:web:27f9ea8b83347251f80323',
|
||||||
measurementId: 'G-YJC9E37P37',
|
measurementId: 'G-YJC9E37P37',
|
||||||
},
|
},
|
||||||
|
functionEndpoints: {
|
||||||
|
placebet: 'https://placebet-w3txbmd3ba-uc.a.run.app',
|
||||||
|
createmarket: 'https://createmarket-w3txbmd3ba-uc.a.run.app',
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
|
export type V2CloudFunction = 'placebet' | 'createmarket'
|
||||||
|
|
||||||
export type EnvConfig = {
|
export type EnvConfig = {
|
||||||
domain: string
|
domain: string
|
||||||
firebaseConfig: FirebaseConfig
|
firebaseConfig: FirebaseConfig
|
||||||
|
functionEndpoints: Record<V2CloudFunction, string>
|
||||||
|
|
||||||
// Access controls
|
// Access controls
|
||||||
adminEmails: string[]
|
adminEmails: string[]
|
||||||
|
@ -37,6 +40,10 @@ export const PROD_CONFIG: EnvConfig = {
|
||||||
appId: '1:128925704902:web:f61f86944d8ffa2a642dc7',
|
appId: '1:128925704902:web:f61f86944d8ffa2a642dc7',
|
||||||
measurementId: 'G-SSFK1Q138D',
|
measurementId: 'G-SSFK1Q138D',
|
||||||
},
|
},
|
||||||
|
functionEndpoints: {
|
||||||
|
placebet: 'https://placebet-nggbo3neva-uc.a.run.app',
|
||||||
|
createmarket: 'https://createmarket-nggbo3neva-uc.a.run.app',
|
||||||
|
},
|
||||||
adminEmails: [
|
adminEmails: [
|
||||||
'akrolsmir@gmail.com', // Austin
|
'akrolsmir@gmail.com', // Austin
|
||||||
'jahooma@gmail.com', // James
|
'jahooma@gmail.com', // James
|
||||||
|
|
|
@ -12,6 +12,11 @@ export const THEOREMONE_CONFIG: EnvConfig = {
|
||||||
appId: '1:698012149198:web:b342af75662831aa84b79f',
|
appId: '1:698012149198:web:b342af75662831aa84b79f',
|
||||||
measurementId: 'G-Y3EZ1WNT6E',
|
measurementId: 'G-Y3EZ1WNT6E',
|
||||||
},
|
},
|
||||||
|
// TODO: fill in real endpoints for T1
|
||||||
|
functionEndpoints: {
|
||||||
|
placebet: 'https://placebet-nggbo3neva-uc.a.run.app',
|
||||||
|
createmarket: 'https://createmarket-nggbo3neva-uc.a.run.app',
|
||||||
|
},
|
||||||
adminEmails: [...PROD_CONFIG.adminEmails, 'david.glidden@theoremone.co'],
|
adminEmails: [...PROD_CONFIG.adminEmails, 'david.glidden@theoremone.co'],
|
||||||
whitelistEmail: '@theoremone.co',
|
whitelistEmail: '@theoremone.co',
|
||||||
moneyMoniker: 'T$',
|
moneyMoniker: 'T$',
|
||||||
|
|
|
@ -202,11 +202,6 @@ function BuyPanel(props: {
|
||||||
|
|
||||||
const [inputRef, focusAmountInput] = useFocus()
|
const [inputRef, focusAmountInput] = useFocus()
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
// warm up cloud function
|
|
||||||
placeBet({}).catch(() => {})
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (selected) focusAmountInput()
|
if (selected) focusAmountInput()
|
||||||
}, [selected, focusAmountInput])
|
}, [selected, focusAmountInput])
|
||||||
|
|
|
@ -2,6 +2,7 @@ import { NextApiRequest, NextApiResponse } from 'next'
|
||||||
import { promisify } from 'util'
|
import { promisify } from 'util'
|
||||||
import { pipeline } from 'stream'
|
import { pipeline } from 'stream'
|
||||||
import { getFunctionUrl } from 'web/lib/firebase/api-call'
|
import { getFunctionUrl } from 'web/lib/firebase/api-call'
|
||||||
|
import { V2CloudFunction } from 'common/envs/prod'
|
||||||
import fetch, { Headers, Response } from 'node-fetch'
|
import fetch, { Headers, Response } from 'node-fetch'
|
||||||
|
|
||||||
function getProxiedRequestHeaders(req: NextApiRequest, whitelist: string[]) {
|
function getProxiedRequestHeaders(req: NextApiRequest, whitelist: string[]) {
|
||||||
|
@ -32,8 +33,8 @@ function getProxiedResponseHeaders(res: Response, whitelist: string[]) {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
export const fetchBackend = (req: NextApiRequest, endpoint: string) => {
|
export const fetchBackend = (req: NextApiRequest, name: V2CloudFunction) => {
|
||||||
const url = getFunctionUrl(endpoint)
|
const url = getFunctionUrl(name)
|
||||||
const headers = getProxiedRequestHeaders(req, [
|
const headers = getProxiedRequestHeaders(req, [
|
||||||
'Authorization',
|
'Authorization',
|
||||||
'Content-Length',
|
'Content-Length',
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { auth } from './users'
|
import { auth } from './users'
|
||||||
import { FIREBASE_CONFIG } from 'common/envs/constants'
|
import { ENV_CONFIG } from 'common/envs/constants'
|
||||||
|
import { V2CloudFunction } from 'common/envs/prod'
|
||||||
|
|
||||||
export class APIError extends Error {
|
export class APIError extends Error {
|
||||||
code: number
|
code: number
|
||||||
|
@ -38,17 +39,14 @@ export async function call(url: string, method: string, params: any) {
|
||||||
// app just hit the cloud functions directly -- there's no difference and it's
|
// app just hit the cloud functions directly -- there's no difference and it's
|
||||||
// one less hop
|
// one less hop
|
||||||
|
|
||||||
export function getFunctionUrl(name: string) {
|
export function getFunctionUrl(name: V2CloudFunction) {
|
||||||
const { projectId, region } = FIREBASE_CONFIG
|
return ENV_CONFIG.functionEndpoints[name]
|
||||||
return process.env.NEXT_PUBLIC_FIREBASE_EMULATE
|
|
||||||
? `http://localhost:5001/${projectId}/${region}/${name}`
|
|
||||||
: `https://${region}-${projectId}.cloudfunctions.net/${name}`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createContract(params: any) {
|
export function createMarket(params: any) {
|
||||||
return call(getFunctionUrl('createContract'), 'POST', params)
|
return call(getFunctionUrl('createmarket'), 'POST', params)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function placeBet(params: any) {
|
export function placeBet(params: any) {
|
||||||
return call(getFunctionUrl('placeBet'), 'POST', params)
|
return call(getFunctionUrl('placebet'), 'POST', params)
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ export default async function route(req: NextApiRequest, res: NextApiResponse) {
|
||||||
methods: 'POST',
|
methods: 'POST',
|
||||||
})
|
})
|
||||||
try {
|
try {
|
||||||
const backendRes = await fetchBackend(req, 'placeBet')
|
const backendRes = await fetchBackend(req, 'placebet')
|
||||||
await forwardResponse(res, backendRes)
|
await forwardResponse(res, backendRes)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Error talking to cloud function: ', err)
|
console.error('Error talking to cloud function: ', err)
|
||||||
|
|
|
@ -14,7 +14,7 @@ export default async function route(req: NextApiRequest, res: NextApiResponse) {
|
||||||
methods: 'POST',
|
methods: 'POST',
|
||||||
})
|
})
|
||||||
try {
|
try {
|
||||||
const backendRes = await fetchBackend(req, 'createContract')
|
const backendRes = await fetchBackend(req, 'createmarket')
|
||||||
await forwardResponse(res, backendRes)
|
await forwardResponse(res, backendRes)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Error talking to cloud function: ', err)
|
console.error('Error talking to cloud function: ', err)
|
||||||
|
|
|
@ -6,7 +6,7 @@ import Textarea from 'react-expanding-textarea'
|
||||||
import { Spacer } from 'web/components/layout/spacer'
|
import { Spacer } from 'web/components/layout/spacer'
|
||||||
import { useUser } from 'web/hooks/use-user'
|
import { useUser } from 'web/hooks/use-user'
|
||||||
import { Contract, contractPath } from 'web/lib/firebase/contracts'
|
import { Contract, contractPath } from 'web/lib/firebase/contracts'
|
||||||
import { createContract } from 'web/lib/firebase/api-call'
|
import { createMarket } from 'web/lib/firebase/api-call'
|
||||||
import { FIXED_ANTE, MINIMUM_ANTE } from 'common/antes'
|
import { FIXED_ANTE, MINIMUM_ANTE } from 'common/antes'
|
||||||
import { InfoTooltip } from 'web/components/info-tooltip'
|
import { InfoTooltip } from 'web/components/info-tooltip'
|
||||||
import { Page } from 'web/components/page'
|
import { Page } from 'web/components/page'
|
||||||
|
@ -64,10 +64,6 @@ export function NewContract(props: { question: string; tag?: string }) {
|
||||||
if (creator === null) router.push('/')
|
if (creator === null) router.push('/')
|
||||||
}, [creator])
|
}, [creator])
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
createContract({}).catch(() => {}) // warm up function
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
const [outcomeType, setOutcomeType] = useState<outcomeType>('BINARY')
|
const [outcomeType, setOutcomeType] = useState<outcomeType>('BINARY')
|
||||||
const [initialProb, setInitialProb] = useState(50)
|
const [initialProb, setInitialProb] = useState(50)
|
||||||
const [minString, setMinString] = useState('')
|
const [minString, setMinString] = useState('')
|
||||||
|
@ -141,7 +137,7 @@ export function NewContract(props: { question: string; tag?: string }) {
|
||||||
setIsSubmitting(true)
|
setIsSubmitting(true)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await createContract(
|
const result = await createMarket(
|
||||||
removeUndefinedProps({
|
removeUndefinedProps({
|
||||||
question,
|
question,
|
||||||
outcomeType,
|
outcomeType,
|
||||||
|
|
|
@ -16,7 +16,7 @@ import { Linkify } from 'web/components/linkify'
|
||||||
import { Page } from 'web/components/page'
|
import { Page } from 'web/components/page'
|
||||||
import { Title } from 'web/components/title'
|
import { Title } from 'web/components/title'
|
||||||
import { useUser } from 'web/hooks/use-user'
|
import { useUser } from 'web/hooks/use-user'
|
||||||
import { createContract } from 'web/lib/firebase/api-call'
|
import { createMarket } from 'web/lib/firebase/api-call'
|
||||||
import { contractPath } from 'web/lib/firebase/contracts'
|
import { contractPath } from 'web/lib/firebase/contracts'
|
||||||
|
|
||||||
type Prediction = {
|
type Prediction = {
|
||||||
|
@ -138,7 +138,7 @@ ${TEST_VALUE}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createContracts() {
|
async function createMarkets() {
|
||||||
if (!user) {
|
if (!user) {
|
||||||
// TODO: Convey error with snackbar/toast
|
// TODO: Convey error with snackbar/toast
|
||||||
console.error('You need to be signed in!')
|
console.error('You need to be signed in!')
|
||||||
|
@ -146,7 +146,7 @@ ${TEST_VALUE}
|
||||||
}
|
}
|
||||||
setIsSubmitting(true)
|
setIsSubmitting(true)
|
||||||
for (const prediction of predictions) {
|
for (const prediction of predictions) {
|
||||||
const contract = (await createContract({
|
const contract = (await createMarket({
|
||||||
question: prediction.question,
|
question: prediction.question,
|
||||||
description: prediction.description,
|
description: prediction.description,
|
||||||
initialProb: prediction.initialProb,
|
initialProb: prediction.initialProb,
|
||||||
|
@ -270,7 +270,7 @@ ${TEST_VALUE}
|
||||||
disabled={predictions.length === 0 || isSubmitting}
|
disabled={predictions.length === 0 || isSubmitting}
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
createContracts()
|
createMarkets()
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Create all
|
Create all
|
||||||
|
|
Loading…
Reference in New Issue
Block a user