import { BigNumber } from '@0xproject/utils'; import * as _ from 'lodash'; import Dialog from 'material-ui/Dialog'; import FlatButton from 'material-ui/FlatButton'; import * as React from 'react'; import { Blockchain } from 'ts/blockchain'; import { AddressInput } from 'ts/components/inputs/address_input'; import { TokenAmountInput } from 'ts/components/inputs/token_amount_input'; import { EthAmountInput } from 'ts/containers/inputs/eth_amount_input'; import { Token } from 'ts/types'; interface SendDialogProps { blockchain: Blockchain; userAddress: string; networkId: number; onComplete: (recipient: string, value: BigNumber) => void; onCancelled: () => void; isOpen: boolean; asset: Token | 'ETH'; lastForceTokenStateRefetch: number; } interface SendDialogState { value?: BigNumber; recipient: string; shouldShowIncompleteErrs: boolean; isAmountValid: boolean; } export class SendDialog extends React.Component { constructor(props: SendDialogProps) { super(props); this.state = { recipient: '', shouldShowIncompleteErrs: false, isAmountValid: false, }; } public render(): React.ReactNode { const transferDialogActions = [ , , ]; return ( {this._renderSendDialogBody()} ); } private _renderSendDialogBody(): React.ReactNode { const input = this.props.asset === 'ETH' ? ( ) : ( ); return (
{input}
); } private _onRecipientChange(recipient?: string): void { this.setState({ shouldShowIncompleteErrs: false, recipient, }); } private _onValueChange(isValid: boolean, amount?: BigNumber): void { this.setState({ isAmountValid: isValid, value: amount, }); } private _onSendClick(): void { if (this._hasErrors()) { this.setState({ shouldShowIncompleteErrs: true, }); } else { const value = this.state.value; this.setState({ recipient: undefined, value: undefined, }); this.props.onComplete(this.state.recipient, value); } } private _onCancel(): void { this.setState({ value: undefined, }); this.props.onCancelled(); } private _hasErrors(): boolean { return _.isUndefined(this.state.recipient) || _.isUndefined(this.state.value) || !this.state.isAmountValid; } }