Handle NaN and negative loan calcs
This commit is contained in:
parent
d79783ea25
commit
e8ead84793
|
@ -73,8 +73,7 @@ async function updateLoansCore() {
|
||||||
|
|
||||||
await writeAsync(firestore, betUpdates)
|
await writeAsync(firestore, betUpdates)
|
||||||
|
|
||||||
const userPayouts = eligibleUsers
|
const userPayouts = eligibleUsers.map((user) => {
|
||||||
.map((user) => {
|
|
||||||
const updates = userLoanUpdates.filter(
|
const updates = userLoanUpdates.filter(
|
||||||
(update) => update.userId === user.id
|
(update) => update.userId === user.id
|
||||||
)
|
)
|
||||||
|
@ -83,7 +82,6 @@ async function updateLoansCore() {
|
||||||
payout: sumBy(updates, (update) => update.newLoan),
|
payout: sumBy(updates, (update) => update.newLoan),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.filter((update) => update.payout > 0)
|
|
||||||
|
|
||||||
log(`${userPayouts.length} user payouts`)
|
log(`${userPayouts.length} user payouts`)
|
||||||
|
|
||||||
|
@ -156,7 +154,7 @@ const getBinaryContractLoanUpdate = (contract: CPMMContract, bets: Bet[]) => {
|
||||||
const oldestBet = minBy(bets, (bet) => bet.createdTime)
|
const oldestBet = minBy(bets, (bet) => bet.createdTime)
|
||||||
|
|
||||||
const newLoan = calculateNewLoan(invested, loanAmount)
|
const newLoan = calculateNewLoan(invested, loanAmount)
|
||||||
if (newLoan <= 0 || !oldestBet) return undefined
|
if (isNaN(newLoan) || newLoan <= 0 || !oldestBet) return undefined
|
||||||
|
|
||||||
const loanTotal = (oldestBet.loanAmount ?? 0) + newLoan
|
const loanTotal = (oldestBet.loanAmount ?? 0) + newLoan
|
||||||
|
|
||||||
|
@ -180,6 +178,8 @@ const getFreeResponseContractLoanUpdate = (
|
||||||
const newLoan = calculateNewLoan(bet.amount, loanAmount)
|
const newLoan = calculateNewLoan(bet.amount, loanAmount)
|
||||||
const loanTotal = loanAmount + newLoan
|
const loanTotal = loanAmount + newLoan
|
||||||
|
|
||||||
|
if (isNaN(newLoan) || newLoan <= 0) return undefined
|
||||||
|
|
||||||
return {
|
return {
|
||||||
userId: bet.userId,
|
userId: bet.userId,
|
||||||
contractId: contract.id,
|
contractId: contract.id,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user