// @flow import React from 'react'; import { isValidETHAddress, isPositiveIntegerOrZero } from 'libs/validators'; import translate from 'translations'; export default class AddCustomTokenForm extends React.Component { props: { onSave: ({ address: string, symbol: string, decimal: number }) => void }; state = { address: '', symbol: '', decimal: '' }; render() { return (
{translate('x_Save')}
); } isValid() { const { address, symbol, decimal } = this.state; if (!isPositiveIntegerOrZero(parseInt(decimal))) { return false; } if (!isValidETHAddress(address)) { return false; } if (this.state.symbol === '') { return false; } return true; } onFieldChange = (e: SyntheticInputEvent) => { var name = e.target.name; var value = e.target.value; this.setState(state => { var newState = Object.assign({}, state); newState[name] = value; return newState; }); }; onSave = () => { if (!this.isValid()) { return; } const { address, symbol, decimal } = this.state; this.props.onSave({ address, symbol, decimal: parseInt(decimal) }); }; }