deduct market ante from profits
This commit is contained in:
		
							parent
							
								
									e8ab863557
								
							
						
					
					
						commit
						535154b190
					
				| 
						 | 
				
			
			@ -118,7 +118,7 @@ export const createContract = functions
 | 
			
		|||
        tags ?? []
 | 
			
		||||
      )
 | 
			
		||||
 | 
			
		||||
      if (!isFree && ante) await chargeUser(creator.id, ante)
 | 
			
		||||
      if (!isFree && ante) await chargeUser(creator.id, ante, true)
 | 
			
		||||
 | 
			
		||||
      await contractRef.create(contract)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -79,9 +79,13 @@ export const payUser = (userId: string, payout: number, isDeposit = false) => {
 | 
			
		|||
  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)
 | 
			
		||||
    throw new Error('User charge is not positive: ' + charge)
 | 
			
		||||
 | 
			
		||||
  return updateUserBalance(userId, -charge)
 | 
			
		||||
  return updateUserBalance(userId, -charge, isAnte)
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user