From 2fe71731e44d851dd2e80b994d52ac5b1c7b8d72 Mon Sep 17 00:00:00 2001
From: mantikoros <sgrugett@gmail.com>
Date: Sat, 9 Apr 2022 13:51:22 -0500
Subject: [PATCH] create: fixed ante of $100

---
 common/antes.ts                  |  3 +++
 common/calculate.ts              |  2 +-
 functions/src/create-contract.ts |  5 +++-
 web/pages/create.tsx             | 42 ++++++++++++++++++++++----------
 4 files changed, 37 insertions(+), 15 deletions(-)

diff --git a/common/antes.ts b/common/antes.ts
index 6a0c0946..a443f508 100644
--- a/common/antes.ts
+++ b/common/antes.ts
@@ -5,6 +5,9 @@ import { User } from './user'
 import { LiquidityProvision } from './liquidity-provision'
 import { noFees } from './fees'
 
+export const FIXED_ANTE = 100
+
+// deprecated
 export const PHANTOM_ANTE = 0.001
 export const MINIMUM_ANTE = 50
 
diff --git a/common/calculate.ts b/common/calculate.ts
index 361606e4..4adecb54 100644
--- a/common/calculate.ts
+++ b/common/calculate.ts
@@ -1,4 +1,4 @@
-import _ from 'lodash'
+import * as _ from 'lodash'
 import { Bet } from './bet'
 import {
   calculateCpmmSale,
diff --git a/functions/src/create-contract.ts b/functions/src/create-contract.ts
index 85bc211d..16a416b1 100644
--- a/functions/src/create-contract.ts
+++ b/functions/src/create-contract.ts
@@ -19,6 +19,7 @@ import { slugify } from '../../common/util/slugify'
 import { randomString } from '../../common/util/random'
 import { getNewContract } from '../../common/new-contract'
 import {
+  FIXED_ANTE,
   getAnteBets,
   getCpmmInitialLiquidity,
   getFreeAnswerAnte,
@@ -47,7 +48,7 @@ export const createContract = functions
       const creator = await getUser(userId)
       if (!creator) return { status: 'error', message: 'User not found' }
 
-      let { question, description, initialProb, ante, closeTime, tags } = data
+      let { question, description, initialProb, closeTime, tags } = data
 
       if (!question || typeof question != 'string')
         return { status: 'error', message: 'Missing or invalid question field' }
@@ -71,6 +72,8 @@ export const createContract = functions
       )
         return { status: 'error', message: 'Invalid initial probability' }
 
+      const ante = FIXED_ANTE // data.ante
+
       if (
         ante === undefined ||
         ante < MINIMUM_ANTE ||
diff --git a/web/pages/create.tsx b/web/pages/create.tsx
index 4092e97e..e5a295af 100644
--- a/web/pages/create.tsx
+++ b/web/pages/create.tsx
@@ -9,7 +9,7 @@ import { useUser } from '../hooks/use-user'
 import { Contract, contractPath } from '../lib/firebase/contracts'
 import { createContract } from '../lib/firebase/api-call'
 import { BuyAmountInput } from '../components/amount-input'
-import { MINIMUM_ANTE } from '../../common/antes'
+import { FIXED_ANTE, MINIMUM_ANTE } from '../../common/antes'
 import { InfoTooltip } from '../components/info-tooltip'
 import { CREATOR_FEE } from '../../common/fees'
 import { Page } from '../components/page'
@@ -19,6 +19,7 @@ import { parseWordsAsTags } from '../../common/util/parse'
 import { TagsList } from '../components/tags-list'
 import { Row } from '../components/layout/row'
 import { MAX_DESCRIPTION_LENGTH, outcomeType } from '../../common/contract'
+import { formatMoney } from '../../common/util/format'
 
 export default function Create() {
   const [question, setQuestion] = useState('')
@@ -69,15 +70,15 @@ export function NewContract(props: { question: string; tag?: string }) {
   const [tagText, setTagText] = useState<string>(tag ?? '')
   const tags = parseWordsAsTags(tagText)
 
-  const [ante, setAnte] = useState<number | undefined | null>(null)
-  useEffect(() => {
-    if (ante === null && creator) {
-      const initialAnte = creator.balance < 100 ? MINIMUM_ANTE : 100
-      setAnte(initialAnte)
-    }
-  }, [ante, creator])
+  const [ante, setAnte] = useState(FIXED_ANTE)
+  // useEffect(() => {
+  //   if (ante === null && creator) {
+  //     const initialAnte = creator.balance < 100 ? MINIMUM_ANTE : 100
+  //     setAnte(initialAnte)
+  //   }
+  // }, [ante, creator])
 
-  const [anteError, setAnteError] = useState<string | undefined>()
+  // const [anteError, setAnteError] = useState<string | undefined>()
   // By default, close the market a week from today
   const weekFromToday = dayjs().add(7, 'day').format('YYYY-MM-DDT23:59')
   const [closeDate, setCloseDate] = useState<undefined | string>(weekFromToday)
@@ -236,12 +237,27 @@ export function NewContract(props: { question: string; tag?: string }) {
 
       <div className="form-control mb-1 items-start">
         <label className="label mb-1 gap-2">
-          <span>Market subsidy</span>
+          <span>Cost</span>
           <InfoTooltip
-            text={`Provide liquidity to encourage traders to participate.`}
+            text={`Cost to create your market. This amount is used to subsidize trading.`}
           />
         </label>
-        <BuyAmountInput
+
+        <div className="label-text text-neutral pl-1">{formatMoney(ante)}</div>
+
+        {ante > balance && (
+          <div className="mb-2 mt-2 mr-auto self-center whitespace-nowrap text-xs font-medium tracking-wide">
+            <span className="mr-2 text-red-500">Insufficient balance</span>
+            <button
+              className="btn btn-xs btn-primary"
+              onClick={() => (window.location.href = '/add-funds')}
+            >
+              Add funds
+            </button>
+          </div>
+        )}
+
+        {/* <BuyAmountInput
           amount={ante ?? undefined}
           minimumAmount={MINIMUM_ANTE}
           onChange={setAnte}
@@ -249,7 +265,7 @@ export function NewContract(props: { question: string; tag?: string }) {
           setError={setAnteError}
           disabled={isSubmitting}
           contractIdForLoan={undefined}
-        />
+        /> */}
       </div>
 
       <Spacer h={4} />