import React, { Component } from 'react' import PropTypes from 'prop-types' import classnames from 'classnames' import Loading from '../../../loading-screen' import GasPriceChart from '../../gas-price-chart' import debounce from 'lodash.debounce' export default class AdvancedTabContent extends Component { static contextTypes = { t: PropTypes.func, } static propTypes = { updateCustomGasPrice: PropTypes.func, updateCustomGasLimit: PropTypes.func, customGasPrice: PropTypes.number, customGasLimit: PropTypes.number, gasEstimatesLoading: PropTypes.bool, millisecondsRemaining: PropTypes.number, totalFee: PropTypes.string, timeRemaining: PropTypes.string, gasChartProps: PropTypes.object, insufficientBalance: PropTypes.bool, customPriceIsSafe: PropTypes.bool, isSpeedUp: PropTypes.bool, } constructor (props) { super(props) this.debouncedGasLimitReset = debounce((dVal) => { if (dVal < 21000) { props.updateCustomGasLimit(21000) } }, 1000, { trailing: true }) this.onChangeGasLimit = (val) => { props.updateCustomGasLimit(val) this.debouncedGasLimitReset(val) } } gasInputError ({ labelKey, insufficientBalance, customPriceIsSafe, isSpeedUp, value }) { let errorText let errorType let isInError = true if (insufficientBalance) { errorText = 'Insufficient Balance' errorType = 'error' } else if (labelKey === 'gasPrice' && isSpeedUp && value === 0) { errorText = 'Zero gas price on speed up' errorType = 'error' } else if (labelKey === 'gasPrice' && !customPriceIsSafe) { errorText = 'Gas Price Extremely Low' errorType = 'warning' } else { isInError = false } return { isInError, errorText, errorType, } } gasInput ({ labelKey, value, onChange, insufficientBalance, showGWEI, customPriceIsSafe, isSpeedUp }) { const { isInError, errorText, errorType, } = this.gasInputError({ labelKey, insufficientBalance, customPriceIsSafe, isSpeedUp, value }) return (
onChange(Number(event.target.value))} />
onChange(value + 1)}>
onChange(value - 1)}>
{ isInError ?
{ errorText }
: null }
) } infoButton (onClick) { return } renderDataSummary (totalFee, timeRemaining) { return (
{ this.context.t('newTransactionFee') } ~{ this.context.t('transactionTime') }
{totalFee}
{timeRemaining}
) } renderGasEditRow (gasInputArgs) { return (
{ this.context.t(gasInputArgs.labelKey) } { this.infoButton(() => {}) }
{ this.gasInput(gasInputArgs) }
) } renderGasEditRows ({ customGasPrice, updateCustomGasPrice, customGasLimit, updateCustomGasLimit, insufficientBalance, customPriceIsSafe, isSpeedUp, }) { return (
{ this.renderGasEditRow({ labelKey: 'gasPrice', value: customGasPrice, onChange: updateCustomGasPrice, insufficientBalance, customPriceIsSafe, showGWEI: true, isSpeedUp, }) } { this.renderGasEditRow({ labelKey: 'gasLimit', value: customGasLimit, onChange: this.onChangeGasLimit, insufficientBalance, customPriceIsSafe, }) }
) } render () { const { updateCustomGasPrice, updateCustomGasLimit, timeRemaining, customGasPrice, customGasLimit, insufficientBalance, totalFee, gasChartProps, gasEstimatesLoading, customPriceIsSafe, isSpeedUp, } = this.props return (
{ this.renderDataSummary(totalFee, timeRemaining) }
{ this.renderGasEditRows({ customGasPrice, updateCustomGasPrice, customGasLimit, updateCustomGasLimit, insufficientBalance, customPriceIsSafe, isSpeedUp, }) }
Live Gas Price Predictions
{!gasEstimatesLoading ? : }
Slower Faster
) } }