diff --git a/common/antes.ts b/common/antes.ts
index 0b7cb1b3..e2c7028c 100644
--- a/common/antes.ts
+++ b/common/antes.ts
@@ -3,7 +3,8 @@ import { getProbability } from './calculate'
import { Contract } from './contract'
import { User } from './user'
-export const PHANTOM_ANTE = 200
+export const PHANTOM_ANTE = 100
+export const MINIMUM_ANTE = 10
export const calcStartPool = (initialProbInt: number, ante = 0) => {
const p = initialProbInt / 100.0
diff --git a/functions/src/create-contract.ts b/functions/src/create-contract.ts
index 779b38d4..e588f42b 100644
--- a/functions/src/create-contract.ts
+++ b/functions/src/create-contract.ts
@@ -6,7 +6,7 @@ import { Contract } from '../../common/contract'
import { slugify } from '../../common/util/slugify'
import { randomString } from '../../common/util/random-string'
import { getNewContract } from '../../common/new-contract'
-import { getAnteBets } from '../../common/antes'
+import { getAnteBets, MINIMUM_ANTE } from '../../common/antes'
export const createContract = functions
.runWith({ minInstances: 1 })
@@ -32,9 +32,15 @@ export const createContract = functions
if (!question || !initialProb)
return { status: 'error', message: 'Missing contract attributes' }
+ if (initialProb < 1 || initialProb > 99)
+ return { status: 'error', message: 'Invalid initial probability' }
+
if (
- ante !== undefined &&
- (ante < 0 || ante > creator.balance || isNaN(ante) || !isFinite(ante))
+ ante === undefined ||
+ ante < MINIMUM_ANTE ||
+ ante > creator.balance ||
+ isNaN(ante) ||
+ !isFinite(ante)
)
return { status: 'error', message: 'Invalid ante' }
diff --git a/web/components/amount-input.tsx b/web/components/amount-input.tsx
index 205c68b6..ccbce060 100644
--- a/web/components/amount-input.tsx
+++ b/web/components/amount-input.tsx
@@ -10,6 +10,7 @@ export function AmountInput(props: {
onChange: (newAmount: number | undefined) => void
error: string | undefined
setError: (error: string | undefined) => void
+ minimumAmount?: number
disabled?: boolean
className?: string
inputClassName?: string
@@ -22,6 +23,7 @@ export function AmountInput(props: {
disabled,
className,
inputClassName,
+ minimumAmount,
} = props
const user = useUser()
@@ -33,11 +35,16 @@ export function AmountInput(props: {
onChange(str ? amount : undefined)
- if (user && user.balance < amount) setError('Insufficient balance')
- else setError(undefined)
+ if (user && user.balance < amount) {
+ setError('Insufficient balance')
+ } else if (minimumAmount && amount < minimumAmount) {
+ setError('Minimum amount: ' + formatMoney(minimumAmount))
+ } else {
+ setError(undefined)
+ }
}
- const remainingBalance = (user?.balance ?? 0) - (amount ?? 0)
+ const remainingBalance = Math.max(0, (user?.balance ?? 0) - (amount ?? 0))
return (
@@ -57,22 +64,22 @@ export function AmountInput(props: {
onChange={(e) => onAmountChange(e.target.value)}
/>
- {user &&
- (error ? (
-
- {error}
+ {error && (
+
+ {error}
+
+ )}
+ {user && (
+
+
+ Remaining balance
- ) : (
-
-
- Remaining balance
-
-
- {formatMoney(Math.floor(remainingBalance))}
- {user.balance !== 1000 && }
-
-
- ))}
+
+ {formatMoney(Math.floor(remainingBalance))}
+ {user.balance !== 1000 && }
+
+
+ )}
)
}
diff --git a/web/pages/create.tsx b/web/pages/create.tsx
index 7cb0f6e1..d25612c4 100644
--- a/web/pages/create.tsx
+++ b/web/pages/create.tsx
@@ -9,10 +9,10 @@ import { Title } from '../components/title'
import { useUser } from '../hooks/use-user'
import { Contract, contractPath } from '../lib/firebase/contracts'
import { Page } from '../components/page'
-import { AdvancedPanel } from '../components/advanced-panel'
import { createContract } from '../lib/firebase/api-call'
import { Row } from '../components/layout/row'
import { AmountInput } from '../components/amount-input'
+import { MINIMUM_ANTE } from '../../common/antes'
// Allow user to create a new contract
export default function NewContract() {
@@ -23,8 +23,7 @@ export default function NewContract() {
}, [creator])
useEffect(() => {
- // warm up function
- createContract({}).catch()
+ createContract({}).catch() // warm up function
}, [])
const [initialProb, setInitialProb] = useState(50)
@@ -32,6 +31,13 @@ export default function NewContract() {
const [description, setDescription] = useState('')
const [ante, setAnte] = useState
(undefined)
+ useEffect(() => {
+ if (creator) {
+ const initialAnte = creator.balance < 100 ? 10 : 100
+ setAnte(initialAnte)
+ }
+ }, [creator])
+
const [anteError, setAnteError] = useState()
const [closeDate, setCloseDate] = useState('')
@@ -41,14 +47,15 @@ export default function NewContract() {
// We'd like this to look like "Apr 2, 2022, 23:59:59 PM PT" but timezones are hard with dayjs
const formattedCloseTime = closeTime ? new Date(closeTime).toString() : ''
- const user = useUser()
- const remainingBalance = (user?.balance || 0) - (ante || 0)
+ const remainingBalance = (creator?.balance || 0) - (ante || 0)
const isValid =
initialProb > 0 &&
initialProb < 100 &&
question.length > 0 &&
- (ante === undefined || (ante >= 0 && ante <= remainingBalance)) &&
+ ante !== undefined &&
+ ante >= MINIMUM_ANTE &&
+ ante <= remainingBalance &&
// If set, closeTime must be in the future
closeTime &&
closeTime > Date.now()
@@ -76,7 +83,7 @@ export default function NewContract() {
}
// const descriptionPlaceholder = `e.g. This market will resolve to “Yes” if, by June 2, 2021, 11:59:59 PM ET, Paxlovid (also known under PF-07321332)...`
- const descriptionPlaceholder = `(Optional) Provide more detail on how you will resolve this market.`
+ const descriptionPlaceholder = `Provide more detail on how you will resolve this market. (Optional)`
if (!creator) return <>>
@@ -84,7 +91,7 @@ export default function NewContract() {
-
+
{/* Create a Tailwind form that takes in all the fields needed for a new contract */}
{/* When the form is submitted, create a new contract in the database */}