manifold/web/hooks/use-liquidity.ts
mantikoros 0cd9943e0d
Liquidity withdrawal (#457)
* withdrawLiquidity cloud function

* update rules

* exclude antes from getCpmmLiquidityPoolWeights

* update correct lp shares

* liquidity panel

* don't create bet if less than 1 surplus share

* withdrawLiquidity return type

* static analysis fix

* hook dependency

* prettier

* renaming

* typo

* getCpmmLiquidityPoolWeights: always exclude antes

* delete unused function

* casting
2022-06-08 13:00:49 -05:00

27 lines
794 B
TypeScript

import { useEffect, useState } from 'react'
import { CPMMContract } from 'common/contract'
import { LiquidityProvision } from 'common/liquidity-provision'
import { getUserLiquidityShares } from 'common/calculate-cpmm'
import { listenForLiquidity } from 'web/lib/firebase/liquidity'
export const useLiquidity = (contractId: string) => {
const [liquidities, setLiquidities] = useState<
LiquidityProvision[] | undefined
>(undefined)
useEffect(() => {
return listenForLiquidity(contractId, setLiquidities)
}, [contractId])
return liquidities
}
export const useUserLiquidity = (contract: CPMMContract, userId: string) => {
const liquidities = useLiquidity(contract.id)
const userShares = getUserLiquidityShares(userId, contract, liquidities ?? [])
return userShares
}