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) => export const composeValidators = (...validators: Function[]): FieldValidator => (value: Field) =>
validators.reduce((error, validator) => error || validator(value), undefined) 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 amount = Number(value)
const max = limit - base const max = limit - base
if (amount <= max) { if (amount <= max) {
return undefined 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} name={TKN_VALUE_PARAM}
component={TextField} component={TextField}
type="text" 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*" placeholder="Amount of tokens*"
text="Amount of Tokens" text="Amount of Tokens"
/> />