WA-232 Adding symbol to inLimit validator
This commit is contained in:
parent
3c550ec446
commit
fb8c48b6b1
|
@ -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})`
|
||||||
}
|
}
|
||||||
|
|
|
@ -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"
|
||||||
/>
|
/>
|
||||||
|
|
Loading…
Reference in New Issue