import { useCallback, useMemo, useRef } from 'react'; import { AsyncRenderer } from '@vegaprotocol/ui-toolkit'; import { useDataProvider } from '@vegaprotocol/react-helpers'; import { positionsMetricsDataProvider as dataProvider } from './positions-data-providers'; import type { Position } from './positions-data-providers'; import { Positions } from './positions'; import { useClosePosition } from '../'; interface PositionsManagerProps { partyId: string; } const getSymbols = (positions: Position[]) => Array.from(new Set(positions.map((position) => position.assetSymbol))).sort(); export const PositionsManager = ({ partyId }: PositionsManagerProps) => { const variables = useMemo(() => ({ partyId }), [partyId]); const assetSymbols = useRef(); const { submit, Dialog } = useClosePosition(); const onClose = useCallback( (position: Position) => { submit(position); }, [submit] ); const update = useCallback(({ data }: { data: Position[] | null }) => { if (data?.length) { const newAssetSymbols = getSymbols(data); if ( !newAssetSymbols.every( (symbol) => assetSymbols.current && assetSymbols.current.includes(symbol) ) ) { return false; } } return true; }, []); const { data, error, loading } = useDataProvider({ dataProvider, update, variables, }); return ( <> {data && getSymbols(data)?.map((assetSymbol) => ( ))}

Your position was not closed! This is still not implemented.

); };