diff --git a/libs/positions/src/lib/positions-table.spec.tsx b/libs/positions/src/lib/positions-table.spec.tsx index 85b9dec1e..4e28596b9 100644 --- a/libs/positions/src/lib/positions-table.spec.tsx +++ b/libs/positions/src/lib/positions-table.spec.tsx @@ -172,3 +172,33 @@ it('displays realised and unrealised PNL', async () => { expect(cells[9].textContent).toEqual('1.23'); expect(cells[10].textContent).toEqual('4.56'); }); + +it('displays close button', async () => { + await act(async () => { + render( + { + return; + }} + /> + ); + }); + const cells = screen.getAllByRole('gridcell'); + expect(cells[12].textContent).toEqual('Close'); +}); + +it('do not display close button if openVolume is zero', async () => { + await act(async () => { + render( + { + return; + }} + /> + ); + }); + const cells = screen.getAllByRole('gridcell'); + expect(cells[12].textContent).toEqual(''); +}); diff --git a/libs/positions/src/lib/positions-table.tsx b/libs/positions/src/lib/positions-table.tsx index 203d19fd7..de3e9ecbb 100644 --- a/libs/positions/src/lib/positions-table.tsx +++ b/libs/positions/src/lib/positions-table.tsx @@ -381,14 +381,16 @@ export const PositionsTable = forwardRef( {onClose ? ( ) => ( - data && onClose(data)} - > - {t('Close')} - - )} + cellRenderer={({ data }: VegaICellRendererParams) => + data?.openVolume && data?.openVolume !== '0' ? ( + data && onClose(data)} + > + {t('Close')} + + ) : null + } /> ) : null}