From b3f7b87ef8a83876d86eca581e211c0c0ba749c7 Mon Sep 17 00:00:00 2001 From: James Grugett Date: Thu, 6 Oct 2022 21:43:14 -0500 Subject: [PATCH] Fix a bug --- common/new-bet.ts | 8 ++++---- functions/src/place-bet.ts | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/common/new-bet.ts b/common/new-bet.ts index c834cb90..2a9f3318 100644 --- a/common/new-bet.ts +++ b/common/new-bet.ts @@ -172,7 +172,7 @@ export const computeFills = ( let amount = betAmount let cpmmState = { pool: state.pool, p: state.p } let totalFees = noFees - const makerBalanceByUserId = { ...balanceByUserId } + const currentBalanceByUserId = { ...balanceByUserId } let i = 0 while (true) { @@ -191,17 +191,17 @@ export const computeFills = ( // Matched against bet. i++ const { userId } = maker.bet - const makerBalance = makerBalanceByUserId[userId] + const makerBalance = currentBalanceByUserId[userId] if (floatingGreaterEqual(makerBalance, maker.amount)) { - makerBalanceByUserId[userId] = makerBalance - maker.amount + currentBalanceByUserId[userId] = makerBalance - maker.amount } else { // Insufficient balance. Cancel maker bet. ordersToCancel.push(maker.bet) continue } - if (userId) takers.push(taker) + takers.push(taker) makers.push(maker) } diff --git a/functions/src/place-bet.ts b/functions/src/place-bet.ts index 4798dddf..50c89912 100644 --- a/functions/src/place-bet.ts +++ b/functions/src/place-bet.ts @@ -6,7 +6,7 @@ import { Query, Transaction, } from 'firebase-admin/firestore' -import { groupBy, mapValues, sumBy, uniq, uniqBy } from 'lodash' +import { groupBy, mapValues, sumBy, uniq } from 'lodash' import { APIError, newEndpoint, validate } from './api' import { Contract, CPMM_MIN_POOL_QTY } from '../../common/contract' @@ -217,7 +217,7 @@ export const getUnfilledBetsAndUserBalances = async ( const unfilledBets = unfilledBetsSnap.docs.map((doc) => doc.data()) // Get balance of all users with open limit orders. - const userIds = uniqBy(unfilledBets, (bet) => bet.userId) + const userIds = uniq(unfilledBets.map((bet) => bet.userId)) const userDocs = userIds.length === 0 ? []