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 payout = 0
let loan = 0
let sellProfit = 0
let saleValue = 0
let redeemed = 0
for (const bet of yourBets) {
const { isSold, sale, amount, loanAmount, isRedemption } = bet
if (isSold) {
sellProfit -= amount
invested += amount
} else if (sale) {
sellProfit += sale.amount
saleValue += sale.amount
} else {
if (isRedemption) {
redeemed += -1 * amount
} else if (amount > 0) {
invested += amount
} else {
sellProfit -= amount
saleValue -= amount
}
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 netInvestment = payout - loan

View File

@ -321,6 +321,8 @@ export function MyBetsSummary(props: {
bets
)
console.log({ invested, profit, payout })
return (
<Row className={clsx('flex-wrap gap-4 sm:flex-nowrap sm:gap-6', className)}>
<Row className="gap-4 sm:gap-6">