import { BigNumber } from '@0x/utils'; import * as _ from 'lodash'; import * as React from 'react'; import { SelectedAssetAmountInput } from '../containers/selected_asset_amount_input'; import { ColorOption } from '../style/theme'; import { AsyncProcessState, OrderState } from '../types'; import { format } from '../util/format'; import { AmountPlaceholder } from './amount_placeholder'; import { Container, Flex, Text } from './ui'; import { Icon } from './ui/icon'; export interface InstantHeadingProps { selectedAssetAmount?: BigNumber; totalEthBaseAmount?: BigNumber; ethUsdPrice?: BigNumber; quoteRequestState: AsyncProcessState; buyOrderState: OrderState; } const PLACEHOLDER_COLOR = ColorOption.white; const ICON_WIDTH = 34; const ICON_HEIGHT = 34; const ICON_COLOR = ColorOption.white; export class InstantHeading extends React.Component { public render(): React.ReactNode { const iconOrAmounts = this._renderIcon() || this._renderAmountsSection(); return ( {this._renderTopText()} {iconOrAmounts} ); } private _renderAmountsSection(): React.ReactNode { return ( {this._placeholderOrAmount(this._ethAmount)} {this._placeholderOrAmount(this._dollarAmount)} ); } private _renderIcon(): React.ReactNode { const processState = this.props.buyOrderState.processState; if (processState === AsyncProcessState.FAILURE) { return ; } else if (processState === AsyncProcessState.SUCCESS) { return ; } return undefined; } private _renderTopText(): React.ReactNode { const processState = this.props.buyOrderState.processState; if (processState === AsyncProcessState.FAILURE) { return 'Order failed'; } else if (processState === AsyncProcessState.SUCCESS) { return 'Tokens received!'; } return 'I want to buy'; } private _placeholderOrAmount(amountFunction: () => React.ReactNode): React.ReactNode { if (this.props.quoteRequestState === AsyncProcessState.PENDING) { return ; } if (_.isUndefined(this.props.selectedAssetAmount)) { return ; } return amountFunction(); } private readonly _ethAmount = (): React.ReactNode => { return ( {format.ethBaseAmount( this.props.totalEthBaseAmount, 4, , )} ); }; private readonly _dollarAmount = (): React.ReactNode => { return ( {format.ethBaseAmountInUsd( this.props.totalEthBaseAmount, this.props.ethUsdPrice, 2, , )} ); }; }