Skip to content

Commit

Permalink
Update multi send number validation
Browse files Browse the repository at this point in the history
  • Loading branch information
KuznetsovNikita committed Jun 12, 2024
1 parent e025332 commit c99e044
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 23 deletions.
11 changes: 0 additions & 11 deletions packages/uikit/src/components/transfer/amountView/AmountViewUI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,17 +182,6 @@ export const replaceTypedDecimalSeparator = (value: string): string => {
return value;
};

export const replaceSingleDecimalSeparator = (value: string): string => {
const notSeparator = getNotDecimalSeparator();
if (notSeparator) {
const separators = value.matchAll(new RegExp(`\\${notSeparator}`, 'g'));
if (separators && [...separators].length === 1) {
return value.replace(notSeparator, getDecimalSeparator());
}
}
return value;
};

export const seeIfValueValid = (value: string, decimals: number) => {
if (value.length > 21) return false;
if (value !== '') {
Expand Down
18 changes: 6 additions & 12 deletions packages/uikit/src/state/multiSend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ import { TonRecipient } from '@tonkeeper/core/dist/entries/send';
import { csvStringToArray } from '@tonkeeper/core/dist/service/parserService';
import { DNSApi, JettonsApi } from '@tonkeeper/core/dist/tonApiV2';
import { seeIfValidTonAddress } from '@tonkeeper/core/dist/utils/common';
import { getDecimalSeparator } from '@tonkeeper/core/dist/utils/formatting';
import { formatSendValue, isNumeric } from '@tonkeeper/core/dist/utils/send';
import { notNullish } from '@tonkeeper/core/dist/utils/types';
import { useCallback } from 'react';
import { ErrorOption } from 'react-hook-form';
import { seeIfInvalidDns } from '../components/transfer/RecipientView';
import { replaceSingleDecimalSeparator } from '../components/transfer/amountView/AmountViewUI';
import { useAppContext } from '../hooks/appContext';
import { useAppSdk } from '../hooks/appSdk';

Expand Down Expand Up @@ -320,17 +319,10 @@ const parseTableRow = (row: string[], rowIndex: number) => {
};

const parseAmount = (val: string) => {
if (!/^[0-9 ]+([\.,][0-9]+)?$/.test(val)) {
if (!isNumeric(val)) {
throw new Error('Not a valid number');
}

val = val.replace(',', '.').replaceAll(' ', '');
const number = parseFloat(val);
if (!isFinite(number)) {
throw new Error('Not a valid number');
}

return val.replace('.', getDecimalSeparator());
return formatSendValue(val);
};

const parseAsset = (val: string) => {
Expand Down Expand Up @@ -415,6 +407,8 @@ const validatePastedRow = async (
throw new ListImportError('Invalid input', 'invalid_row_length');
}

const amount = parseAmount(row[1]);

let receiver: TonRecipient;

const res = await receiverValidator(row[0]);
Expand All @@ -431,7 +425,7 @@ const validatePastedRow = async (

return {
receiver,
amount: { inFiat: false, value: replaceSingleDecimalSeparator(row[1]) },
amount: { inFiat: false, value: amount },
comment: row[2]
};
};
Expand Down

0 comments on commit c99e044

Please sign in to comment.