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 onChange: (newAmount: number | undefined) => void
error: string | undefined error: string | undefined
setError: (error: string | undefined) => void setError: (error: string | undefined) => void
contractId: string | undefined contractIdForLoan: string | undefined
minimumAmount?: number minimumAmount?: number
disabled?: boolean disabled?: boolean
className?: string className?: string
@ -27,7 +27,7 @@ export function AmountInput(props: {
onChange, onChange,
error, error,
setError, setError,
contractId, contractIdForLoan,
disabled, disabled,
className, className,
inputClassName, inputClassName,
@ -37,14 +37,13 @@ export function AmountInput(props: {
const user = useUser() 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 openUserBets = userBets.filter((bet) => !bet.isSold && !bet.sale)
const prevLoanAmount = _.sumBy(openUserBets, (bet) => bet.loanAmount ?? 0) const prevLoanAmount = _.sumBy(openUserBets, (bet) => bet.loanAmount ?? 0)
const loanAmount = Math.min( const loanAmount = contractIdForLoan
amount ?? 0, ? Math.min(amount ?? 0, MAX_LOAN_PER_CONTRACT - prevLoanAmount)
MAX_LOAN_PER_CONTRACT - prevLoanAmount : 0
)
const onAmountChange = (str: string) => { const onAmountChange = (str: string) => {
if (str.includes('-')) { if (str.includes('-')) {
@ -99,7 +98,7 @@ export function AmountInput(props: {
)} )}
{user && ( {user && (
<Col className="gap-3 text-sm"> <Col className="gap-3 text-sm">
{contractId && ( {contractIdForLoan && (
<Row className="items-center justify-between gap-2 text-gray-500"> <Row className="items-center justify-between gap-2 text-gray-500">
<Row className="items-center gap-2"> <Row className="items-center gap-2">
Amount loaned{' '} Amount loaned{' '}

View File

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

View File

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

View File

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

View File

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

View File

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