Skip to content

Commit

Permalink
Move location monitor to trade panel
Browse files Browse the repository at this point in the history
  • Loading branch information
IanPhilips committed Sep 20, 2024
1 parent 1e76a81 commit 9ea4c59
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 74 deletions.
112 changes: 62 additions & 50 deletions web/components/bet/bet-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import { YesNoSelector } from './yes-no-selector'
import { blockFromSweepstakes, identityPending } from 'common/user'
import { CashoutLimitWarning } from './cashout-limit-warning'
import { InBeta, VerifyButton } from '../twomba/toggle-verify-callout'
import { LocationMonitor } from '../gidx/location-monitor'

export type BinaryOutcomes = 'YES' | 'NO' | undefined

Expand Down Expand Up @@ -393,11 +394,14 @@ export const BuyPanelBody = (props: {
setIsSubmitting(false)
}
}
const [showLocationMonitor, setShowLocationMonitor] = useState(false)

const betDisabled =
isSubmitting ||
!betAmount ||
outcome === undefined ||
error === 'Insufficient balance'
error === 'Insufficient balance' ||
showLocationMonitor

const limits =
contract.outcomeType === 'STONK'
Expand Down Expand Up @@ -703,55 +707,63 @@ export const BuyPanelBody = (props: {
{betType !== 'Limit' && (
<Col className="gap-2">
{user ? (
<WarningConfirmationButton
marketType="binary"
amount={betAmount}
warning={warning}
userOptedOutOfWarning={user.optOutBetWarnings}
onSubmit={submitBet}
ButtonClassName={clsx('flex-grow')}
actionLabelClassName={'line-clamp-1'}
isSubmitting={isSubmitting}
disabled={betDisabled}
size="xl"
color={
pseudonymColor ??
binaryMCColors?.[outcome == 'YES' ? 0 : 1] ??
(outcome === 'NO' ? 'red' : 'green')
}
actionLabel={
betDisabled ? (
`Select ${formatOutcomeLabel(
contract,
'YES'
)} or ${formatOutcomeLabel(contract, 'NO')}`
) : isStonk ? (
<span>
{formatOutcomeLabel(contract, outcome, pseudonymName)}{' '}
<MoneyDisplay
amount={betAmount}
isCashContract={isCashContract}
/>
</span>
) : (
<span>
{capitalize(TRADE_TERM)}{' '}
{binaryMCOutcomeLabel ??
formatOutcomeLabel(
contract,
outcome,
pseudonymName
)}{' '}
to win{' '}
<MoneyDisplay
amount={currentPayout}
isCashContract={isCashContract}
/>
</span>
)
}
inModal={!!onClose}
/>
<>
<LocationMonitor
contract={contract}
user={user}
setShowPanel={setShowLocationMonitor}
showPanel={showLocationMonitor}
/>
<WarningConfirmationButton
marketType="binary"
amount={betAmount}
warning={warning}
userOptedOutOfWarning={user.optOutBetWarnings}
onSubmit={submitBet}
ButtonClassName={clsx('flex-grow')}
actionLabelClassName={'line-clamp-1'}
isSubmitting={isSubmitting}
disabled={betDisabled}
size="xl"
color={
pseudonymColor ??
binaryMCColors?.[outcome == 'YES' ? 0 : 1] ??
(outcome === 'NO' ? 'red' : 'green')
}
actionLabel={
betDisabled && !outcome ? (
`Select ${formatOutcomeLabel(
contract,
'YES'
)} or ${formatOutcomeLabel(contract, 'NO')}`
) : isStonk ? (
<span>
{formatOutcomeLabel(contract, outcome, pseudonymName)}{' '}
<MoneyDisplay
amount={betAmount ?? 0}
isCashContract={isCashContract}
/>
</span>
) : (
<span>
{capitalize(TRADE_TERM)}{' '}
{binaryMCOutcomeLabel ??
formatOutcomeLabel(
contract,
outcome,
pseudonymName
)}{' '}
to win{' '}
<MoneyDisplay
amount={currentPayout}
isCashContract={isCashContract}
/>
</span>
)
}
inModal={!!onClose}
/>
</>
) : (
<Button
color={outcome === 'NO' ? 'red' : 'green'}
Expand Down
12 changes: 10 additions & 2 deletions web/components/bet/limit-order-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { FeeDisplay } from './fees'
import { MoneyDisplay } from './money-display'
import { TRADE_TERM } from 'common/envs/constants'
import { capitalize } from 'lodash'
import { LocationMonitor } from '../gidx/location-monitor'

export default function LimitOrderPanel(props: {
contract:
Expand Down Expand Up @@ -140,6 +141,7 @@ export default function LimitOrderPanel(props: {
const [limitProbInt, setLimitProbInt] = useState<number | undefined>(
Math.round(initialProb * 100)
)
const [showLocationMonitor, setShowLocationMonitor] = useState(false)

const hasLimitBet = !!limitProbInt && !!betAmount

Expand All @@ -148,7 +150,8 @@ export default function LimitOrderPanel(props: {
!outcome ||
!betAmount ||
!hasLimitBet ||
error === 'Insufficient balance'
error === 'Insufficient balance' ||
showLocationMonitor

const preLimitProb =
limitProbInt === undefined
Expand Down Expand Up @@ -281,7 +284,6 @@ export default function LimitOrderPanel(props: {
}
const returnPercent = formatPercent(currentReturn)
const totalFees = getFeeTotal(fees)

const hideYesNo = isBinaryMC || !!pseudonym

return (
Expand Down Expand Up @@ -468,6 +470,12 @@ export default function LimitOrderPanel(props: {
/>
</Row>

<LocationMonitor
contract={contract}
user={user}
setShowPanel={setShowLocationMonitor}
showPanel={showLocationMonitor}
/>
<Row className="items-center justify-between gap-2">
{user && (
<Button
Expand Down
10 changes: 1 addition & 9 deletions web/components/contract/contract-overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ import {
import { useLiveContractWithAnswers } from 'web/hooks/use-contract'
import { VerifyButton } from '../twomba/toggle-verify-callout'
import { InBeta } from '../twomba/toggle-verify-callout'
import { LocationMonitor } from '../gidx/location-monitor'

export const ContractOverview = memo(
(props: {
Expand Down Expand Up @@ -174,7 +173,6 @@ export const BinaryOverview = (props: {
chartAnnotations: ChartAnnotation[]
}) => {
const { contract, resolutionRating } = props
const [showLocationPane, setShowLocationPane] = useState(false)
const user = useUser()

const [showZoomer, setShowZoomer] = useState(false)
Expand Down Expand Up @@ -233,13 +231,7 @@ export const BinaryOverview = (props: {
pointerMode={pointerMode}
chartAnnotations={chartAnnotations}
/>
<LocationMonitor
contract={contract}
user={user}
setShowPanel={setShowLocationPane}
showPanel={showLocationPane}
/>
{tradingAllowed(contract) && !showLocationPane && (
{tradingAllowed(contract) && (
<BinaryBetPanel contract={contract} user={user} />
)}
</>
Expand Down
21 changes: 8 additions & 13 deletions web/components/gidx/location-monitor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useMonitorStatus } from 'web/hooks/use-monitor-status'
import { User } from 'common/user'
import { Col } from '../layout/col'
import { Contract } from 'common/contract'
import { TRADE_TERM } from 'common/envs/constants'

export const LocationMonitor = (props: {
contract: Contract
Expand Down Expand Up @@ -33,19 +34,13 @@ export const LocationMonitor = (props: {
return null
}
return (
<Col className="gap-2 p-2">
<span className="text-xl font-semibold">Location Required</span>
<p>
You must share your location to participate in sweepstakes. Please allow
location sharing.
</p>
<div className="mt-2 flex justify-end">
<Button
loading={loading}
onClick={() => requestLocation()}
className="ml-2"
>
Share Location
<Col className=" p-2">
<span className="text-xl font-semibold">
Location required to participate in sweepstakes
</span>
<div className="mt-2 flex">
<Button size="xl" loading={loading} onClick={() => requestLocation()}>
Share location to {TRADE_TERM}
</Button>
</div>
{monitorStatus === 'error' && (
Expand Down

0 comments on commit 9ea4c59

Please sign in to comment.