From 87ae478b9c6f3a277a6aa47836a947e272494f6b Mon Sep 17 00:00:00 2001 From: Edd Date: Thu, 8 Sep 2022 10:12:01 +0000 Subject: [PATCH] fix(positions): split market name more defensively (#1265) --- libs/positions/src/lib/positions-table.spec.tsx | 12 ++++++++++++ libs/positions/src/lib/positions-table.tsx | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/libs/positions/src/lib/positions-table.spec.tsx b/libs/positions/src/lib/positions-table.spec.tsx index 0df7fc177..3b0128c38 100644 --- a/libs/positions/src/lib/positions-table.spec.tsx +++ b/libs/positions/src/lib/positions-table.spec.tsx @@ -66,6 +66,18 @@ it('Splits market name', async () => { expect(screen.getByText('31 july 2022')).toBeTruthy(); }); +it('Does not fail if the market name does not match the split pattern', async () => { + const breakingMarketName = 'OP/USD AUG-SEP22 - Incentive'; + const row = [ + Object.assign({}, singleRow, { marketName: breakingMarketName }), + ]; + await act(async () => { + render(); + }); + + expect(screen.getByText(breakingMarketName)).toBeTruthy(); +}); + it('add color and sign to amount, displays positive notional value', async () => { let result: RenderResult; await act(async () => { diff --git a/libs/positions/src/lib/positions-table.tsx b/libs/positions/src/lib/positions-table.tsx index 9b45b366d..fa2ca2abf 100644 --- a/libs/positions/src/lib/positions-table.tsx +++ b/libs/positions/src/lib/positions-table.tsx @@ -172,7 +172,7 @@ export const PositionsTable = forwardRef( } // split market name into two parts, 'Part1 (Part2)' or 'Part1 - Part2' const matches = value.match(/^(.*)(\((.*)\)| - (.*))\s*$/); - if (matches) { + if (matches && matches[1] && matches[3]) { return [matches[1].trim(), matches[3].trim()]; } return [value];