Add payout if MKT. Current value uses MKT payout.
This commit is contained in:
parent
44f44272ff
commit
4d0646a200
|
@ -18,13 +18,12 @@ import { UserLink } from './user-page'
|
||||||
import {
|
import {
|
||||||
calculatePayout,
|
calculatePayout,
|
||||||
calculateSaleAmount,
|
calculateSaleAmount,
|
||||||
currentValue,
|
|
||||||
resolvedPayout,
|
resolvedPayout,
|
||||||
} from '../lib/calculate'
|
} from '../lib/calculate'
|
||||||
import clsx from 'clsx'
|
import clsx from 'clsx'
|
||||||
import { cloudFunction } from '../lib/firebase/api-call'
|
import { cloudFunction } from '../lib/firebase/api-call'
|
||||||
import { ConfirmationButton } from './confirmation-button'
|
import { ConfirmationButton } from './confirmation-button'
|
||||||
import { OutcomeLabel, YesLabel, NoLabel } from './outcome-label'
|
import { OutcomeLabel, YesLabel, NoLabel, MarketLabel } from './outcome-label'
|
||||||
|
|
||||||
export function BetsList(props: { user: User }) {
|
export function BetsList(props: { user: User }) {
|
||||||
const { user } = props
|
const { user } = props
|
||||||
|
@ -84,7 +83,7 @@ export function BetsList(props: { user: User }) {
|
||||||
const currentBetsValue = _.sumBy(unresolved, (contract) =>
|
const currentBetsValue = _.sumBy(unresolved, (contract) =>
|
||||||
_.sumBy(contractBets[contract.id], (bet) => {
|
_.sumBy(contractBets[contract.id], (bet) => {
|
||||||
if (bet.isSold || bet.sale) return 0
|
if (bet.isSold || bet.sale) return 0
|
||||||
return currentValue(contract, bet)
|
return calculatePayout(contract, bet, 'MKT')
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -183,9 +182,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
|
||||||
className?: string
|
className?: string
|
||||||
}) {
|
}) {
|
||||||
const { bets, contract, className } = props
|
const { bets, contract, showMKT, className } = props
|
||||||
const { resolution } = contract
|
const { resolution } = contract
|
||||||
|
|
||||||
const excludeSales = bets.filter((b) => !b.isSold && !b.sale)
|
const excludeSales = bets.filter((b) => !b.isSold && !b.sale)
|
||||||
|
@ -202,21 +202,29 @@ export function MyBetsSummary(props: {
|
||||||
calculatePayout(contract, bet, 'NO')
|
calculatePayout(contract, bet, 'NO')
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const marketWinnings = _.sumBy(excludeSales, (bet) =>
|
||||||
|
calculatePayout(contract, bet, 'MKT')
|
||||||
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Row className={clsx('gap-4 sm:gap-6', className)}>
|
<Row
|
||||||
|
className={clsx(
|
||||||
|
'gap-4 sm:gap-6',
|
||||||
|
showMKT && 'flex-wrap sm:flex-nowrap',
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
>
|
||||||
<Col>
|
<Col>
|
||||||
<div className="text-sm text-gray-500 whitespace-nowrap">Invested</div>
|
<div className="text-sm text-gray-500 whitespace-nowrap">Invested</div>
|
||||||
<div className="whitespace-nowrap">{formatMoney(betsTotal)}</div>
|
<div className="whitespace-nowrap">{formatMoney(betsTotal)}</div>
|
||||||
</Col>
|
</Col>
|
||||||
{resolution ? (
|
{resolution ? (
|
||||||
<>
|
<Col>
|
||||||
<Col>
|
<div className="text-sm text-gray-500">Payout</div>
|
||||||
<div className="text-sm text-gray-500">Payout</div>
|
<div className="whitespace-nowrap">{formatMoney(betsPayout)}</div>
|
||||||
<div className="whitespace-nowrap">{formatMoney(betsPayout)}</div>
|
</Col>
|
||||||
</Col>
|
|
||||||
</>
|
|
||||||
) : (
|
) : (
|
||||||
<>
|
<Row className="gap-4 sm:gap-6">
|
||||||
<Col>
|
<Col>
|
||||||
<div className="text-sm text-gray-500 whitespace-nowrap">
|
<div className="text-sm text-gray-500 whitespace-nowrap">
|
||||||
Payout if <YesLabel />
|
Payout if <YesLabel />
|
||||||
|
@ -229,7 +237,17 @@ export function MyBetsSummary(props: {
|
||||||
</div>
|
</div>
|
||||||
<div className="whitespace-nowrap">{formatMoney(noWinnings)}</div>
|
<div className="whitespace-nowrap">{formatMoney(noWinnings)}</div>
|
||||||
</Col>
|
</Col>
|
||||||
</>
|
{showMKT && (
|
||||||
|
<Col>
|
||||||
|
<div className="text-sm text-gray-500 whitespace-nowrap">
|
||||||
|
Payout if <MarketLabel />
|
||||||
|
</div>
|
||||||
|
<div className="whitespace-nowrap">
|
||||||
|
{formatMoney(marketWinnings)}
|
||||||
|
</div>
|
||||||
|
</Col>
|
||||||
|
)}
|
||||||
|
</Row>
|
||||||
)}
|
)}
|
||||||
</Row>
|
</Row>
|
||||||
)
|
)
|
||||||
|
|
|
@ -110,7 +110,7 @@ function BetsSection(props: { contract: Contract; user: User | null }) {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Title text="Your trades" />
|
<Title text="Your trades" />
|
||||||
<MyBetsSummary contract={contract} bets={userBets} />
|
<MyBetsSummary 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} />
|
||||||
|
|
Loading…
Reference in New Issue
Block a user