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'
|
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'
|
2020-08-18 21:18:25 +02:00
|
|
|
import GasFeeDisplay from './gas-fee-display/gas-fee-display.component'
|
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-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,
|
2020-05-29 19:46:10 +02:00
|
|
|
sendToken: PropTypes.object,
|
2019-05-20 18:38:08 +02:00
|
|
|
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,
|
2020-08-19 16:03:15 +02:00
|
|
|
isMainnet: 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,
|
2020-01-07 21:10:44 +01:00
|
|
|
}
|
2018-07-02 04:09:28 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderAdvancedOptionsButton() {
|
2019-03-05 16:45:01 +01:00
|
|
|
const { metricsEvent } = this.context
|
2020-08-19 16:03:15 +02:00
|
|
|
const { showCustomizeGasModal, isMainnet } = this.props
|
|
|
|
// Tests should behave in same way as mainnet, but are using Localhost
|
|
|
|
if (!isMainnet && !process.env.IN_TEST) {
|
|
|
|
return null
|
|
|
|
}
|
2019-12-03 17:35:44 +01:00
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className="advanced-gas-options-btn"
|
|
|
|
onClick={() => {
|
|
|
|
metricsEvent({
|
|
|
|
eventOpts: {
|
|
|
|
category: 'Transactions',
|
|
|
|
action: 'Edit Screen',
|
|
|
|
name: 'Clicked "Advanced Options"',
|
|
|
|
},
|
|
|
|
})
|
|
|
|
showCustomizeGasModal()
|
|
|
|
}}
|
|
|
|
>
|
2020-11-03 00:41:28 +01:00
|
|
|
{this.context.t('advancedOptions')}
|
2019-12-03 17:35:44 +01:00
|
|
|
</div>
|
|
|
|
)
|
2019-02-06 01:24:28 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
setMaxAmount() {
|
2019-05-20 18:38:08 +02:00
|
|
|
const {
|
|
|
|
balance,
|
|
|
|
gasTotal,
|
2020-05-29 19:46:10 +02:00
|
|
|
sendToken,
|
2019-05-20 18:38:08 +02:00
|
|
|
setAmountToMax,
|
|
|
|
tokenBalance,
|
|
|
|
} = this.props
|
|
|
|
|
|
|
|
setAmountToMax({
|
|
|
|
balance,
|
|
|
|
gasTotal,
|
2020-05-29 19:46:10 +02:00
|
|
|
sendToken,
|
2019-05-20 18:38:08 +02:00
|
|
|
tokenBalance,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderContent() {
|
2018-04-11 16:21:54 +02:00
|
|
|
const {
|
|
|
|
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,
|
2020-08-19 16:03:15 +02:00
|
|
|
isMainnet,
|
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-12-03 17:35:44 +01:00
|
|
|
const gasPriceButtonGroup = (
|
|
|
|
<div>
|
|
|
|
<GasPriceButtonGroup
|
|
|
|
className="gas-price-button-group--small"
|
|
|
|
showCheck={false}
|
|
|
|
{...gasPriceButtonGroupProps}
|
2020-11-12 23:57:29 +01:00
|
|
|
handleGasPriceSelection={async (opts) => {
|
2019-12-03 17:35:44 +01:00
|
|
|
metricsEvent({
|
|
|
|
eventOpts: {
|
|
|
|
category: 'Transactions',
|
|
|
|
action: 'Edit Screen',
|
|
|
|
name: 'Changed Gas Button',
|
|
|
|
},
|
|
|
|
})
|
2020-11-12 23:57:29 +01:00
|
|
|
await gasPriceButtonGroupProps.handleGasPriceSelection(opts)
|
2019-12-03 17:35:44 +01:00
|
|
|
if (maxModeOn) {
|
|
|
|
this.setMaxAmount()
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
const gasFeeDisplay = (
|
|
|
|
<GasFeeDisplay
|
|
|
|
gasLoadingError={gasLoadingError}
|
|
|
|
gasTotal={gasTotal}
|
|
|
|
onReset={() => {
|
|
|
|
resetGasButtons()
|
2019-07-31 22:17:11 +02:00
|
|
|
if (maxModeOn) {
|
|
|
|
this.setMaxAmount()
|
|
|
|
}
|
|
|
|
}}
|
2019-12-03 17:35:44 +01:00
|
|
|
onClick={() => showCustomizeGasModal()}
|
2019-07-31 22:17:11 +02:00
|
|
|
/>
|
2019-12-03 17:35:44 +01:00
|
|
|
)
|
|
|
|
const advancedGasInputs = (
|
|
|
|
<div>
|
|
|
|
<AdvancedGasInputs
|
2020-11-03 00:41:28 +01:00
|
|
|
updateCustomGasPrice={(newGasPrice) =>
|
2020-11-12 23:57:29 +01:00
|
|
|
setGasPrice({ gasPrice: newGasPrice, gasLimit })
|
2020-11-03 00:41:28 +01:00
|
|
|
}
|
|
|
|
updateCustomGasLimit={(newGasLimit) =>
|
|
|
|
setGasLimit(newGasLimit, gasPrice)
|
|
|
|
}
|
2019-12-03 17:35:44 +01:00
|
|
|
customGasPrice={gasPrice}
|
|
|
|
customGasLimit={gasLimit}
|
|
|
|
insufficientBalance={insufficientBalance}
|
|
|
|
customPriceIsSafe
|
|
|
|
isSpeedUp={false}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)
|
2020-08-19 16:03:15 +02:00
|
|
|
// Tests should behave in same way as mainnet, but are using Localhost
|
|
|
|
if (advancedInlineGasShown || (!isMainnet && !process.env.IN_TEST)) {
|
2019-02-06 01:24:28 +01:00
|
|
|
return advancedGasInputs
|
|
|
|
} else if (gasButtonGroupShown) {
|
|
|
|
return gasPriceButtonGroup
|
|
|
|
}
|
2020-08-19 18:27:05 +02:00
|
|
|
return gasFeeDisplay
|
2019-02-06 01:24:28 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
gasFeeError,
|
|
|
|
gasButtonGroupShown,
|
|
|
|
advancedInlineGasShown,
|
|
|
|
} = this.props
|
2019-02-06 01:24:28 +01:00
|
|
|
|
2018-04-11 16:21:54 +02:00
|
|
|
return (
|
2020-10-29 17:31:48 +01:00
|
|
|
<>
|
|
|
|
<SendRowWrapper
|
|
|
|
label={`${this.context.t('transactionFee')}:`}
|
|
|
|
showError={gasFeeError}
|
|
|
|
errorType="gasFee"
|
|
|
|
>
|
2020-11-03 00:41:28 +01:00
|
|
|
{this.renderContent()}
|
2020-10-29 17:31:48 +01:00
|
|
|
</SendRowWrapper>
|
2020-11-03 00:41:28 +01:00
|
|
|
{gasButtonGroupShown || advancedInlineGasShown ? (
|
|
|
|
<SendRowWrapper>{this.renderAdvancedOptionsButton()}</SendRowWrapper>
|
|
|
|
) : null}
|
2020-10-29 17:31:48 +01:00
|
|
|
</>
|
2018-04-27 02:38:14 +02:00
|
|
|
)
|
2018-04-11 16:21:54 +02:00
|
|
|
}
|
|
|
|
}
|