From cd1d8ecd8a9d3d1c3f3855271b489a1e9a9730fb Mon Sep 17 00:00:00 2001 From: mantikoros Date: Fri, 9 Sep 2022 01:02:22 -0500 Subject: [PATCH] WarningConfirmationButton for bets --- web/components/answers/answer-bet-panel.tsx | 39 +++++----- web/components/bet-panel.tsx | 42 ++++------- web/components/confirmation-button.tsx | 6 +- .../warning-confirmation-button.tsx | 74 +++++++++++++++++++ 4 files changed, 109 insertions(+), 52 deletions(-) create mode 100644 web/components/warning-confirmation-button.tsx diff --git a/web/components/answers/answer-bet-panel.tsx b/web/components/answers/answer-bet-panel.tsx index 6e54b3b8..f84ff1a3 100644 --- a/web/components/answers/answer-bet-panel.tsx +++ b/web/components/answers/answer-bet-panel.tsx @@ -26,7 +26,7 @@ import { Bet } from 'common/bet' import { track } from 'web/lib/service/analytics' import { BetSignUpPrompt } from '../sign-up-prompt' import { isIOS } from 'web/lib/util/device' -import { AlertBox } from '../alert-box' +import { WarningConfirmationButton } from '../warning-confirmation-button' export function AnswerBetPanel(props: { answer: Answer @@ -116,6 +116,15 @@ export function AnswerBetPanel(props: { const bankrollFraction = (betAmount ?? 0) / (user?.balance ?? 1e9) + const warning = + (betAmount ?? 0) > 10 && bankrollFraction >= 0.5 && bankrollFraction <= 1 + ? `You might not want to spend ${formatPercent( + bankrollFraction + )} of your balance on a single bet. \n\nCurrent balance: ${formatMoney( + user?.balance ?? 0 + )}` + : undefined + return ( @@ -148,21 +157,6 @@ export function AnswerBetPanel(props: { showSliderOnMobile /> - {(betAmount ?? 0) > 10 && - bankrollFraction >= 0.5 && - bankrollFraction <= 1 ? ( - - ) : ( - '' - )} -
Probability
@@ -198,16 +192,17 @@ export function AnswerBetPanel(props: { {user ? ( - + /> ) : ( )} diff --git a/web/components/bet-panel.tsx b/web/components/bet-panel.tsx index ce36cdf9..2dca328a 100644 --- a/web/components/bet-panel.tsx +++ b/web/components/bet-panel.tsx @@ -40,8 +40,8 @@ import { LimitBets } from './limit-bets' import { PillButton } from './buttons/pill-button' import { YesNoSelector } from './yes-no-selector' import { PlayMoneyDisclaimer } from './play-money-disclaimer' -import { AlertBox } from './alert-box' import { isAndroid, isIOS } from 'web/lib/util/device' +import { WarningConfirmationButton } from './warning-confirmation-button' export function BetPanel(props: { contract: CPMMBinaryContract | PseudoNumericContract @@ -271,25 +271,15 @@ function BuyPanel(props: { const bankrollFraction = (betAmount ?? 0) / (user?.balance ?? 1e9) const warning = - (betAmount ?? 0) > 10 && - bankrollFraction >= 0.5 && - bankrollFraction <= 1 ? ( - 10 && bankrollFraction >= 0.5 && bankrollFraction <= 1 + ? `You might not want to spend ${formatPercent( bankrollFraction )} of your balance on a single trade. \n\nCurrent balance: ${formatMoney( user?.balance ?? 0 - )}`} - /> - ) : (betAmount ?? 0) > 10 && probChange >= 0.3 && bankrollFraction <= 1 ? ( - - ) : ( - <> - ) + )}` + : (betAmount ?? 0) > 10 && probChange >= 0.3 && bankrollFraction <= 1 + ? `Are you sure you want to move the market by ${displayedDifference}?` + : undefined return ( @@ -322,8 +312,6 @@ function BuyPanel(props: { showSliderOnMobile /> - {warning} -
@@ -364,20 +352,20 @@ function BuyPanel(props: { {user && ( - + /> )} {wasSubmitted &&
Trade submitted!
} diff --git a/web/components/confirmation-button.tsx b/web/components/confirmation-button.tsx index bc014902..8dbe90c2 100644 --- a/web/components/confirmation-button.tsx +++ b/web/components/confirmation-button.tsx @@ -47,13 +47,13 @@ export function ConfirmationButton(props: { {children}
updateOpen(false)} > {cancelBtn?.label ?? 'Cancel'}
@@ -69,7 +69,7 @@ export function ConfirmationButton(props: {
updateOpen(true)} > {openModalBtn.icon} diff --git a/web/components/warning-confirmation-button.tsx b/web/components/warning-confirmation-button.tsx new file mode 100644 index 00000000..7b707098 --- /dev/null +++ b/web/components/warning-confirmation-button.tsx @@ -0,0 +1,74 @@ +import clsx from 'clsx' +import React from 'react' + +import { Row } from './layout/row' +import { ConfirmationButton } from './confirmation-button' +import { ExclamationIcon } from '@heroicons/react/solid' + +export function WarningConfirmationButton(props: { + warning?: string + onSubmit: () => void + disabled?: boolean + isSubmitting: boolean + openModalButtonClass?: string + submitButtonClassName?: string +}) { + const { + onSubmit, + warning, + disabled, + isSubmitting, + openModalButtonClass, + submitButtonClassName, + } = props + + if (!warning) { + return ( + + ) + } + + return ( + + + + +

{warning}

+
+ ) +}