migration: make up fake share qty for sold shares

This commit is contained in:
mantikoros 2022-04-18 11:23:55 -05:00
parent dc9af1c5b0
commit 789a505f97
2 changed files with 10 additions and 3 deletions

View File

@ -8,7 +8,7 @@ const formatter = new Intl.NumberFormat('en-US', {
})
export function formatMoney(amount: number) {
const newAmount = Math.floor(amount) === 0 ? 0 : Math.floor(amount) // handle -0 case
const newAmount = Math.round(amount) === 0 ? 0 : Math.floor(amount) // handle -0 case
return (
ENV_CONFIG.moneyMoniker + ' ' + formatter.format(newAmount).replace('$', '')
)

View File

@ -47,11 +47,18 @@ async function recalculateContract(contractRef: DocRef, isCommit = false) {
(b) => b.createdTime
)
const getSoldBetPayout = (bet: Bet) => {
const soldBet = bets.find((b) => bet.sale?.betId === b.id)
return soldBet
? -soldBet.amount / Math.sqrt(soldBet.probBefore * soldBet.probAfter)
: 0
}
for (let bet of bets) {
const shares = bet.sale
? -bet.sale.amount
? getSoldBetPayout(bet)
: bet.isSold
? bets.find((b) => b.sale?.betId === bet.id)?.sale?.amount ?? 0
? bet.amount / Math.sqrt(bet.probBefore * bet.probAfter) // make up fake share qty
: calculateStandardDpmPayout(contract, bet, bet.outcome)
console.log(