Add AddressInput component in send custom tx
This commit is contained in:
parent
256c78816f
commit
cf8a4ed506
|
@ -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)) {
|
||||||
|
|
|
@ -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) => {
|
||||||
onSubmit(values)
|
if (values.data || values.value) {
|
||||||
|
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,31 +92,30 @@ 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>
|
||||||
<Row margin="xs">
|
<Row margin="xs">
|
||||||
<Col between="lg">
|
<Col between="lg">
|
||||||
<Paragraph size="md" color="disabled" style={{ letterSpacing: '-0.5px' }} noMargin>
|
<Paragraph size="md" color="disabled" style={{ letterSpacing: '-0.5px' }} noMargin>
|
||||||
Amount
|
Amount
|
||||||
</Paragraph>
|
</Paragraph>
|
||||||
<ButtonLink weight="bold" onClick={mutators.setMax}>
|
<ButtonLink weight="bold" onClick={mutators.setMax}>
|
||||||
Send max
|
Send max
|
||||||
</ButtonLink>
|
</ButtonLink>
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
<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(
|
||||||
|
@ -142,7 +145,7 @@ const SendCustomTx = ({
|
||||||
<Hairline />
|
<Hairline />
|
||||||
<Row align="center" className={classes.buttonRow}>
|
<Row align="center" className={classes.buttonRow}>
|
||||||
<Button minWidth={140} minHeight={42} onClick={onClose}>
|
<Button minWidth={140} minHeight={42} onClick={onClose}>
|
||||||
Cancel
|
Cancel
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
type="submit"
|
type="submit"
|
||||||
|
@ -152,7 +155,7 @@ const SendCustomTx = ({
|
||||||
color="primary"
|
color="primary"
|
||||||
data-testid="review-tx-btn"
|
data-testid="review-tx-btn"
|
||||||
>
|
>
|
||||||
Review
|
Review
|
||||||
</Button>
|
</Button>
|
||||||
</Row>
|
</Row>
|
||||||
</>
|
</>
|
||||||
|
|
Loading…
Reference in New Issue