Skip to content
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

Ingawei/trades UI #2720

Merged
merged 2 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 28 additions & 36 deletions web/components/bet/contract-bets-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@ import {
answerToRange,
getMultiNumericAnswerMidpoints,
} from 'common/multi-numeric'
import { Pagination } from '../widgets/pagination'

export function ContractBetsTable(props: {
contract: Contract
bets: Bet[]
isYourBets: boolean
hideRedemptionAndLoanMessages?: boolean
truncate?: boolean
paginate?: boolean
}) {
const { contract, isYourBets, hideRedemptionAndLoanMessages, truncate } =
const { contract, isYourBets, hideRedemptionAndLoanMessages, paginate } =
props
const { isResolved, mechanism, outcomeType } = contract

Expand Down Expand Up @@ -67,10 +68,8 @@ export function ContractBetsTable(props: {
'desc'
)

const [truncated, setTruncated] = useState(truncate ?? false)
const truncatedBetCount = 3
const moreBetsCount =
(isMultiNumber ? groupedBets.length : normalBets.length) - truncatedBetCount
const [page, setPage] = useState(0)
const betsPerPage = 5

return (
<div className="overflow-x-auto">
Expand Down Expand Up @@ -121,42 +120,35 @@ export function ContractBetsTable(props: {
</thead>
<tbody>
{isMultiNumber
? groupedBets
.slice(0, truncated ? truncatedBetCount : undefined)
.map((bets) => (
<MultiNumberBetRow
key={bets[0].id}
bets={bets}
contract={contract as CPMMNumericContract}
isYourBet={isYourBets}
/>
))
: (truncated
? normalBets.slice(0, truncatedBetCount)
? (paginate
? groupedBets.slice(
page * betsPerPage,
(page + 1) * betsPerPage
)
: groupedBets
).map((bets) => (
<MultiNumberBetRow
key={bets[0].id}
bets={bets}
contract={contract as CPMMNumericContract}
isYourBet={isYourBets}
/>
))
: (paginate
? normalBets.slice(page * betsPerPage, (page + 1) * betsPerPage)
: normalBets
).map((bet) => (
<BetRow key={bet.id} bet={bet} contract={contract} />
))}
</tbody>
</Table>

{truncate && moreBetsCount > 0 && (
<Button
className="w-full"
color="gray-white"
onClick={() => setTruncated((b) => !b)}
>
{truncated ? (
<>
<ChevronDownIcon className="mr-1 h-4 w-4" />{' '}
{`Show ${moreBetsCount} more trades`}
</>
) : (
<>
<ChevronUpIcon className="mr-1 h-4 w-4" /> {`Show fewer trades`}
</>
)}
</Button>
{paginate && (
<Pagination
page={page}
setPage={setPage}
pageSize={betsPerPage}
totalItems={isMultiNumber ? groupedBets.length : normalBets.length}
/>
)}
</div>
)
Expand Down
1 change: 1 addition & 0 deletions web/components/bet/user-bets-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,7 @@ function BetsTable(props: {
contract={contract}
bets={bets}
isYourBets={areYourBets}
paginate
/>
</Col>
))}
Expand Down
8 changes: 4 additions & 4 deletions web/pages/[username]/[contractSlug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ export function ContractPageContent(props: ContractParams) {

{!tradingAllowed(contract) && (
<UserBetsSummary
className="border-ink-200 !mb-2 mt-2 "
className="border-ink-200 !mb-2 "
contract={contract}
/>
)}
Expand Down Expand Up @@ -654,7 +654,7 @@ function YourTrades(props: { contract: Contract; yourNewBets: Bet[] }) {
) as LimitBet[]

return (
<Col>
<Col className="bg-canvas-50 rounded px-3 py-4 pb-0">
{contract.mechanism === 'cpmm-1' && (
<YourOrders
contract={contract}
Expand All @@ -665,12 +665,12 @@ function YourTrades(props: { contract: Contract; yourNewBets: Bet[] }) {

{visibleUserBets.length > 0 && (
<>
<div className="text-ink-700 text-lg">Your trades</div>
<div className="pl-2 font-semibold">Your trades</div>
<ContractBetsTable
contract={contract}
bets={userBets}
isYourBets
truncate
paginate
/>
</>
)}
Expand Down
Loading