Skip to content

Commit 94e1a4d

Browse files
committed
fix: validate deposit data: show less errors
1 parent 0c00742 commit 94e1a4d

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

shared/hook-form/validation/validate-deposit-data.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { DepositData, DepositDataSDK } from '@lidofinance/lido-csm-sdk';
2-
import { groupBy, mapValues } from 'lodash';
2+
import { groupBy, mapValues, uniqBy } from 'lodash';
33
import { KEYS_UPLOAD_TX_LIMIT } from 'consts/keys';
44
import { ValidationError } from './validation-error';
55

@@ -22,9 +22,14 @@ export const validateDepositData = async ({
2222
const errors = await sdk.validateDepositData(depositData);
2323

2424
if (errors?.length) {
25-
const types = mapValues(groupBy(errors, 'index'), (errors) =>
26-
errors.map((error) => error.message),
27-
);
25+
const types = mapValues(groupBy(errors, 'index'), (errors) => {
26+
const withField = errors.filter((e) => e.field);
27+
const withoutField = errors.filter((e) => !e.field);
28+
const uniqueWithField = uniqBy(withField, 'field');
29+
return [...uniqueWithField, ...withoutField].map(
30+
(error) => error.message,
31+
);
32+
});
2833

2934
throw new ValidationError(
3035
'depositData',

0 commit comments

Comments
 (0)