Add AddressInput component in send custom tx

This commit is contained in:
Germán Martínez 2019-09-02 14:00:30 +02:00
parent 256c78816f
commit cf8a4ed506
2 changed files with 17 additions and 14 deletions

View File

@ -22,7 +22,7 @@ export const required = simpleMemoize((value: Field) => (value ? undefined : 'Re
export const mustBeInteger = (value: string) => (!Number.isInteger(Number(value)) || value.includes('.') ? 'Must be an integer' : undefined) export const mustBeInteger = (value: string) => (!Number.isInteger(Number(value)) || value.includes('.') ? 'Must be an integer' : undefined)
export const mustBeFloat = (value: number) => (Number.isNaN(Number(value)) ? 'Must be a number' : undefined) export const mustBeFloat = (value: number) => (value && Number.isNaN(Number(value)) ? 'Must be a number' : undefined)
export const greaterThan = (min: number) => (value: string) => { export const greaterThan = (min: number) => (value: string) => {
if (Number.isNaN(Number(value)) || Number.parseFloat(value) > Number(min)) { if (Number.isNaN(Number(value)) || Number.parseFloat(value) > Number(min)) {

View File

@ -7,6 +7,7 @@ import IconButton from '@material-ui/core/IconButton'
import Paragraph from '~/components/layout/Paragraph' import Paragraph from '~/components/layout/Paragraph'
import Row from '~/components/layout/Row' import Row from '~/components/layout/Row'
import GnoForm from '~/components/forms/GnoForm' import GnoForm from '~/components/forms/GnoForm'
import AddressInput from '~/components/forms/AddressInput'
import Col from '~/components/layout/Col' import Col from '~/components/layout/Col'
import Button from '~/components/layout/Button' import Button from '~/components/layout/Button'
import Block from '~/components/layout/Block' import Block from '~/components/layout/Block'
@ -17,8 +18,6 @@ import TextField from '~/components/forms/TextField'
import TextareaField from '~/components/forms/TextareaField' import TextareaField from '~/components/forms/TextareaField'
import { import {
composeValidators, composeValidators,
required,
mustBeEthereumAddress,
mustBeFloat, mustBeFloat,
maxValue, maxValue,
greaterThan, greaterThan,
@ -48,13 +47,18 @@ const SendCustomTx = ({
onSubmit, onSubmit,
initialValues, initialValues,
}: Props) => { }: Props) => {
const handleSubmit = (values) => { const handleSubmit = (values: Object) => {
if (values.data || values.value) {
onSubmit(values) onSubmit(values)
} }
}
const formMutators = { const formMutators = {
setMax: (args, state, utils) => { setMax: (args, state, utils) => {
utils.changeValue(state, 'amount', () => ethBalance) utils.changeValue(state, 'value', () => ethBalance)
},
setRecipient: (args, state, utils) => {
utils.changeValue(state, 'recipientAddress', () => args[0])
}, },
} }
@ -88,14 +92,13 @@ const SendCustomTx = ({
<> <>
<Row margin="md"> <Row margin="md">
<Col xs={12}> <Col xs={12}>
<Field <AddressInput
name="recipientAddress" name="recipientAddress"
component={TextField} component={TextField}
type="text"
validate={composeValidators(required, mustBeEthereumAddress)}
placeholder="Recipient*" placeholder="Recipient*"
text="Recipient*" text="Recipient*"
className={classes.addressInput} className={classes.addressInput}
fieldMutator={mutators.setRecipient}
/> />
</Col> </Col>
</Row> </Row>
@ -112,7 +115,7 @@ const SendCustomTx = ({
<Row margin="md"> <Row margin="md">
<Col> <Col>
<Field <Field
name="amount" name="value"
component={TextField} component={TextField}
type="text" type="text"
validate={composeValidators( validate={composeValidators(