bug fix: use new placeBet api in numeric bet panel
This commit is contained in:
parent
4c7836abc7
commit
99c41b6112
|
@ -1,16 +1,17 @@
|
||||||
import clsx from 'clsx'
|
import clsx from 'clsx'
|
||||||
import { getNumericBetsInfo } from 'common/new-bet'
|
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
|
|
||||||
import { Bet } from '../../common/bet'
|
import { getNumericBetsInfo } from 'common/new-bet'
|
||||||
|
import { Bet } from 'common/bet'
|
||||||
import {
|
import {
|
||||||
calculatePayoutAfterCorrectBet,
|
calculatePayoutAfterCorrectBet,
|
||||||
getOutcomeProbability,
|
getOutcomeProbability,
|
||||||
} from '../../common/calculate'
|
} from 'common/calculate'
|
||||||
import { NumericContract } from '../../common/contract'
|
import { NumericContract } from 'common/contract'
|
||||||
import { formatPercent, formatMoney } from '../../common/util/format'
|
import { formatPercent, formatMoney } from 'common/util/format'
|
||||||
|
|
||||||
import { useUser } from '../hooks/use-user'
|
import { useUser } from '../hooks/use-user'
|
||||||
import { placeBet } from '../lib/firebase/api-call'
|
import { APIError, placeBet } from '../lib/firebase/api-call'
|
||||||
import { firebaseLogin, User } from '../lib/firebase/users'
|
import { firebaseLogin, User } from '../lib/firebase/users'
|
||||||
import { BuyAmountInput } from './amount-input'
|
import { BuyAmountInput } from './amount-input'
|
||||||
import { BucketInput } from './bucket-input'
|
import { BucketInput } from './bucket-input'
|
||||||
|
@ -80,24 +81,28 @@ function NumericBuyPanel(props: {
|
||||||
setError(undefined)
|
setError(undefined)
|
||||||
setIsSubmitting(true)
|
setIsSubmitting(true)
|
||||||
|
|
||||||
const result = await placeBet({
|
await placeBet({
|
||||||
amount: betAmount,
|
amount: betAmount,
|
||||||
outcome: bucketChoice,
|
outcome: bucketChoice,
|
||||||
value,
|
value,
|
||||||
contractId: contract.id,
|
contractId: contract.id,
|
||||||
}).then((r) => r.data as any)
|
})
|
||||||
|
.then((r) => {
|
||||||
console.log('placed bet. Result:', result)
|
console.log('placed bet. Result:', r)
|
||||||
|
setIsSubmitting(false)
|
||||||
if (result?.status === 'success') {
|
setWasSubmitted(true)
|
||||||
setIsSubmitting(false)
|
setBetAmount(undefined)
|
||||||
setWasSubmitted(true)
|
if (onBuySuccess) onBuySuccess()
|
||||||
setBetAmount(undefined)
|
})
|
||||||
if (onBuySuccess) onBuySuccess()
|
.catch((e) => {
|
||||||
} else {
|
if (e instanceof APIError) {
|
||||||
setError(result?.message || 'Error placing bet')
|
setError(e.toString())
|
||||||
setIsSubmitting(false)
|
} else {
|
||||||
}
|
console.error(e)
|
||||||
|
setError('Error placing bet')
|
||||||
|
}
|
||||||
|
setIsSubmitting(false)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const betDisabled = isSubmitting || !betAmount || !bucketChoice || error
|
const betDisabled = isSubmitting || !betAmount || !bucketChoice || error
|
||||||
|
|
Loading…
Reference in New Issue
Block a user