sort trades by value
This commit is contained in:
parent
51aa8df010
commit
3609255342
|
@ -33,7 +33,7 @@ import { sellBet } 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 } from './outcome-label'
|
||||||
|
|
||||||
type BetSort = 'newest' | 'profit' | 'resolved'
|
type BetSort = 'newest' | 'profit' | 'resolved' | 'value'
|
||||||
|
|
||||||
export function BetsList(props: { user: User }) {
|
export function BetsList(props: { user: User }) {
|
||||||
const { user } = props
|
const { user } = props
|
||||||
|
@ -41,7 +41,7 @@ export function BetsList(props: { user: User }) {
|
||||||
|
|
||||||
const [contracts, setContracts] = useState<Contract[]>([])
|
const [contracts, setContracts] = useState<Contract[]>([])
|
||||||
|
|
||||||
const [sort, setSort] = useState<BetSort>('profit')
|
const [sort, setSort] = useState<BetSort>('value')
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const loadedBets = bets ? bets : []
|
const loadedBets = bets ? bets : []
|
||||||
|
@ -104,6 +104,8 @@ export function BetsList(props: { user: User }) {
|
||||||
contracts,
|
contracts,
|
||||||
(c) => -1 * (contractsCurrentValue[c.id] - contractsInvestment[c.id])
|
(c) => -1 * (contractsCurrentValue[c.id] - contractsInvestment[c.id])
|
||||||
)
|
)
|
||||||
|
} else if (sort === 'value') {
|
||||||
|
sortedContracts = _.sortBy(contracts, (c) => -contractsCurrentValue[c.id])
|
||||||
}
|
}
|
||||||
|
|
||||||
const [resolved, unresolved] = _.partition(
|
const [resolved, unresolved] = _.partition(
|
||||||
|
@ -161,6 +163,7 @@ export function BetsList(props: { user: User }) {
|
||||||
value={sort}
|
value={sort}
|
||||||
onChange={(e) => setSort(e.target.value as BetSort)}
|
onChange={(e) => setSort(e.target.value as BetSort)}
|
||||||
>
|
>
|
||||||
|
<option value="value">By value</option>
|
||||||
<option value="profit">By profit</option>
|
<option value="profit">By profit</option>
|
||||||
<option value="newest">Newest</option>
|
<option value="newest">Newest</option>
|
||||||
<option value="resolved">Resolved</option>
|
<option value="resolved">Resolved</option>
|
||||||
|
@ -280,6 +283,10 @@ export function MyBetsSummary(props: {
|
||||||
calculatePayout(contract, bet, 'NO')
|
calculatePayout(contract, bet, 'NO')
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const p = getProbability(contract.totalShares)
|
||||||
|
|
||||||
|
const expectation = p * yesWinnings + (1 - p) * noWinnings
|
||||||
|
|
||||||
const marketWinnings = _.sumBy(excludeSales, (bet) =>
|
const marketWinnings = _.sumBy(excludeSales, (bet) =>
|
||||||
calculatePayout(contract, bet, 'MKT')
|
calculatePayout(contract, bet, 'MKT')
|
||||||
)
|
)
|
||||||
|
@ -330,6 +337,14 @@ export function MyBetsSummary(props: {
|
||||||
payoutCol
|
payoutCol
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
|
<Col>
|
||||||
|
<div className="whitespace-nowrap text-sm text-gray-500">
|
||||||
|
Expectation
|
||||||
|
</div>
|
||||||
|
<div className="whitespace-nowrap">
|
||||||
|
{formatMoney(expectation)}
|
||||||
|
</div>
|
||||||
|
</Col>
|
||||||
<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 />
|
||||||
|
|
Loading…
Reference in New Issue
Block a user