2023-01-31 20:49:37 -08:00
|
|
|
import mangoStore from '@store/mangoStore'
|
|
|
|
import { useMemo } from 'react'
|
|
|
|
import useMangoAccount from './useMangoAccount'
|
|
|
|
|
|
|
|
const useOpenPerpPositions = () => {
|
|
|
|
const { mangoAccountAddress } = useMangoAccount()
|
|
|
|
const perpPositions = mangoStore((s) => s.mangoAccount.perpPositions)
|
|
|
|
|
|
|
|
const openPositions = useMemo(() => {
|
|
|
|
if (!mangoAccountAddress) return []
|
|
|
|
return Object.values(perpPositions).filter((p) =>
|
|
|
|
p.basePositionLots.toNumber()
|
|
|
|
)
|
2023-02-08 17:23:21 -08:00
|
|
|
}, [mangoAccountAddress, perpPositions])
|
2023-01-31 20:49:37 -08:00
|
|
|
|
|
|
|
return openPositions
|
|
|
|
}
|
|
|
|
|
|
|
|
export default useOpenPerpPositions
|