import React, { Component } from 'react'
import PropTypes from 'prop-types'
import PageContainer from '../../page-container'
import { Tabs, Tab } from '../../tabs'
import AdvancedTabContent from './advanced-tab-content'
import BasicTabContent from './basic-tab-content'
export default class GasModalPageContainer extends Component {
static contextTypes = {
t: PropTypes.func,
}
static propTypes = {
hideModal: PropTypes.func,
updateCustomGasPrice: PropTypes.func,
updateCustomGasLimit: PropTypes.func,
customGasPrice: PropTypes.number,
customGasLimit: PropTypes.number,
gasPriceButtonGroupProps: PropTypes.object,
infoRowProps: PropTypes.shape({
originalTotalFiat: PropTypes.string,
originalTotalEth: PropTypes.string,
newTotalFiat: PropTypes.string,
newTotalEth: PropTypes.string,
}),
onSubmit: PropTypes.func,
customGasPriceInHex: PropTypes.string,
customGasLimitInHex: PropTypes.string,
}
state = {}
renderBasicTabContent (gasPriceButtonGroupProps) {
return (
)
}
renderAdvancedTabContent ({
convertThenUpdateCustomGasPrice,
convertThenUpdateCustomGasLimit,
customGasPrice,
customGasLimit,
newTotalFiat,
}) {
return (
)
}
renderInfoRow (className, totalLabelKey, fiatTotal, cryptoTotal) {
return (
{`${this.context.t(totalLabelKey)}:`}
{fiatTotal}
{`${this.context.t('amountPlusTxFee')}`}
{cryptoTotal}
)
}
renderInfoRows (originalTotalFiat, originalTotalEth, newTotalFiat, newTotalEth) {
return (
{ this.renderInfoRow('gas-modal-content__info-row--fade', 'originalTotal', originalTotalFiat, originalTotalEth) }
{ this.renderInfoRow('gas-modal-content__info-row', 'newTotal', newTotalFiat, newTotalEth) }
)
}
renderTabs ({
originalTotalFiat,
originalTotalEth,
newTotalFiat,
newTotalEth,
},
{
gasPriceButtonGroupProps,
hideBasic,
...advancedTabProps
}) {
let tabsToRender = [
{ name: 'basic', content: this.renderBasicTabContent(gasPriceButtonGroupProps) },
{ name: 'advanced', content: this.renderAdvancedTabContent(advancedTabProps) },
]
if (hideBasic) {
tabsToRender = tabsToRender.slice(1)
}
return (
{tabsToRender.map(({ name, content }, i) =>
{ content }
{ this.renderInfoRows(originalTotalFiat, originalTotalEth, newTotalFiat, newTotalEth) }
)}
)
}
render () {
const {
hideModal,
infoRowProps,
onSubmit,
customGasPriceInHex,
customGasLimitInHex,
...tabProps
} = this.props
return (
hideModal()}
onClose={() => hideModal()}
onSubmit={() => {
onSubmit(customGasLimitInHex, customGasPriceInHex)
hideModal()
}}
submitText={this.context.t('save')}
/>
)
}
}