Portfolio: Fix calculation of whether you sold all your shares
This commit is contained in:
parent
2ea7ddc1aa
commit
45f92379bc
|
@ -131,9 +131,13 @@ export function getContractBetMetrics(contract: Contract, yourBets: Bet[]) {
|
||||||
let loan = 0
|
let loan = 0
|
||||||
let saleValue = 0
|
let saleValue = 0
|
||||||
let redeemed = 0
|
let redeemed = 0
|
||||||
|
const totalShares: { [outcome: string]: number } = {}
|
||||||
|
|
||||||
for (const bet of yourBets) {
|
for (const bet of yourBets) {
|
||||||
const { isSold, sale, amount, loanAmount, isRedemption } = bet
|
const { isSold, sale, amount, loanAmount, isRedemption, shares, outcome } =
|
||||||
|
bet
|
||||||
|
totalShares[outcome] = (totalShares[outcome] ?? 0) + shares
|
||||||
|
|
||||||
if (isSold) {
|
if (isSold) {
|
||||||
totalInvested += amount
|
totalInvested += amount
|
||||||
} else if (sale) {
|
} else if (sale) {
|
||||||
|
@ -165,6 +169,7 @@ export function getContractBetMetrics(contract: Contract, yourBets: Bet[]) {
|
||||||
netPayout,
|
netPayout,
|
||||||
profit,
|
profit,
|
||||||
profitPercent,
|
profitPercent,
|
||||||
|
totalShares,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,6 +180,7 @@ export function getContractBetNullMetrics() {
|
||||||
netPayout: 0,
|
netPayout: 0,
|
||||||
profit: 0,
|
profit: 0,
|
||||||
profitPercent: 0,
|
profitPercent: 0,
|
||||||
|
totalShares: {} as { [outcome: string]: number },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -125,13 +125,13 @@ export function BetsList(props: { user: User }) {
|
||||||
.filter((c) => {
|
.filter((c) => {
|
||||||
if (filter === 'all') return true
|
if (filter === 'all') return true
|
||||||
|
|
||||||
const metrics = contractsMetrics[c.id]
|
const { totalShares } = contractsMetrics[c.id]
|
||||||
|
const hasSoldAll = Object.values(totalShares).every(
|
||||||
|
(shares) => shares === 0
|
||||||
|
)
|
||||||
|
|
||||||
// Filter for contracts you sold out of.
|
if (filter === 'sold') return hasSoldAll
|
||||||
if (filter === 'sold') return metrics.payout === 0
|
return !hasSoldAll
|
||||||
|
|
||||||
// Filter for contracts where you currently have shares.
|
|
||||||
return metrics.payout > 0
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const [settled, unsettled] = partition(
|
const [settled, unsettled] = partition(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user