2022-06-08 18:00:49 +00:00
|
|
|
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)
|
|
|
|
|
2022-07-09 17:53:50 +00:00
|
|
|
const userShares = getUserLiquidityShares(
|
|
|
|
userId,
|
|
|
|
contract,
|
|
|
|
liquidities ?? [],
|
|
|
|
true
|
|
|
|
)
|
2022-06-08 18:00:49 +00:00
|
|
|
return userShares
|
|
|
|
}
|