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, Flex, Icon, Spinner, Text } from './ui'; export interface InstantHeadingProps { selectedAssetAmount?: BigNumber; totalEthBaseAmount?: 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 = '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._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.selectedAssetAmount)) { return ; } return amountFunction(); } private readonly _renderEthAmount = (): React.ReactNode => { return ( {format.ethBaseAmount( this.props.totalEthBaseAmount, 4, , )} ); }; private readonly _renderDollarAmount = (): React.ReactNode => { return ( {format.ethBaseAmountInUsd( this.props.totalEthBaseAmount, this.props.ethUsdPrice, 2, , )} ); }; }