fix: error message consitency (2486) (#2507)

fix: error message consitency (2486)
This commit is contained in:
Art 2023-01-04 13:25:11 +01:00 committed by GitHub
parent 904a1b7805
commit 1211d27011
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 68 additions and 62 deletions

View File

@ -8,7 +8,6 @@ import {
useOrderMargin,
useMaximumPositionSize,
useCalculateSlippage,
validateAmount,
} from '@vegaprotocol/deal-ticket';
import { InputError } from '@vegaprotocol/ui-toolkit';
import { BigNumber } from 'bignumber.js';
@ -23,6 +22,7 @@ import {
addDecimalsFormatNumber,
addDecimal,
formatNumber,
validateAmount,
} from '@vegaprotocol/react-helpers';
import {
useOrderSubmit,

View File

@ -1,7 +1,6 @@
import { FormGroup, Input, InputError } from '@vegaprotocol/ui-toolkit';
import { t, toDecimal } from '@vegaprotocol/react-helpers';
import { t, toDecimal, validateAmount } from '@vegaprotocol/react-helpers';
import type { DealTicketAmountProps } from './deal-ticket-amount';
import { validateAmount } from '../../utils';
export type DealTicketLimitAmountProps = Omit<
DealTicketAmountProps,

View File

@ -2,9 +2,10 @@ import {
addDecimalsFormatNumber,
t,
toDecimal,
validateAmount,
} from '@vegaprotocol/react-helpers';
import { Input, InputError, Tooltip } from '@vegaprotocol/ui-toolkit';
import { isMarketInAuction, validateAmount } from '../../utils';
import { isMarketInAuction } from '../../utils';
import type { DealTicketAmountProps } from './deal-ticket-amount';
import { getMarketPrice } from '../../utils/get-price';

View File

@ -1,6 +1,5 @@
export * from './get-default-order';
export * from './is-market-in-auction';
export * from './validate-amount';
export * from './validate-expiration';
export * from './validate-market-state';
export * from './validate-market-trading-mode';

View File

@ -5,6 +5,7 @@ import {
getDateTimeFormat,
addDecimal,
addDecimalsFormatNumber,
validateAmount,
} from '@vegaprotocol/react-helpers';
import * as Schema from '@vegaprotocol/types';
import {
@ -50,6 +51,7 @@ export const OrderEditDialog = ({
const step = toDecimal(order.market?.decimalPlaces ?? 0);
const stepSize = toDecimal(order.market?.positionDecimalPlaces ?? 0);
return (
<Dialog
open={isOpen}
@ -97,6 +99,7 @@ export const OrderEditDialog = ({
onSubmit={handleSubmit(onSubmit)}
data-testid="edit-order"
className="w-full mt-4"
noValidate
>
<div className="flex flex-col md:flex-row gap-4">
<FormGroup label={t('Price')} labelFor="limitPrice" className="grow">
@ -110,6 +113,7 @@ export const OrderEditDialog = ({
Number(value) > 0
? true
: t('The price cannot be negative'),
validate: validateAmount(step, t('Price')),
},
})}
id="limitPrice"
@ -129,6 +133,7 @@ export const OrderEditDialog = ({
validate: {
min: (value) =>
Number(value) > 0 ? true : t('The size cannot be negative'),
validate: validateAmount(stepSize, t('Size')),
},
})}
id="size"

View File

@ -0,0 +1,56 @@
import BigNumber from 'bignumber.js';
import { ethers } from 'ethers';
import { t } from '../i18n';
export const required = (value: string) => {
if (value === null || value === undefined || value === '') {
return t('Required');
}
return true;
};
export const ethereumAddress = (value: string) => {
if (!ethers.utils.isAddress(value)) {
return t('Invalid Ethereum address');
}
return true;
};
export const vegaPublicKey = (value: string) => {
if (value.length !== 64 || !/^[A-Fa-f0-9]*$/i.test(value)) {
return t('Invalid Vega key');
}
return true;
};
export const minSafe = (min: BigNumber) => (value: string) => {
if (new BigNumber(value).isLessThan(min)) {
return t('Value is below minimum');
}
return true;
};
export const maxSafe = (max: BigNumber) => (value: string) => {
if (new BigNumber(value).isGreaterThan(max)) {
return t('Value is above maximum');
}
return true;
};
export const suitableForSyntaxHighlighter = (str: string) => {
try {
const test = JSON.parse(str);
return test && Object.keys(test).length > 0;
} catch (e) {
return false;
}
};
export const validateJson = (value: string) => {
try {
JSON.parse(value);
return true;
} catch (e) {
return t('Must be valid JSON');
}
};

View File

@ -1,56 +1,2 @@
import BigNumber from 'bignumber.js';
import { ethers } from 'ethers';
import { t } from '../i18n';
export const required = (value: string) => {
if (value === null || value === undefined || value === '') {
return t('Required');
}
return true;
};
export const ethereumAddress = (value: string) => {
if (!ethers.utils.isAddress(value)) {
return t('Invalid Ethereum address');
}
return true;
};
export const vegaPublicKey = (value: string) => {
if (value.length !== 64 || !/^[A-Fa-f0-9]*$/i.test(value)) {
return t('Invalid Vega key');
}
return true;
};
export const minSafe = (min: BigNumber) => (value: string) => {
if (new BigNumber(value).isLessThan(min)) {
return t('Value is below minimum');
}
return true;
};
export const maxSafe = (max: BigNumber) => (value: string) => {
if (new BigNumber(value).isGreaterThan(max)) {
return t('Value is above maximum');
}
return true;
};
export const suitableForSyntaxHighlighter = (str: string) => {
try {
const test = JSON.parse(str);
return test && Object.keys(test).length > 0;
} catch (e) {
return false;
}
};
export const validateJson = (value: string) => {
try {
JSON.parse(value);
return true;
} catch (e) {
return t('Must be valid JSON');
}
};
export * from './common';
export * from './validate-amount';

View File

@ -1,4 +1,4 @@
import { t } from '@vegaprotocol/react-helpers';
import { t } from '../i18n';
export const validateAmount = (step: number, field: string) => {
const [, stepDecimals = ''] = String(step).split('.');