fix(positions): split market name more defensively (#1265)

This commit is contained in:
Edd 2022-09-08 10:12:01 +00:00 committed by GitHub
parent dc59859964
commit 87ae478b9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -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(<PositionsTable rowData={row} />);
});
expect(screen.getByText(breakingMarketName)).toBeTruthy();
});
it('add color and sign to amount, displays positive notional value', async () => {
let result: RenderResult;
await act(async () => {

View File

@ -172,7 +172,7 @@ export const PositionsTable = forwardRef<AgGridReact, Props>(
}
// 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];