manifold/web/hooks/use-liquidity.ts
mantikoros 0ec15ff2f8
Make liquidity great again (#1020)
* add subsidy

* drizzle liquidity

* update liquidity panel

* remove addliquidity

* update cloud functions index

* remove json endpoints

* imports

* drizzle liquidity: add velocity; dev script; run every minute

* adjust speed

* logging

* liquidity button, dialog

* modal size

* modal

* info table

* pay back excess liquidity

* remove client withdrawal

* house liquidity subsidy

* disable liquidity button if market resolved or closed

* format tip amount
2022-10-10 21:56:16 -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
}