WA-232 Adding symbol to inLimit validator

This commit is contained in:
apanizo 2018-07-05 11:25:40 +02:00
parent 3c550ec446
commit fb8c48b6b1
2 changed files with 3 additions and 3 deletions

View File

@ -52,12 +52,12 @@ export const uniqueAddress = (addresses: string[]) => (value: string) =>
export const composeValidators = (...validators: Function[]): FieldValidator => (value: Field) =>
validators.reduce((error, validator) => error || validator(value), undefined)
export const inLimit = (limit: number, base: number, baseText: string) => (value: string) => {
export const inLimit = (limit: number, base: number, baseText: string, symbol: string = 'ETH') => (value: string) => {
const amount = Number(value)
const max = limit - base
if (amount <= max) {
return undefined
}
return `Should not exceed ${max} ETH (amount to reach ${baseText})`
return `Should not exceed ${max} ${symbol} (amount to reach ${baseText})`
}

View File

@ -39,7 +39,7 @@ const SendTokenForm = ({ funds, symbol }: Props) => () => (
name={TKN_VALUE_PARAM}
component={TextField}
type="text"
validate={composeValidators(required, mustBeFloat, greaterThan(0), inLimit(Number(funds), 0, 'available balance'))}
validate={composeValidators(required, mustBeFloat, greaterThan(0), inLimit(Number(funds), 0, 'available balance', symbol))}
placeholder="Amount of tokens*"
text="Amount of Tokens"
/>