Fix profit calculation for dpm sales

This commit is contained in:
James Grugett 2022-04-13 20:42:47 -05:00
parent e58ec54546
commit 2a3593c269
2 changed files with 6 additions and 5 deletions

View File

@ -118,23 +118,22 @@ export function getContractBetMetrics(contract: Contract, yourBets: Bet[]) {
let invested = 0 let invested = 0
let payout = 0 let payout = 0
let loan = 0 let loan = 0
let sellProfit = 0 let saleValue = 0
let redeemed = 0 let redeemed = 0
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) {
sellProfit -= amount
invested += amount invested += amount
} else if (sale) { } else if (sale) {
sellProfit += 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 invested += amount
} else { } else {
sellProfit -= amount saleValue -= amount
} }
loan += loanAmount ?? 0 loan += loanAmount ?? 0
@ -144,7 +143,7 @@ export function getContractBetMetrics(contract: Contract, yourBets: Bet[]) {
} }
} }
const profit = payout - invested + sellProfit + redeemed const profit = payout + saleValue + redeemed - invested
const profitPercent = (profit / invested) * 100 const profitPercent = (profit / invested) * 100
const netInvestment = payout - loan const netInvestment = payout - loan

View File

@ -321,6 +321,8 @@ 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">