-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
conditional orderbook tab and button #2888
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,14 @@ import { | |
} from 'common/antes' | ||
import { Bet } from 'common/bet' | ||
import { ContractComment } from 'common/comment' | ||
import { BinaryContract, Contract, CPMMNumericContract } from 'common/contract' | ||
import { | ||
BinaryContract, | ||
Contract, | ||
CPMMMultiContract, | ||
CPMMNumericContract, | ||
PseudoNumericContract, | ||
StonkContract, | ||
} from 'common/contract' | ||
import { buildArray } from 'common/util/array' | ||
import { shortFormatNumber, maybePluralize } from 'common/util/format' | ||
import { MINUTE_MS } from 'common/util/time' | ||
|
@@ -43,6 +50,8 @@ import generateFilterDropdownItems from '../search/search-dropdown-helpers' | |
import { useAPIGetter } from 'web/hooks/use-api-getter' | ||
import { api } from 'web/lib/api/api' | ||
import { TRADE_TERM } from 'common/envs/constants' | ||
import { useUnfilledBets } from 'web/hooks/use-bets' | ||
import { OrderBookPanel } from '../bet/order-book' | ||
|
||
export function ContractTabs(props: { | ||
mainContract: Contract | ||
|
@@ -94,6 +103,92 @@ export function ContractTabs(props: { | |
(totalPositions > 0 ? `${shortFormatNumber(totalPositions)} ` : '') + | ||
maybePluralize('Holder', totalPositions) | ||
|
||
const tabs = buildArray( | ||
{ | ||
title: commentsTitle, | ||
content: ( | ||
<CommentsTabContent | ||
contract={mainContract} | ||
comments={comments} | ||
pinnedComments={pinnedComments} | ||
setCommentsLength={setTotalComments} | ||
blockedUserIds={blockedUserIds} | ||
replyTo={replyTo} | ||
clearReply={() => setReplyTo?.(undefined)} | ||
className="-ml-2 -mr-1" | ||
bets={uniqBy(bets.concat(betReplies), (b) => b.id)} | ||
appRouter={appRouter} | ||
/> | ||
), | ||
}, | ||
totalBets > 0 && | ||
(liveContract.mechanism === 'cpmm-1' || | ||
liveContract.mechanism === 'cpmm-multi-1') && { | ||
title: positionsTitle, | ||
content: ( | ||
<UserPositionsTable | ||
key={liveContract.id} | ||
positions={ | ||
// If contract is resolved, will have to refetch positions by profit | ||
Object.values(userPositionsByOutcome).length > 0 && | ||
!liveContract.isResolved | ||
? userPositionsByOutcome | ||
: undefined | ||
} | ||
contract={liveContract as BinaryContract} | ||
setTotalPositions={setTotalPositions} | ||
/> | ||
), | ||
}, | ||
totalBets > 0 && { | ||
title: tradesTitle, | ||
content: ( | ||
<Col className={'gap-4'}> | ||
<BetsTabContent | ||
key={liveContract.id} | ||
contract={liveContract} | ||
bets={bets} | ||
totalBets={totalBets} | ||
setReplyToBet={setReplyTo} | ||
/> | ||
</Col> | ||
), | ||
}, | ||
totalBets > 0 && | ||
liveContract.mechanism === 'cpmm-1' && { | ||
title: 'Order book', | ||
className: 'hidden md:block', | ||
content: null, | ||
} | ||
) | ||
|
||
const filteredTabs = tabs.filter(Boolean) | ||
|
||
const orderBookTabIndex = filteredTabs.findIndex( | ||
(tab) => tab.title === 'Order book' | ||
) | ||
|
||
const isOrderBookTabActive = | ||
orderBookTabIndex >= 0 && activeIndex === orderBookTabIndex | ||
|
||
const unfilledBets = | ||
useUnfilledBets(liveContract.id, { enabled: isOrderBookTabActive }) ?? [] | ||
|
||
if (orderBookTabIndex >= 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is this? Why isn't the order book simply in the tabs array as the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm I'm confused I thought this as well as the clause u asked about above in a comment made up the logic that makes it so useUnfilledBets only gets the unfilledbets once the conditions are met and prevent them from loading with the page There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if |
||
filteredTabs[orderBookTabIndex].content = ( | ||
<OrderBookPanel | ||
contract={ | ||
liveContract as | ||
| BinaryContract | ||
| PseudoNumericContract | ||
| StonkContract | ||
| CPMMNumericContract | ||
} | ||
limitBets={unfilledBets} | ||
/> | ||
) | ||
} | ||
|
||
return ( | ||
<ControlledTabs | ||
className="mb-4" | ||
|
@@ -108,62 +203,13 @@ export function ContractTabs(props: { | |
? 'trades' | ||
: title === positionsTitle | ||
? 'positions' | ||
: title === 'Order book' | ||
? 'orderbook' | ||
: 'contract' | ||
} tab` | ||
) | ||
}} | ||
tabs={buildArray( | ||
{ | ||
title: commentsTitle, | ||
content: ( | ||
<CommentsTabContent | ||
contract={mainContract} | ||
comments={comments} | ||
pinnedComments={pinnedComments} | ||
setCommentsLength={setTotalComments} | ||
blockedUserIds={blockedUserIds} | ||
replyTo={replyTo} | ||
clearReply={() => setReplyTo?.(undefined)} | ||
className="-ml-2 -mr-1" | ||
bets={uniqBy(bets.concat(betReplies), (b) => b.id)} | ||
appRouter={appRouter} | ||
/> | ||
), | ||
}, | ||
totalBets > 0 && | ||
(liveContract.mechanism === 'cpmm-1' || | ||
liveContract.mechanism === 'cpmm-multi-1') && { | ||
title: positionsTitle, | ||
content: ( | ||
<UserPositionsTable | ||
key={liveContract.id} | ||
positions={ | ||
// If contract is resolved, will have to refetch positions by profit | ||
Object.values(userPositionsByOutcome).length > 0 && | ||
!liveContract.isResolved | ||
? userPositionsByOutcome | ||
: undefined | ||
} | ||
contract={liveContract as BinaryContract} | ||
setTotalPositions={setTotalPositions} | ||
/> | ||
), | ||
}, | ||
totalBets > 0 && { | ||
title: tradesTitle, | ||
content: ( | ||
<Col className={'gap-4'}> | ||
<BetsTabContent | ||
key={liveContract.id} | ||
contract={liveContract} | ||
bets={bets} | ||
totalBets={totalBets} | ||
setReplyToBet={setReplyTo} | ||
/> | ||
</Col> | ||
), | ||
} | ||
)} | ||
tabs={filteredTabs} | ||
/> | ||
) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,11 @@ import { | |
type Contract, | ||
type ContractParams, | ||
tradingAllowed, | ||
BinaryContract, | ||
CPMMMultiContract, | ||
CPMMNumericContract, | ||
PseudoNumericContract, | ||
StonkContract, | ||
} from 'common/contract' | ||
import { mergeWith, uniqBy } from 'lodash' | ||
import Head from 'next/head' | ||
|
@@ -55,7 +60,7 @@ import { Rating, ReviewPanel } from 'web/components/reviews/stars' | |
import { GradientContainer } from 'web/components/widgets/gradient-container' | ||
import { Tooltip } from 'web/components/widgets/tooltip' | ||
import { useAdmin, useTrusted } from 'web/hooks/use-admin' | ||
import { useContractBets } from 'web/hooks/use-bets' | ||
import { useContractBets, useUnfilledBets } from 'web/hooks/use-bets' | ||
import { useLiveContractWithAnswers } from 'web/hooks/use-contract' | ||
import { useGoogleAnalytics } from 'web/hooks/use-google-analytics' | ||
import { useHeaderIsStuck } from 'web/hooks/use-header-is-stuck' | ||
|
@@ -76,6 +81,8 @@ import { useSweepstakes } from '../sweestakes-context' | |
import { useMonitorStatus } from 'web/hooks/use-monitor-status' | ||
import { ToggleVerifyCallout } from '../twomba/toggle-verify-callout' | ||
import { useRouter } from 'next/router' | ||
import { Button } from '../buttons/button' | ||
import { OrderBookPanel } from '../bet/order-book' | ||
|
||
export function TwombaContractPageContent(props: ContractParams) { | ||
const { | ||
|
@@ -220,6 +227,11 @@ export function TwombaContractPageContent(props: ContractParams) { | |
const isSpiceMarket = !!liveContract.isSpicePayout | ||
const isCashContract = liveContract.token === 'CASH' | ||
|
||
const [showOrderBook, setShowOrderBook] = useState(false) | ||
|
||
const unfilledBets = | ||
useUnfilledBets(liveContract.id, { enabled: showOrderBook }) ?? [] | ||
|
||
return ( | ||
<> | ||
{props.contract.visibility !== 'public' && ( | ||
|
@@ -442,13 +454,49 @@ export function TwombaContractPageContent(props: ContractParams) { | |
<Row className="my-2 flex-wrap items-center justify-between gap-y-2"></Row> | ||
{!user && <SidebarSignUpButton className="mb-4 flex md:hidden" />} | ||
{!!user && ( | ||
<ContractSharePanel | ||
isClosed={isClosed} | ||
isCreator={isCreator} | ||
showResolver={showResolver} | ||
// TODO: upgrade tier | ||
contract={props.contract} | ||
/> | ||
<Col> | ||
<Row className="items-center gap-2"> | ||
SirSaltyy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{totalBets > 0 && ( | ||
<div className="flex sm:hidden"> | ||
<Button | ||
color="indigo-outline" | ||
size="lg" | ||
onClick={() => { | ||
setShowOrderBook((prev) => !prev) | ||
if (!showOrderBook) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's this clause for? |
||
} | ||
}} | ||
className={clsx( | ||
'w-full rounded-md px-4 py-2 text-indigo-500', | ||
showOrderBook && | ||
'bg-primary-600 !text-ink-0 ring-transparent' | ||
)} | ||
> | ||
Order Book | ||
</Button> | ||
</div> | ||
)} | ||
<ContractSharePanel | ||
isClosed={isClosed} | ||
isCreator={isCreator} | ||
showResolver={showResolver} | ||
// TODO: upgrade tier | ||
contract={props.contract} | ||
/> | ||
</Row> | ||
{showOrderBook && ( | ||
<OrderBookPanel | ||
contract={ | ||
liveContract as | ||
| BinaryContract | ||
| PseudoNumericContract | ||
| StonkContract | ||
| CPMMNumericContract | ||
} | ||
limitBets={unfilledBets} | ||
/> | ||
)} | ||
</Col> | ||
)} | ||
|
||
{isResolved && resolution !== 'CANCEL' && ( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need this filter