Show correct remaning balance for ante input when creating market

This commit is contained in:
James Grugett 2022-03-02 13:50:19 -08:00
parent 2a03751d49
commit 6abf235505
6 changed files with 12 additions and 13 deletions

View File

@ -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 && (
<Col className="gap-3 text-sm">
{contractId && (
{contractIdForLoan && (
<Row className="items-center justify-between gap-2 text-gray-500">
<Row className="items-center gap-2">
Amount loaned{' '}

View File

@ -115,7 +115,7 @@ export function AnswerBetPanel(props: {
setError={setError}
disabled={isSubmitting}
inputRef={inputRef}
contractId={contract.id}
contractIdForLoan={contract.id}
/>
<Col className="gap-3 mt-3 w-full">
<Row className="justify-between items-center text-sm">

View File

@ -101,7 +101,7 @@ export function CreateAnswerPanel(props: { contract: Contract }) {
setError={setAmountError}
minimumAmount={1}
disabled={isSubmitting}
contractId={contract.id}
contractIdForLoan={contract.id}
/>
</Col>
<Col className="gap-3">

View File

@ -159,7 +159,7 @@ export function BetPanel(props: {
setError={setError}
disabled={isSubmitting}
inputRef={inputRef}
contractId={contract.id}
contractIdForLoan={contract.id}
/>
<Col className="gap-3 mt-3 w-full">

View File

@ -248,7 +248,7 @@ export function NewContract(props: { question: string; tag?: string }) {
error={anteError}
setError={setAnteError}
disabled={isSubmitting}
contractId={undefined}
contractIdForLoan={undefined}
/>
</div>

View File

@ -245,7 +245,7 @@ ${TEST_VALUE}
error={anteError}
setError={setAnteError}
disabled={isSubmitting}
contractId={undefined}
contractIdForLoan={undefined}
/>
</div>