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)
|
||||
|
||||
const userPayouts = eligibleUsers
|
||||
.map((user) => {
|
||||
const userPayouts = eligibleUsers.map((user) => {
|
||||
const updates = userLoanUpdates.filter(
|
||||
(update) => update.userId === user.id
|
||||
)
|
||||
|
@ -83,7 +82,6 @@ async function updateLoansCore() {
|
|||
payout: sumBy(updates, (update) => update.newLoan),
|
||||
}
|
||||
})
|
||||
.filter((update) => update.payout > 0)
|
||||
|
||||
log(`${userPayouts.length} user payouts`)
|
||||
|
||||
|
@ -156,7 +154,7 @@ const getBinaryContractLoanUpdate = (contract: CPMMContract, bets: Bet[]) => {
|
|||
const oldestBet = minBy(bets, (bet) => bet.createdTime)
|
||||
|
||||
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
|
||||
|
||||
|
@ -180,6 +178,8 @@ const getFreeResponseContractLoanUpdate = (
|
|||
const newLoan = calculateNewLoan(bet.amount, loanAmount)
|
||||
const loanTotal = loanAmount + newLoan
|
||||
|
||||
if (isNaN(newLoan) || newLoan <= 0) return undefined
|
||||
|
||||
return {
|
||||
userId: bet.userId,
|
||||
contractId: contract.id,
|
||||
|
|
Loading…
Reference in New Issue
Block a user