From 6abf2355051424a4ddd7b095c9f8ea84d8a3c824 Mon Sep 17 00:00:00 2001 From: James Grugett Date: Wed, 2 Mar 2022 13:50:19 -0800 Subject: [PATCH] Show correct remaning balance for ante input when creating market --- web/components/amount-input.tsx | 15 +++++++-------- web/components/answers/answer-bet-panel.tsx | 2 +- web/components/answers/create-answer-panel.tsx | 2 +- web/components/bet-panel.tsx | 2 +- web/pages/create.tsx | 2 +- web/pages/make-predictions.tsx | 2 +- 6 files changed, 12 insertions(+), 13 deletions(-) diff --git a/web/components/amount-input.tsx b/web/components/amount-input.tsx index e36962a2..a29811e9 100644 --- a/web/components/amount-input.tsx +++ b/web/components/amount-input.tsx @@ -14,7 +14,7 @@ export function AmountInput(props: { onChange: (newAmount: number | undefined) => void error: string | undefined setError: (error: string | undefined) => void - contractId: string | undefined + contractIdForLoan: string | undefined minimumAmount?: number disabled?: boolean className?: string @@ -27,7 +27,7 @@ export function AmountInput(props: { onChange, error, setError, - contractId, + contractIdForLoan, disabled, className, inputClassName, @@ -37,14 +37,13 @@ export function AmountInput(props: { const user = useUser() - const userBets = useUserContractBets(user?.id, contractId) ?? [] + const userBets = useUserContractBets(user?.id, contractIdForLoan) ?? [] const openUserBets = userBets.filter((bet) => !bet.isSold && !bet.sale) const prevLoanAmount = _.sumBy(openUserBets, (bet) => bet.loanAmount ?? 0) - const loanAmount = Math.min( - amount ?? 0, - MAX_LOAN_PER_CONTRACT - prevLoanAmount - ) + const loanAmount = contractIdForLoan + ? Math.min(amount ?? 0, MAX_LOAN_PER_CONTRACT - prevLoanAmount) + : 0 const onAmountChange = (str: string) => { if (str.includes('-')) { @@ -99,7 +98,7 @@ export function AmountInput(props: { )} {user && ( - {contractId && ( + {contractIdForLoan && ( Amount loaned{' '} diff --git a/web/components/answers/answer-bet-panel.tsx b/web/components/answers/answer-bet-panel.tsx index 26939b35..d45bdc35 100644 --- a/web/components/answers/answer-bet-panel.tsx +++ b/web/components/answers/answer-bet-panel.tsx @@ -115,7 +115,7 @@ export function AnswerBetPanel(props: { setError={setError} disabled={isSubmitting} inputRef={inputRef} - contractId={contract.id} + contractIdForLoan={contract.id} /> diff --git a/web/components/answers/create-answer-panel.tsx b/web/components/answers/create-answer-panel.tsx index 2dbadd9e..3f0f5dee 100644 --- a/web/components/answers/create-answer-panel.tsx +++ b/web/components/answers/create-answer-panel.tsx @@ -101,7 +101,7 @@ export function CreateAnswerPanel(props: { contract: Contract }) { setError={setAmountError} minimumAmount={1} disabled={isSubmitting} - contractId={contract.id} + contractIdForLoan={contract.id} /> diff --git a/web/components/bet-panel.tsx b/web/components/bet-panel.tsx index 67f304c5..89594ae3 100644 --- a/web/components/bet-panel.tsx +++ b/web/components/bet-panel.tsx @@ -159,7 +159,7 @@ export function BetPanel(props: { setError={setError} disabled={isSubmitting} inputRef={inputRef} - contractId={contract.id} + contractIdForLoan={contract.id} /> diff --git a/web/pages/create.tsx b/web/pages/create.tsx index 76afa8d2..47ce00d4 100644 --- a/web/pages/create.tsx +++ b/web/pages/create.tsx @@ -248,7 +248,7 @@ export function NewContract(props: { question: string; tag?: string }) { error={anteError} setError={setAnteError} disabled={isSubmitting} - contractId={undefined} + contractIdForLoan={undefined} /> diff --git a/web/pages/make-predictions.tsx b/web/pages/make-predictions.tsx index 37872c39..eceb692a 100644 --- a/web/pages/make-predictions.tsx +++ b/web/pages/make-predictions.tsx @@ -245,7 +245,7 @@ ${TEST_VALUE} error={anteError} setError={setAnteError} disabled={isSubmitting} - contractId={undefined} + contractIdForLoan={undefined} />