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

Show fractional shares for advanced traders #2463

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion common/src/util/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ export function getMoneyNumber(amount: number) {
}

export function formatMoneyWithDecimals(amount: number) {
return ENV_CONFIG.moneyMoniker + amount.toFixed(2)
const plusEpsilon = amount + 0.00000000001 * Math.sign(amount)
const newAmount = Math.round(plusEpsilon) === 0 ? 0 : Math.trunc(plusEpsilon * 100) / 100
return ENV_CONFIG.moneyMoniker + newAmount
}

export function formatMoneyToDecimal(amount: number) {
Expand Down
6 changes: 6 additions & 0 deletions web/components/bet/bet-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
formatMoney,
formatOutcomeLabel,
formatPercent,
formatMoneyWithDecimals,
} from 'common/util/format'
import { computeCpmmBet } from 'common/new-bet'
import { User, firebaseLogin } from 'web/lib/firebase/users'
Expand All @@ -41,6 +42,7 @@ import { getCpmmProbability } from 'common/calculate-cpmm'
import { removeUndefinedProps } from 'common/util/object'
import { calculateCpmmMultiArbitrageBet } from 'common/calculate-cpmm-arbitrage'
import LimitOrderPanel from './limit-order-panel'
import { useIsAdvancedTrader } from 'web/hooks/use-is-advanced-trader'

export type BinaryOutcomes = 'YES' | 'NO' | undefined

Expand Down Expand Up @@ -255,6 +257,8 @@ export function BuyPanel(props: {

const selected = seeLimit ? 'LIMIT' : outcome

const isAdvancedTrader = useIsAdvancedTrader()

return (
<Col>
<Row
Expand Down Expand Up @@ -336,6 +340,8 @@ export function BuyPanel(props: {
? getStonkDisplayShares(contract, currentPayout, 2)
: isPseudoNumeric
? Math.floor(currentPayout)
: isAdvancedTrader
? formatMoneyWithDecimals(currentPayout)
: formatMoney(currentPayout)}
</span>
<span className="text-ink-500 pr-3 text-sm">
Expand Down
24 changes: 16 additions & 8 deletions web/components/bet/bet-summary.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import clsx from 'clsx'

import { formatMoney } from 'common/util/format'
import {
formatMoney,
formatMoneyWithDecimals,
} from 'common/util/format'
import { Col } from '../layout/col'
import { Contract } from 'web/lib/firebase/contracts'
import { Row } from '../layout/row'
Expand All @@ -15,6 +18,7 @@ import { getWinningTweet, TweetButton } from '../buttons/tweet-button'
import { CPMMContract } from 'common/contract'
import { SellRow } from 'web/components/bet/sell-row'
import { User } from 'common/user'
import { useIsAdvancedTrader } from 'web/hooks/use-is-advanced-trader'

export function UserBetsSummary(props: {
contract: Contract
Expand Down Expand Up @@ -80,6 +84,8 @@ export function BetsSummary(props: {
const prob = contract.mechanism === 'cpmm-1' ? getProbability(contract) : 0
const expectation = prob * yesWinnings + (1 - prob) * noWinnings

const isAdvancedTrader = useIsAdvancedTrader()

if (metrics.invested === 0 && metrics.profit === 0) return null

return (
Expand All @@ -89,7 +95,9 @@ export function BetsSummary(props: {
<Col>
<div className="text-ink-500 text-sm">Payout</div>
<div className="whitespace-nowrap">
{formatMoney(payout)}{' '}
{isAdvancedTrader
? formatMoneyWithDecimals(payout)
: formatMoney(payout)}{' '}
<ProfitBadge profitPercent={profitPercent} />
</div>
</Col>
Expand Down Expand Up @@ -128,11 +136,11 @@ export function BetsSummary(props: {
<div className="whitespace-nowrap">
{position > 1e-7 ? (
<>
{formatMoney(position)} on <YesLabel />
{isAdvancedTrader ? formatMoneyWithDecimals(position) : formatMoney(position)} on <YesLabel />
</>
) : position < -1e-7 ? (
<>
{formatMoney(-position)} on <NoLabel />
{isAdvancedTrader ? formatMoneyWithDecimals(-position) : formatMoney(-position)} on <NoLabel />
</>
) : (
'——'
Expand All @@ -150,7 +158,7 @@ export function BetsSummary(props: {
} position in the question is worth right now according to the current probability.`}
/>
</div>
<div className="whitespace-nowrap">{formatMoney(payout)}</div>
<div className="whitespace-nowrap">{isAdvancedTrader ? formatMoneyWithDecimals(payout) : formatMoney(payout)}</div>
</Col>
)
)}
Expand All @@ -171,7 +179,7 @@ export function BetsSummary(props: {
Spent{' '}
<InfoTooltip text="Cost basis. Cash originally invested in this question, using average cost accounting." />
</div>
<div className="whitespace-nowrap">{formatMoney(invested)}</div>
<div className="whitespace-nowrap">{isAdvancedTrader ? formatMoneyWithDecimals(invested) : formatMoney(invested)}</div>
</Col>

{isBinary && !resolution && !hideValue && (
Expand All @@ -184,7 +192,7 @@ export function BetsSummary(props: {
} position in the question is worth right now according to the current probability.`}
/>
</div>
<div className="whitespace-nowrap">{formatMoney(expectation)}</div>
<div className="whitespace-nowrap">{isAdvancedTrader ? formatMoneyWithDecimals(expectation) : formatMoney(expectation)}</div>
</Col>
)}

Expand All @@ -199,7 +207,7 @@ export function BetsSummary(props: {
/>
</div>
<div className="whitespace-nowrap">
{formatMoney(profit)}
{isAdvancedTrader ? formatMoneyWithDecimals(profit) : formatMoney(profit)}
<ProfitBadge profitPercent={profitPercent} round={true} />
</div>
</Col>
Expand Down
Loading