From 3ee03ffcba7d3c075da2551b70fbfcccb25b482a Mon Sep 17 00:00:00 2001 From: mantikoros Date: Wed, 15 Dec 2021 12:12:47 -0600 Subject: [PATCH] bet panel: error handling --- web/components/bet-panel.tsx | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/web/components/bet-panel.tsx b/web/components/bet-panel.tsx index 3ea8d163..13f5068d 100644 --- a/web/components/bet-panel.tsx +++ b/web/components/bet-panel.tsx @@ -63,12 +63,18 @@ export function BetPanel(props: { contract: Contract; className?: string }) { amount: betAmount, outcome: betChoice, contractId: contract.id, - }) + }).then(r => r.data as any) + console.log('placed bet. Result:', result) - setIsSubmitting(false) - setWasSubmitted(true) - setBetAmount(undefined) + if (result?.status === 'success') { + setIsSubmitting(false) + setWasSubmitted(true) + setBetAmount(undefined) + } else { + setError(result?.error || 'Error placing bet') + setIsSubmitting(false) + } } const betDisabled = isSubmitting || !betAmount || error @@ -144,8 +150,8 @@ export function BetPanel(props: { contract: Contract; className?: string }) { betDisabled ? 'btn-disabled' : betChoice === 'YES' - ? 'btn-primary' - : 'bg-red-400 hover:bg-red-500 border-none', + ? 'btn-primary' + : 'bg-red-400 hover:bg-red-500 border-none', isSubmitting ? 'loading' : '' )} onClick={betDisabled ? undefined : submitBet}