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 } 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: AsyncProcessState; } const placeholderColor = 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 { if (this.props.buyOrderState === AsyncProcessState.FAILURE) { return ; } return undefined; } private _renderTopText(): React.ReactNode { if (this.props.buyOrderState === AsyncProcessState.FAILURE) { return 'Order failed'; } 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, , )} ); }; }