beautify trades page

This commit is contained in:
mantikoros 2022-02-14 16:00:35 -06:00
parent 97bf1049b5
commit 443acdbcf8
2 changed files with 83 additions and 40 deletions

View File

@ -127,18 +127,20 @@ export function BetsList(props: { user: User }) {
const totalReturn = const totalReturn =
(pnl > 0 ? '+' : '') + ((pnl / user.totalDeposits) * 100).toFixed() + '%' (pnl > 0 ? '+' : '') + ((pnl / user.totalDeposits) * 100).toFixed() + '%'
const color = pnl === 0 ? '' : pnl > 0 ? 'text-green-500' : 'text-red-500'
return ( return (
<Col className="mt-6 gap-6"> <Col className="mt-6 gap-6">
<Col className="mx-4 gap-4 sm:flex-row sm:justify-between md:mx-0"> <Col className="mx-4 gap-4 sm:flex-row sm:justify-between md:mx-0">
<Row className="gap-8"> <Row className="gap-8">
<Col> <Col>
<div className="text-sm text-gray-500">Total portfolio</div> <div className="text-sm text-gray-500">Portfolio value</div>
<div>{formatMoney(totalPortfolio)}</div> <div>{formatMoney(totalPortfolio)}</div>
</Col> </Col>
<Col> <Col>
<div className="text-sm text-gray-500">Total profits & losses</div> <div className="text-sm text-gray-500">Total profits & losses</div>
<div> <div>
{formatMoney(pnl)} ({totalReturn}) {formatMoney(pnl)} (<span className={color}>{totalReturn}</span>)
</div> </div>
</Col> </Col>
<Col> <Col>
@ -226,6 +228,7 @@ function MyContractBets(props: { contract: Contract; bets: Bet[] }) {
className="mr-5 flex-1 justify-end sm:mr-8" className="mr-5 flex-1 justify-end sm:mr-8"
contract={contract} contract={contract}
bets={bets} bets={bets}
onlyMKT
/> />
</Row> </Row>
@ -235,6 +238,14 @@ function MyContractBets(props: { contract: Contract; bets: Bet[] }) {
> >
<Spacer h={8} /> <Spacer h={8} />
<MyBetsSummary
className="mr-5 flex-1 sm:mr-8"
contract={contract}
bets={bets}
/>
<Spacer h={8} />
<ContractBetsTable contract={contract} bets={bets} /> <ContractBetsTable contract={contract} bets={bets} />
</div> </div>
</div> </div>
@ -244,10 +255,10 @@ function MyContractBets(props: { contract: Contract; bets: Bet[] }) {
export function MyBetsSummary(props: { export function MyBetsSummary(props: {
contract: Contract contract: Contract
bets: Bet[] bets: Bet[]
showMKT?: boolean onlyMKT?: boolean
className?: string className?: string
}) { }) {
const { bets, contract, showMKT, className } = props const { bets, contract, onlyMKT, className } = props
const { resolution } = contract const { resolution } = contract
calculateCancelPayout calculateCancelPayout
@ -269,38 +280,74 @@ export function MyBetsSummary(props: {
calculatePayout(contract, bet, 'MKT') calculatePayout(contract, bet, 'MKT')
) )
const currentValue = resolution ? betsPayout : marketWinnings
const pnl = currentValue - betsTotal
const totalReturn =
betsTotal === 0
? '0%'
: (pnl > 0 ? '+' : '') + ((pnl / betsTotal) * 100).toFixed() + '%'
const color = pnl === 0 ? '' : pnl > 0 ? 'text-green-500' : 'text-red-500'
const mktCol = (
<Col>
<div className="whitespace-nowrap text-sm text-gray-500">
Market value
</div>
<div className="whitespace-nowrap">
{formatMoney(marketWinnings)} (
<span className={color}>{totalReturn}</span>)
</div>
</Col>
)
const payoutCol = (
<Col>
<div className="text-sm text-gray-500">Payout</div>
<div className="whitespace-nowrap">
{formatMoney(betsPayout)} (<span className={color}>{totalReturn}</span>)
</div>
</Col>
)
return ( return (
<Row <Row
className={clsx( className={clsx(
'gap-4 sm:gap-6', 'gap-4 sm:gap-6',
showMKT && 'flex-wrap sm:flex-nowrap', !onlyMKT && 'flex-wrap sm:flex-nowrap',
className className
)} )}
> >
<Col> {onlyMKT ? (
<div className="whitespace-nowrap text-sm text-gray-500">Invested</div> <Row className="gap-4 sm:gap-6">{resolution ? payoutCol : mktCol}</Row>
<div className="whitespace-nowrap">{formatMoney(betsTotal)}</div>
</Col>
{resolution ? (
<Col>
<div className="text-sm text-gray-500">Payout</div>
<div className="whitespace-nowrap">{formatMoney(betsPayout)}</div>
</Col>
) : ( ) : (
<Row className="gap-4 sm:gap-6"> <Row className="gap-4 sm:gap-6">
<Col>
<div className="whitespace-nowrap text-sm text-gray-500">
Invested
</div>
<div className="whitespace-nowrap">{formatMoney(betsTotal)}</div>
</Col>
{resolution ? (
payoutCol
) : (
<>
<Col> <Col>
<div className="whitespace-nowrap text-sm text-gray-500"> <div className="whitespace-nowrap text-sm text-gray-500">
Payout if <YesLabel /> Payout if <YesLabel />
</div> </div>
<div className="whitespace-nowrap">{formatMoney(yesWinnings)}</div> <div className="whitespace-nowrap">
{formatMoney(yesWinnings)}
</div>
</Col> </Col>
<Col> <Col>
<div className="whitespace-nowrap text-sm text-gray-500"> <div className="whitespace-nowrap text-sm text-gray-500">
Payout if <NoLabel /> Payout if <NoLabel />
</div> </div>
<div className="whitespace-nowrap">{formatMoney(noWinnings)}</div> <div className="whitespace-nowrap">
{formatMoney(noWinnings)}
</div>
</Col> </Col>
{showMKT && (
<Col> <Col>
<div className="whitespace-nowrap text-sm text-gray-500"> <div className="whitespace-nowrap text-sm text-gray-500">
Payout at{' '} Payout at{' '}
@ -312,6 +359,7 @@ export function MyBetsSummary(props: {
{formatMoney(marketWinnings)} {formatMoney(marketWinnings)}
</div> </div>
</Col> </Col>
</>
)} )}
</Row> </Row>
)} )}

View File

@ -156,12 +156,7 @@ function BetsSection(props: { contract: Contract; user: User | null }) {
return ( return (
<div> <div>
<Title className="px-2" text="Your trades" /> <Title className="px-2" text="Your trades" />
<MyBetsSummary <MyBetsSummary className="px-2" contract={contract} bets={userBets} />
className="px-2"
contract={contract}
bets={userBets}
showMKT
/>
<Spacer h={6} /> <Spacer h={6} />
<ContractBetsTable contract={contract} bets={userBets} /> <ContractBetsTable contract={contract} bets={userBets} />
<Spacer h={12} /> <Spacer h={12} />