Merge fixes
This commit is contained in:
parent
cf85a8cc61
commit
84d66d8462
|
@ -75,10 +75,8 @@ export const createanswer = newEndpoint(opts, async (req, auth) => {
|
||||||
}
|
}
|
||||||
transaction.create(newAnswerDoc, answer)
|
transaction.create(newAnswerDoc, answer)
|
||||||
|
|
||||||
const loanAmount = 0
|
|
||||||
|
|
||||||
const { newBet, newPool, newTotalShares, newTotalBets } =
|
const { newBet, newPool, newTotalShares, newTotalBets } =
|
||||||
getNewMultiBetInfo(answerId, amount, contract, loanAmount)
|
getNewMultiBetInfo(answerId, amount, contract)
|
||||||
|
|
||||||
const newBalance = user.balance - amount
|
const newBalance = user.balance - amount
|
||||||
const betDoc = firestore.collection(`contracts/${contractId}/bets`).doc()
|
const betDoc = firestore.collection(`contracts/${contractId}/bets`).doc()
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import * as functions from 'firebase-functions'
|
import * as functions from 'firebase-functions'
|
||||||
import * as admin from 'firebase-admin'
|
import * as admin from 'firebase-admin'
|
||||||
import { getValues, log, writeAsync } from './utils'
|
import { getValues, log, writeAsync } from './utils'
|
||||||
import { Bet } from 'common/bet'
|
import { Bet, LimitBet } from 'common/bet'
|
||||||
import { Contract, CPMMContract, FreeResponseContract } from 'common/contract'
|
import { Contract, CPMMContract, FreeResponseContract } from 'common/contract'
|
||||||
import { User } from 'common/user'
|
import { User } from 'common/user'
|
||||||
import { Dictionary, groupBy, keyBy, minBy, sumBy } from 'lodash'
|
import { Dictionary, groupBy, keyBy, minBy, sumBy } from 'lodash'
|
||||||
|
@ -34,21 +34,23 @@ async function updateLoansCore() {
|
||||||
const contractsById = keyBy(contracts, (contract) => contract.id)
|
const contractsById = keyBy(contracts, (contract) => contract.id)
|
||||||
const betsByUser = groupBy(bets, (bet) => bet.userId)
|
const betsByUser = groupBy(bets, (bet) => bet.userId)
|
||||||
|
|
||||||
const userLoanUpdates = users.map((user) =>
|
const userLoanUpdates = users
|
||||||
getUserLoanUpdates(betsByUser[user.id] ?? [], contractsById).betUpdates
|
.map(
|
||||||
).flat()
|
(user) =>
|
||||||
|
getUserLoanUpdates(betsByUser[user.id] ?? [], contractsById).betUpdates
|
||||||
|
)
|
||||||
|
.flat()
|
||||||
|
|
||||||
const betUpdates = userLoanUpdates
|
const betUpdates = userLoanUpdates.map((update) => ({
|
||||||
.map((update) => ({
|
doc: firestore
|
||||||
doc: firestore
|
.collection('contracts')
|
||||||
.collection('contracts')
|
.doc(update.contractId)
|
||||||
.doc(update.contractId)
|
.collection('bets')
|
||||||
.collection('bets')
|
.doc(update.betId),
|
||||||
.doc(update.betId),
|
fields: {
|
||||||
fields: {
|
loanAmount: update.loanTotal,
|
||||||
loanAmount: update.loanTotal,
|
},
|
||||||
},
|
}))
|
||||||
}))
|
|
||||||
|
|
||||||
await writeAsync(firestore, betUpdates)
|
await writeAsync(firestore, betUpdates)
|
||||||
}
|
}
|
||||||
|
@ -91,7 +93,13 @@ const getBinaryContractLoanUpdate = (contract: CPMMContract, bets: Bet[]) => {
|
||||||
const shares = YES || NO
|
const shares = YES || NO
|
||||||
const outcome = YES ? 'YES' : 'NO'
|
const outcome = YES ? 'YES' : 'NO'
|
||||||
|
|
||||||
const { saleValue } = calculateCpmmSale(contract, shares, outcome)
|
const unfilledBets: LimitBet[] = []
|
||||||
|
const { saleValue } = calculateCpmmSale(
|
||||||
|
contract,
|
||||||
|
shares,
|
||||||
|
outcome,
|
||||||
|
unfilledBets
|
||||||
|
)
|
||||||
const loanAmount = sumBy(bets, (bet) => bet.loanAmount ?? 0)
|
const loanAmount = sumBy(bets, (bet) => bet.loanAmount ?? 0)
|
||||||
const oldestBet = minBy(bets, (bet) => bet.createdTime)
|
const oldestBet = minBy(bets, (bet) => bet.createdTime)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user