You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
132 lines
3.7 KiB
132 lines
3.7 KiB
7 years ago
|
import React, { Component } from 'react'
|
||
|
import PropTypes from 'prop-types'
|
||
6 years ago
|
import SendRowWrapper from '../send-row-wrapper'
|
||
7 years ago
|
import GasFeeDisplay from './gas-fee-display/gas-fee-display.component'
|
||
6 years ago
|
import GasPriceButtonGroup from '../../../../components/app/gas-customization/gas-price-button-group'
|
||
|
import AdvancedGasInputs from '../../../../components/app/gas-customization/advanced-gas-inputs'
|
||
7 years ago
|
|
||
|
export default class SendGasRow extends Component {
|
||
|
|
||
|
static propTypes = {
|
||
7 years ago
|
conversionRate: PropTypes.number,
|
||
7 years ago
|
convertedCurrency: PropTypes.string,
|
||
7 years ago
|
gasFeeError: PropTypes.bool,
|
||
7 years ago
|
gasLoadingError: PropTypes.bool,
|
||
|
gasTotal: PropTypes.string,
|
||
7 years ago
|
showCustomizeGasModal: PropTypes.func,
|
||
6 years ago
|
setGasPrice: PropTypes.func,
|
||
|
setGasLimit: PropTypes.func,
|
||
6 years ago
|
gasPriceButtonGroupProps: PropTypes.object,
|
||
|
gasButtonGroupShown: PropTypes.bool,
|
||
6 years ago
|
advancedInlineGasShown: PropTypes.bool,
|
||
6 years ago
|
resetGasButtons: PropTypes.func,
|
||
6 years ago
|
gasPrice: PropTypes.string,
|
||
|
gasLimit: PropTypes.string,
|
||
6 years ago
|
insufficientBalance: PropTypes.bool,
|
||
6 years ago
|
}
|
||
7 years ago
|
|
||
7 years ago
|
static contextTypes = {
|
||
|
t: PropTypes.func,
|
||
6 years ago
|
metricsEvent: PropTypes.func,
|
||
|
};
|
||
7 years ago
|
|
||
6 years ago
|
renderAdvancedOptionsButton () {
|
||
6 years ago
|
const { metricsEvent } = this.context
|
||
6 years ago
|
const { showCustomizeGasModal } = this.props
|
||
6 years ago
|
return <div className="advanced-gas-options-btn" onClick={() => {
|
||
|
metricsEvent({
|
||
|
eventOpts: {
|
||
|
category: 'Transactions',
|
||
|
action: 'Edit Screen',
|
||
|
name: 'Clicked "Advanced Options"',
|
||
|
},
|
||
|
})
|
||
|
showCustomizeGasModal()
|
||
|
}}>
|
||
6 years ago
|
{ this.context.t('advancedOptions') }
|
||
|
</div>
|
||
|
}
|
||
|
|
||
|
renderContent () {
|
||
7 years ago
|
const {
|
||
|
conversionRate,
|
||
|
convertedCurrency,
|
||
|
gasLoadingError,
|
||
7 years ago
|
gasTotal,
|
||
|
showCustomizeGasModal,
|
||
6 years ago
|
gasPriceButtonGroupProps,
|
||
|
gasButtonGroupShown,
|
||
6 years ago
|
advancedInlineGasShown,
|
||
6 years ago
|
resetGasButtons,
|
||
6 years ago
|
setGasPrice,
|
||
|
setGasLimit,
|
||
|
gasPrice,
|
||
|
gasLimit,
|
||
|
insufficientBalance,
|
||
7 years ago
|
} = this.props
|
||
6 years ago
|
const { metricsEvent } = this.context
|
||
7 years ago
|
|
||
6 years ago
|
const gasPriceButtonGroup = <div>
|
||
|
<GasPriceButtonGroup
|
||
|
className="gas-price-button-group--small"
|
||
|
showCheck={false}
|
||
|
{...gasPriceButtonGroupProps}
|
||
6 years ago
|
handleGasPriceSelection={(...args) => {
|
||
|
metricsEvent({
|
||
|
eventOpts: {
|
||
|
category: 'Transactions',
|
||
|
action: 'Edit Screen',
|
||
|
name: 'Changed Gas Button',
|
||
|
},
|
||
|
})
|
||
|
gasPriceButtonGroupProps.handleGasPriceSelection(...args)
|
||
|
}}
|
||
6 years ago
|
/>
|
||
|
{ this.renderAdvancedOptionsButton() }
|
||
|
</div>
|
||
|
const gasFeeDisplay = <GasFeeDisplay
|
||
|
conversionRate={conversionRate}
|
||
|
convertedCurrency={convertedCurrency}
|
||
|
gasLoadingError={gasLoadingError}
|
||
|
gasTotal={gasTotal}
|
||
|
onReset={resetGasButtons}
|
||
|
onClick={() => showCustomizeGasModal()}
|
||
|
/>
|
||
|
const advancedGasInputs = <div>
|
||
|
<AdvancedGasInputs
|
||
|
updateCustomGasPrice={newGasPrice => setGasPrice(newGasPrice, gasLimit)}
|
||
|
updateCustomGasLimit={newGasLimit => setGasLimit(newGasLimit, gasPrice)}
|
||
|
customGasPrice={gasPrice}
|
||
|
customGasLimit={gasLimit}
|
||
|
insufficientBalance={insufficientBalance}
|
||
|
customPriceIsSafe={true}
|
||
|
isSpeedUp={false}
|
||
|
/>
|
||
|
{ this.renderAdvancedOptionsButton() }
|
||
|
</div>
|
||
|
|
||
|
if (advancedInlineGasShown) {
|
||
|
return advancedGasInputs
|
||
|
} else if (gasButtonGroupShown) {
|
||
|
return gasPriceButtonGroup
|
||
|
} else {
|
||
|
return gasFeeDisplay
|
||
|
}
|
||
|
}
|
||
|
|
||
|
render () {
|
||
|
const { gasFeeError } = this.props
|
||
|
|
||
7 years ago
|
return (
|
||
7 years ago
|
<SendRowWrapper
|
||
6 years ago
|
label={`${this.context.t('transactionFee')}:`}
|
||
7 years ago
|
showError={gasFeeError}
|
||
|
errorType={'gasFee'}
|
||
|
>
|
||
6 years ago
|
{ this.renderContent() }
|
||
7 years ago
|
</SendRowWrapper>
|
||
7 years ago
|
)
|
||
7 years ago
|
}
|
||
|
|
||
|
}
|