2018-04-11 16:21:54 +02:00
|
|
|
import React, { Component } from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
2019-03-22 00:03:30 +01:00
|
|
|
import SendRowWrapper from '../send-row-wrapper'
|
2018-06-21 08:43:48 +02:00
|
|
|
import GasFeeDisplay from './gas-fee-display/gas-fee-display.component'
|
2019-04-17 21:15:13 +02:00
|
|
|
import GasPriceButtonGroup from '../../../../components/app/gas-customization/gas-price-button-group'
|
|
|
|
import AdvancedGasInputs from '../../../../components/app/gas-customization/advanced-gas-inputs'
|
2018-04-11 16:21:54 +02:00
|
|
|
|
|
|
|
export default class SendGasRow extends Component {
|
|
|
|
|
|
|
|
static propTypes = {
|
2019-05-20 18:38:08 +02:00
|
|
|
balance: PropTypes.string,
|
2018-04-26 18:38:38 +02:00
|
|
|
conversionRate: PropTypes.number,
|
2018-04-27 02:38:14 +02:00
|
|
|
convertedCurrency: PropTypes.string,
|
2018-06-29 19:19:40 +02:00
|
|
|
gasFeeError: PropTypes.bool,
|
2018-04-27 02:38:14 +02:00
|
|
|
gasLoadingError: PropTypes.bool,
|
|
|
|
gasTotal: PropTypes.string,
|
2019-05-20 18:38:08 +02:00
|
|
|
maxModeOn: PropTypes.bool,
|
2018-04-27 12:41:18 +02:00
|
|
|
showCustomizeGasModal: PropTypes.func,
|
2019-05-20 18:38:08 +02:00
|
|
|
selectedToken: PropTypes.object,
|
|
|
|
setAmountToMax: PropTypes.func,
|
2019-02-06 01:24:28 +01:00
|
|
|
setGasPrice: PropTypes.func,
|
|
|
|
setGasLimit: PropTypes.func,
|
2019-05-20 18:38:08 +02:00
|
|
|
tokenBalance: PropTypes.string,
|
2018-09-20 06:16:43 +02:00
|
|
|
gasPriceButtonGroupProps: PropTypes.object,
|
|
|
|
gasButtonGroupShown: PropTypes.bool,
|
2019-02-06 01:24:28 +01:00
|
|
|
advancedInlineGasShown: PropTypes.bool,
|
2018-11-05 18:01:46 +01:00
|
|
|
resetGasButtons: PropTypes.func,
|
2019-04-17 21:15:13 +02:00
|
|
|
gasPrice: PropTypes.string,
|
|
|
|
gasLimit: PropTypes.string,
|
2019-02-06 01:24:28 +01:00
|
|
|
insufficientBalance: PropTypes.bool,
|
2018-11-20 01:06:34 +01:00
|
|
|
}
|
2018-04-11 16:21:54 +02:00
|
|
|
|
2018-07-02 04:09:28 +02:00
|
|
|
static contextTypes = {
|
|
|
|
t: PropTypes.func,
|
2019-03-05 16:45:01 +01:00
|
|
|
metricsEvent: PropTypes.func,
|
|
|
|
};
|
2018-07-02 04:09:28 +02:00
|
|
|
|
2019-02-06 01:24:28 +01:00
|
|
|
renderAdvancedOptionsButton () {
|
2019-03-05 16:45:01 +01:00
|
|
|
const { metricsEvent } = this.context
|
2019-02-06 01:24:28 +01:00
|
|
|
const { showCustomizeGasModal } = this.props
|
2019-03-05 16:45:01 +01:00
|
|
|
return <div className="advanced-gas-options-btn" onClick={() => {
|
|
|
|
metricsEvent({
|
|
|
|
eventOpts: {
|
|
|
|
category: 'Transactions',
|
|
|
|
action: 'Edit Screen',
|
|
|
|
name: 'Clicked "Advanced Options"',
|
|
|
|
},
|
|
|
|
})
|
|
|
|
showCustomizeGasModal()
|
|
|
|
}}>
|
2019-02-06 01:24:28 +01:00
|
|
|
{ this.context.t('advancedOptions') }
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
|
2019-05-20 18:38:08 +02:00
|
|
|
setMaxAmount () {
|
|
|
|
const {
|
|
|
|
balance,
|
|
|
|
gasTotal,
|
|
|
|
selectedToken,
|
|
|
|
setAmountToMax,
|
|
|
|
tokenBalance,
|
|
|
|
} = this.props
|
|
|
|
|
|
|
|
setAmountToMax({
|
|
|
|
balance,
|
|
|
|
gasTotal,
|
|
|
|
selectedToken,
|
|
|
|
tokenBalance,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-02-06 01:24:28 +01:00
|
|
|
renderContent () {
|
2018-04-11 16:21:54 +02:00
|
|
|
const {
|
|
|
|
conversionRate,
|
|
|
|
convertedCurrency,
|
|
|
|
gasLoadingError,
|
2018-04-27 02:38:14 +02:00
|
|
|
gasTotal,
|
|
|
|
showCustomizeGasModal,
|
2018-09-13 14:35:17 +02:00
|
|
|
gasPriceButtonGroupProps,
|
|
|
|
gasButtonGroupShown,
|
2019-02-06 01:24:28 +01:00
|
|
|
advancedInlineGasShown,
|
2019-05-20 18:38:08 +02:00
|
|
|
maxModeOn,
|
2018-11-05 18:01:46 +01:00
|
|
|
resetGasButtons,
|
2019-02-06 01:24:28 +01:00
|
|
|
setGasPrice,
|
|
|
|
setGasLimit,
|
|
|
|
gasPrice,
|
|
|
|
gasLimit,
|
|
|
|
insufficientBalance,
|
2018-04-11 16:21:54 +02:00
|
|
|
} = this.props
|
2019-03-05 16:45:01 +01:00
|
|
|
const { metricsEvent } = this.context
|
2018-04-11 16:21:54 +02:00
|
|
|
|
2019-02-06 01:24:28 +01:00
|
|
|
const gasPriceButtonGroup = <div>
|
2019-07-31 22:17:11 +02:00
|
|
|
<GasPriceButtonGroup
|
|
|
|
className="gas-price-button-group--small"
|
|
|
|
showCheck={false}
|
|
|
|
{...gasPriceButtonGroupProps}
|
|
|
|
handleGasPriceSelection={async (...args) => {
|
|
|
|
metricsEvent({
|
|
|
|
eventOpts: {
|
|
|
|
category: 'Transactions',
|
|
|
|
action: 'Edit Screen',
|
|
|
|
name: 'Changed Gas Button',
|
|
|
|
},
|
|
|
|
})
|
|
|
|
await gasPriceButtonGroupProps.handleGasPriceSelection(...args)
|
|
|
|
if (maxModeOn) {
|
|
|
|
this.setMaxAmount()
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
{ this.renderAdvancedOptionsButton() }
|
|
|
|
</div>
|
2019-02-06 01:24:28 +01:00
|
|
|
const gasFeeDisplay = <GasFeeDisplay
|
|
|
|
conversionRate={conversionRate}
|
|
|
|
convertedCurrency={convertedCurrency}
|
|
|
|
gasLoadingError={gasLoadingError}
|
|
|
|
gasTotal={gasTotal}
|
2019-05-20 18:38:08 +02:00
|
|
|
onReset={() => {
|
|
|
|
resetGasButtons()
|
|
|
|
if (maxModeOn) {
|
|
|
|
this.setMaxAmount()
|
|
|
|
}
|
|
|
|
}}
|
2019-02-06 01:24:28 +01:00
|
|
|
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() }
|
2019-07-31 22:17:11 +02:00
|
|
|
</div>
|
2019-02-06 01:24:28 +01:00
|
|
|
|
|
|
|
if (advancedInlineGasShown) {
|
|
|
|
return advancedGasInputs
|
|
|
|
} else if (gasButtonGroupShown) {
|
|
|
|
return gasPriceButtonGroup
|
|
|
|
} else {
|
|
|
|
return gasFeeDisplay
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
const { gasFeeError } = this.props
|
|
|
|
|
2018-04-11 16:21:54 +02:00
|
|
|
return (
|
2018-06-29 19:19:40 +02:00
|
|
|
<SendRowWrapper
|
2018-09-13 14:35:17 +02:00
|
|
|
label={`${this.context.t('transactionFee')}:`}
|
2018-06-29 19:19:40 +02:00
|
|
|
showError={gasFeeError}
|
|
|
|
errorType={'gasFee'}
|
|
|
|
>
|
2019-02-06 01:24:28 +01:00
|
|
|
{ this.renderContent() }
|
2018-04-11 16:21:54 +02:00
|
|
|
</SendRowWrapper>
|
2018-04-27 02:38:14 +02:00
|
|
|
)
|
2018-04-11 16:21:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|