From 99c41b6112ad81c9bdb7b59bba5701fd4ac4e8cd Mon Sep 17 00:00:00 2001 From: mantikoros Date: Thu, 19 May 2022 20:39:15 -0400 Subject: [PATCH] bug fix: use new placeBet api in numeric bet panel --- web/components/numeric-bet-panel.tsx | 45 +++++++++++++++------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/web/components/numeric-bet-panel.tsx b/web/components/numeric-bet-panel.tsx index ba25c411..20478e25 100644 --- a/web/components/numeric-bet-panel.tsx +++ b/web/components/numeric-bet-panel.tsx @@ -1,16 +1,17 @@ import clsx from 'clsx' -import { getNumericBetsInfo } from 'common/new-bet' import { useState } from 'react' -import { Bet } from '../../common/bet' +import { getNumericBetsInfo } from 'common/new-bet' +import { Bet } from 'common/bet' import { calculatePayoutAfterCorrectBet, getOutcomeProbability, -} from '../../common/calculate' -import { NumericContract } from '../../common/contract' -import { formatPercent, formatMoney } from '../../common/util/format' +} from 'common/calculate' +import { NumericContract } from 'common/contract' +import { formatPercent, formatMoney } from 'common/util/format' + 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 { BuyAmountInput } from './amount-input' import { BucketInput } from './bucket-input' @@ -80,24 +81,28 @@ function NumericBuyPanel(props: { setError(undefined) setIsSubmitting(true) - const result = await placeBet({ + await placeBet({ amount: betAmount, outcome: bucketChoice, value, contractId: contract.id, - }).then((r) => r.data as any) - - console.log('placed bet. Result:', result) - - if (result?.status === 'success') { - setIsSubmitting(false) - setWasSubmitted(true) - setBetAmount(undefined) - if (onBuySuccess) onBuySuccess() - } else { - setError(result?.message || 'Error placing bet') - setIsSubmitting(false) - } + }) + .then((r) => { + console.log('placed bet. Result:', r) + setIsSubmitting(false) + setWasSubmitted(true) + setBetAmount(undefined) + if (onBuySuccess) onBuySuccess() + }) + .catch((e) => { + if (e instanceof APIError) { + setError(e.toString()) + } else { + console.error(e) + setError('Error placing bet') + } + setIsSubmitting(false) + }) } const betDisabled = isSubmitting || !betAmount || !bucketChoice || error