2018-10-22 00:51:29 -07:00
|
|
|
import React from 'react';
|
|
|
|
import classnames from 'classnames';
|
|
|
|
import { Form, Input } from 'antd';
|
|
|
|
import { InputProps } from 'antd/lib/input';
|
|
|
|
import { FormItemProps } from 'antd/lib/form';
|
2018-12-14 11:36:22 -08:00
|
|
|
import { isValidAddress } from 'utils/validators';
|
2018-10-22 00:51:29 -07:00
|
|
|
import Identicon from 'components/Identicon';
|
|
|
|
import { DONATION } from 'utils/constants';
|
|
|
|
import './AddressInput.less';
|
|
|
|
|
|
|
|
export interface Props {
|
|
|
|
value: string | undefined;
|
|
|
|
className?: string;
|
|
|
|
showIdenticon?: boolean;
|
|
|
|
inputProps?: InputProps;
|
|
|
|
formItemProps?: FormItemProps;
|
|
|
|
onChange(ev: React.ChangeEvent<HTMLInputElement>): void;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default class AddressInput extends React.Component<Props> {
|
|
|
|
render() {
|
|
|
|
const { value, onChange, className, showIdenticon } = this.props;
|
|
|
|
const passedFormItemProps = this.props.formItemProps || {};
|
|
|
|
const passedInputProps = this.props.inputProps || {};
|
2018-12-14 11:36:22 -08:00
|
|
|
const isInvalid = value && !isValidAddress(value);
|
2018-10-22 00:51:29 -07:00
|
|
|
|
|
|
|
const formItemProps = {
|
|
|
|
validateStatus: (isInvalid
|
|
|
|
? 'error'
|
|
|
|
: undefined) as FormItemProps['validateStatus'],
|
|
|
|
help: isInvalid ? 'Address is invalid' : undefined,
|
|
|
|
...passedFormItemProps,
|
|
|
|
className: classnames('AddressInput', className, passedFormItemProps.className),
|
|
|
|
};
|
|
|
|
|
|
|
|
const inputProps = {
|
2018-12-27 09:41:26 -08:00
|
|
|
placeholder: DONATION.ZCASH_SPROUT,
|
2018-10-22 00:51:29 -07:00
|
|
|
prefix: value &&
|
|
|
|
showIdenticon && (
|
|
|
|
<Identicon className="AddressInput-input-identicon" address={value} />
|
|
|
|
),
|
|
|
|
...passedInputProps,
|
|
|
|
value,
|
|
|
|
onChange,
|
|
|
|
className: classnames(
|
|
|
|
'AddressInput-input',
|
|
|
|
className && `${className}-input`,
|
|
|
|
passedInputProps.className,
|
|
|
|
),
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Form.Item {...formItemProps}>
|
|
|
|
<Input {...inputProps} />
|
|
|
|
</Form.Item>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|