import React, { Component } from 'react'; import PropTypes from 'prop-types'; import PageContainer from '../../../ui/page-container'; import { Tabs, Tab } from '../../../ui/tabs'; import AdvancedTabContent from './advanced-tab-content'; import BasicTabContent from './basic-tab-content'; export default class GasModalPageContainer extends Component { static contextTypes = { t: PropTypes.func, metricsEvent: PropTypes.func, trackEvent: PropTypes.func, }; static propTypes = { hideBasic: PropTypes.bool, updateCustomGasPrice: PropTypes.func, updateCustomGasLimit: PropTypes.func, insufficientBalance: PropTypes.bool, fetchBasicGasEstimates: PropTypes.func, gasPriceButtonGroupProps: PropTypes.object, infoRowProps: PropTypes.shape({ originalTotalFiat: PropTypes.string, originalTotalEth: PropTypes.string, newTotalFiat: PropTypes.string, newTotalEth: PropTypes.string, sendAmount: PropTypes.string, transactionFee: PropTypes.string, }), onSubmit: PropTypes.func, customModalGasPriceInHex: PropTypes.string, customModalGasLimitInHex: PropTypes.string, cancelAndClose: PropTypes.func, customPriceIsSafe: PropTypes.bool, isSpeedUp: PropTypes.bool, isRetry: PropTypes.bool, disableSave: PropTypes.bool, customPriceIsExcessive: PropTypes.bool.isRequired, }; componentDidMount() { this.props.fetchBasicGasEstimates(); } renderBasicTabContent(gasPriceButtonGroupProps) { return ( ); } renderAdvancedTabContent() { const { updateCustomGasPrice, updateCustomGasLimit, customModalGasPriceInHex, customModalGasLimitInHex, insufficientBalance, customPriceIsSafe, isSpeedUp, isRetry, customPriceIsExcessive, infoRowProps: { transactionFee }, } = this.props; return ( ); } renderInfoRows(newTotalFiat, newTotalEth, sendAmount, transactionFee) { return (
{this.context.t('sendAmount')} {sendAmount}
{this.context.t('transactionFee')} {transactionFee}
{this.context.t('newTotal')} {newTotalEth}
{newTotalFiat}
); } renderTabs() { const { gasPriceButtonGroupProps, hideBasic, infoRowProps: { newTotalFiat, newTotalEth, sendAmount, transactionFee }, } = this.props; let tabsToRender; if (hideBasic) { tabsToRender = [ { name: this.context.t('advanced'), content: this.renderAdvancedTabContent(), }, ]; } else { tabsToRender = [ { name: this.context.t('basic'), content: this.renderBasicTabContent(gasPriceButtonGroupProps), }, { name: this.context.t('advanced'), content: this.renderAdvancedTabContent(), }, ]; } return ( {tabsToRender.map(({ name, content }, i) => (
{content} {this.renderInfoRows( newTotalFiat, newTotalEth, sendAmount, transactionFee, )}
))}
); } render() { const { cancelAndClose, onSubmit, customModalGasPriceInHex, customModalGasLimitInHex, disableSave, isSpeedUp, } = this.props; return (
cancelAndClose()} onClose={() => cancelAndClose()} onSubmit={() => { if (isSpeedUp) { this.context.metricsEvent({ eventOpts: { category: 'Navigation', action: 'Activity Log', name: 'Saved "Speed Up"', }, }); } onSubmit(customModalGasLimitInHex, customModalGasPriceInHex); }} submitText={this.context.t('save')} headerCloseText={this.context.t('close')} hideCancel />
); } }