import { BigNumber } from '@0x/utils'; import * as _ from 'lodash'; import * as React from 'react'; import { SelectedERC20AssetAmountInput } from '../containers/selected_erc20_asset_amount_input'; import { ColorOption } from '../style/theme'; import { AsyncProcessState, ERC20Asset, OrderProcessState, OrderState } from '../types'; import { format } from '../util/format'; import { AmountPlaceholder } from './amount_placeholder'; import { Container } from './ui/container'; import { Flex } from './ui/flex'; import { Icon } from './ui/icon'; import { Spinner } from './ui/spinner'; import { Text } from './ui/text'; export interface InstantHeadingProps { selectedAssetUnitAmount?: BigNumber; totalEthBaseUnitAmount?: BigNumber; ethUsdPrice?: BigNumber; quoteRequestState: AsyncProcessState; buyOrderState: OrderState; onSelectAssetClick?: (asset?: ERC20Asset) => void; } 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 { if ( _.isUndefined(this.props.totalEthBaseUnitAmount) && this.props.quoteRequestState !== AsyncProcessState.Pending ) { return null; } else { return ( {this._renderPlaceholderOrAmount(this._renderEthAmount)} {this._renderPlaceholderOrAmount(this._renderDollarAmount)} ); } } private _renderIcon(): React.ReactNode { const processState = this.props.buyOrderState.processState; if (processState === OrderProcessState.Failure) { return ; } else if (processState === OrderProcessState.Processing) { return ; } else if (processState === OrderProcessState.Success) { return ; } return undefined; } private _renderTopText(): React.ReactNode { const processState = this.props.buyOrderState.processState; if (processState === OrderProcessState.Failure) { return 'Order failed'; } else if (processState === OrderProcessState.Processing) { return 'Processing Order...'; } else if (processState === OrderProcessState.Success) { return 'Tokens received!'; } return 'I want to buy'; } private _renderPlaceholderOrAmount(amountFunction: () => React.ReactNode): React.ReactNode { if (this.props.quoteRequestState === AsyncProcessState.Pending) { return ; } if (_.isUndefined(this.props.selectedAssetUnitAmount)) { return ; } return amountFunction(); } private readonly _renderEthAmount = (): React.ReactNode => { const ethAmount = format.ethBaseUnitAmount( this.props.totalEthBaseUnitAmount, 4, , ); const fontSize = _.isString(ethAmount) && ethAmount.length >= 13 ? '14px' : '16px'; return ( {ethAmount} ); }; private readonly _renderDollarAmount = (): React.ReactNode => { return ( {format.ethBaseUnitAmountInUsd( this.props.totalEthBaseUnitAmount, this.props.ethUsdPrice, 2, , )} ); }; }