deduct market ante from profits

This commit is contained in:
mantikoros 2022-05-09 15:40:02 -04:00
parent e8ab863557
commit 535154b190
2 changed files with 7 additions and 3 deletions

View File

@ -118,7 +118,7 @@ export const createContract = functions
tags ?? [] tags ?? []
) )
if (!isFree && ante) await chargeUser(creator.id, ante) if (!isFree && ante) await chargeUser(creator.id, ante, true)
await contractRef.create(contract) await contractRef.create(contract)

View File

@ -79,9 +79,13 @@ export const payUser = (userId: string, payout: number, isDeposit = false) => {
return updateUserBalance(userId, payout, isDeposit) return updateUserBalance(userId, payout, isDeposit)
} }
export const chargeUser = (userId: string, charge: number) => { export const chargeUser = (
userId: string,
charge: number,
isAnte?: boolean
) => {
if (!isFinite(charge) || charge <= 0) if (!isFinite(charge) || charge <= 0)
throw new Error('User charge is not positive: ' + charge) throw new Error('User charge is not positive: ' + charge)
return updateUserBalance(userId, -charge) return updateUserBalance(userId, -charge, isAnte)
} }