2022-12-11 22:01:49 -08:00
|
|
|
import mangoStore from '@store/mangoStore'
|
2023-01-31 20:49:37 -08:00
|
|
|
import { useMemo } from 'react'
|
|
|
|
import useMangoAccount from './useMangoAccount'
|
2022-12-11 22:01:49 -08:00
|
|
|
import useMangoGroup from './useMangoGroup'
|
|
|
|
|
|
|
|
const useUnsettledPerpPositions = () => {
|
|
|
|
const { group } = useMangoGroup()
|
2023-01-31 20:49:37 -08:00
|
|
|
const { mangoAccountAddress } = useMangoAccount()
|
2022-12-11 22:01:49 -08:00
|
|
|
const perpPositions = mangoStore((s) => s.mangoAccount.perpPositions)
|
|
|
|
|
2023-01-31 20:49:37 -08:00
|
|
|
const positions = useMemo(() => {
|
|
|
|
if (!mangoAccountAddress) return []
|
|
|
|
return perpPositions.filter((p) => {
|
|
|
|
const market = group?.getPerpMarketByMarketIndex(p.marketIndex)
|
|
|
|
if (!market || !group) return false
|
2023-02-09 13:22:54 -08:00
|
|
|
return p.getUnsettledPnlUi(market) !== 0
|
2023-01-31 20:49:37 -08:00
|
|
|
})
|
2023-02-16 11:17:03 -08:00
|
|
|
}, [mangoAccountAddress, perpPositions, group])
|
2023-01-31 20:49:37 -08:00
|
|
|
|
|
|
|
return positions
|
2022-12-11 22:01:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
export default useUnsettledPerpPositions
|