From a80d1f194c157de48ec502f61e1b2903dfb9836e Mon Sep 17 00:00:00 2001 From: James Grugett Date: Sat, 27 Aug 2022 17:14:41 -0500 Subject: [PATCH] Don't redeem shares if there's only epsilon shares to redeem --- functions/src/redeem-shares.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/functions/src/redeem-shares.ts b/functions/src/redeem-shares.ts index 0a69521f..055aa2dc 100644 --- a/functions/src/redeem-shares.ts +++ b/functions/src/redeem-shares.ts @@ -5,6 +5,7 @@ import { getRedeemableAmount, getRedemptionBets } from '../../common/redeem' import { Contract } from '../../common/contract' import { User } from '../../common/user' +import { floatingEqual } from 'common/util/math' export const redeemShares = async (userId: string, contractId: string) => { return await firestore.runTransaction(async (trans) => { @@ -21,7 +22,7 @@ export const redeemShares = async (userId: string, contractId: string) => { const betsSnap = await trans.get(betsColl.where('userId', '==', userId)) const bets = betsSnap.docs.map((doc) => doc.data() as Bet) const { shares, loanPayment, netAmount } = getRedeemableAmount(bets) - if (netAmount === 0) { + if (floatingEqual(netAmount, 0)) { return { status: 'success' } } const [yesBet, noBet] = getRedemptionBets(shares, loanPayment, contract)