Tweak current investment calculation

This commit is contained in:
James Grugett 2022-04-13 22:28:29 -05:00
parent 2a3593c269
commit 8a59ab3180
2 changed files with 13 additions and 13 deletions

View File

@ -115,7 +115,8 @@ export function resolvedPayout(contract: Contract, bet: Bet) {
export function getContractBetMetrics(contract: Contract, yourBets: Bet[]) { export function getContractBetMetrics(contract: Contract, yourBets: Bet[]) {
const { resolution } = contract const { resolution } = contract
let invested = 0 let currentInvested = 0
let totalInvested = 0
let payout = 0 let payout = 0
let loan = 0 let loan = 0
let saleValue = 0 let saleValue = 0
@ -124,18 +125,19 @@ export function getContractBetMetrics(contract: Contract, yourBets: Bet[]) {
for (const bet of yourBets) { for (const bet of yourBets) {
const { isSold, sale, amount, loanAmount, isRedemption } = bet const { isSold, sale, amount, loanAmount, isRedemption } = bet
if (isSold) { if (isSold) {
invested += amount totalInvested += amount
} else if (sale) { } else if (sale) {
saleValue += sale.amount saleValue += sale.amount
} else { } else {
if (isRedemption) { if (isRedemption) {
redeemed += -1 * amount redeemed += -1 * amount
} else if (amount > 0) { } else if (amount > 0) {
invested += amount totalInvested += amount
} else { } else {
saleValue -= amount saleValue -= amount
} }
currentInvested += amount
loan += loanAmount ?? 0 loan += loanAmount ?? 0
payout += resolution payout += resolution
? calculatePayout(contract, bet, resolution) ? calculatePayout(contract, bet, resolution)
@ -143,16 +145,16 @@ export function getContractBetMetrics(contract: Contract, yourBets: Bet[]) {
} }
} }
const profit = payout + saleValue + redeemed - invested const netPayout = payout - loan
const profitPercent = (profit / invested) * 100 const profit = payout + saleValue + redeemed - totalInvested
const netInvestment = payout - loan const profitPercent = (profit / totalInvested) * 100
return { return {
invested, invested: Math.max(0, currentInvested),
payout, payout,
netPayout,
profit, profit,
profitPercent, profitPercent,
netInvestment,
} }
} }
@ -160,8 +162,8 @@ export function getContractBetNullMetrics() {
return { return {
invested: 0, invested: 0,
payout: 0, payout: 0,
netPayout: 0,
profit: 0, profit: 0,
profitPercent: 0, profitPercent: 0,
netInvestment: 0,
} }
} }

View File

@ -119,7 +119,7 @@ export function BetsList(props: { user: User }) {
) )
const currentNetInvestment = _.sumBy( const currentNetInvestment = _.sumBy(
unsettled, unsettled,
(c) => contractsMetrics[c.id].netInvestment (c) => contractsMetrics[c.id].netPayout
) )
const totalPortfolio = currentNetInvestment + user.balance const totalPortfolio = currentNetInvestment + user.balance
@ -127,7 +127,7 @@ export function BetsList(props: { user: User }) {
const totalPnl = totalPortfolio - user.totalDeposits const totalPnl = totalPortfolio - user.totalDeposits
const totalProfitPercent = (totalPnl / user.totalDeposits) * 100 const totalProfitPercent = (totalPnl / user.totalDeposits) * 100
const investedProfitPercent = const investedProfitPercent =
((currentBetsValue - currentInvested) / currentInvested) * 100 ((currentBetsValue - currentInvested) / (currentInvested + 0.1)) * 100
return ( return (
<Col className="mt-6 gap-4 sm:gap-6"> <Col className="mt-6 gap-4 sm:gap-6">
@ -321,8 +321,6 @@ export function MyBetsSummary(props: {
bets bets
) )
console.log({ invested, profit, payout })
return ( return (
<Row className={clsx('flex-wrap gap-4 sm:flex-nowrap sm:gap-6', className)}> <Row className={clsx('flex-wrap gap-4 sm:flex-nowrap sm:gap-6', className)}>
<Row className="gap-4 sm:gap-6"> <Row className="gap-4 sm:gap-6">