Don't run share redemption after adding liquidity (#631)
This commit is contained in:
parent
43b30e6d04
commit
5fd42df1ed
|
@ -4,7 +4,6 @@ import { z } from 'zod'
|
||||||
import { Contract } from '../../common/contract'
|
import { Contract } from '../../common/contract'
|
||||||
import { User } from '../../common/user'
|
import { User } from '../../common/user'
|
||||||
import { removeUndefinedProps } from '../../common/util/object'
|
import { removeUndefinedProps } from '../../common/util/object'
|
||||||
import { redeemShares } from './redeem-shares'
|
|
||||||
import { getNewLiquidityProvision } from '../../common/add-liquidity'
|
import { getNewLiquidityProvision } from '../../common/add-liquidity'
|
||||||
import { APIError, newEndpoint, validate } from './api'
|
import { APIError, newEndpoint, validate } from './api'
|
||||||
|
|
||||||
|
@ -19,8 +18,7 @@ export const addliquidity = newEndpoint({}, async (req, auth) => {
|
||||||
if (!isFinite(amount)) throw new APIError(400, 'Invalid amount')
|
if (!isFinite(amount)) throw new APIError(400, 'Invalid amount')
|
||||||
|
|
||||||
// run as transaction to prevent race conditions
|
// run as transaction to prevent race conditions
|
||||||
return await firestore
|
return await firestore.runTransaction(async (transaction) => {
|
||||||
.runTransaction(async (transaction) => {
|
|
||||||
const userDoc = firestore.doc(`users/${auth.uid}`)
|
const userDoc = firestore.doc(`users/${auth.uid}`)
|
||||||
const userSnap = await transaction.get(userDoc)
|
const userSnap = await transaction.get(userDoc)
|
||||||
if (!userSnap.exists) throw new APIError(400, 'User not found')
|
if (!userSnap.exists) throw new APIError(400, 'User not found')
|
||||||
|
@ -87,10 +85,6 @@ export const addliquidity = newEndpoint({}, async (req, auth) => {
|
||||||
|
|
||||||
return newLiquidityProvision
|
return newLiquidityProvision
|
||||||
})
|
})
|
||||||
.then(async (result) => {
|
|
||||||
await redeemShares(auth.uid, contractId)
|
|
||||||
return result
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const firestore = admin.firestore()
|
const firestore = admin.firestore()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user