2021-02-04 19:15:23 +01:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import SendRowWrapper from '../send-row-wrapper';
|
|
|
|
import GasPriceButtonGroup from '../../../../components/app/gas-customization/gas-price-button-group';
|
|
|
|
import AdvancedGasInputs from '../../../../components/app/gas-customization/advanced-gas-inputs';
|
2021-06-23 23:35:25 +02:00
|
|
|
import { GAS_INPUT_MODES } from '../../../../ducks/send';
|
2021-02-04 19:15:23 +01: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 = {
|
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,
|
2021-07-31 03:29:21 +02:00
|
|
|
showLegacyCustomizeGasModal: PropTypes.func,
|
2021-06-23 23:35:25 +02:00
|
|
|
updateGasPrice: PropTypes.func,
|
|
|
|
updateGasLimit: PropTypes.func,
|
|
|
|
gasInputMode: PropTypes.oneOf(Object.values(GAS_INPUT_MODES)),
|
2018-09-20 06:16:43 +02:00
|
|
|
gasPriceButtonGroupProps: PropTypes.object,
|
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,
|
2021-06-23 23:35:25 +02:00
|
|
|
minimumGasLimit: PropTypes.string,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-04-11 16:21:54 +02:00
|
|
|
|
2018-07-02 04:09:28 +02:00
|
|
|
static contextTypes = {
|
|
|
|
t: PropTypes.func,
|
2021-06-21 21:02:51 +02:00
|
|
|
trackEvent: PropTypes.func,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-07-02 04:09:28 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderAdvancedOptionsButton() {
|
2021-06-21 21:02:51 +02:00
|
|
|
const { trackEvent } = this.context;
|
2021-07-31 03:29:21 +02:00
|
|
|
const { showLegacyCustomizeGasModal } = this.props;
|
2019-12-03 17:35:44 +01:00
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className="advanced-gas-options-btn"
|
|
|
|
onClick={() => {
|
2021-06-21 21:02:51 +02:00
|
|
|
trackEvent({
|
|
|
|
category: 'Transactions',
|
|
|
|
event: 'Clicked "Advanced Options"',
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2021-07-31 03:29:21 +02:00
|
|
|
showLegacyCustomizeGasModal();
|
2019-12-03 17:35:44 +01:00
|
|
|
}}
|
|
|
|
>
|
2020-11-03 00:41:28 +01:00
|
|
|
{this.context.t('advancedOptions')}
|
2019-12-03 17:35:44 +01:00
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-02-06 01:24:28 +01:00
|
|
|
}
|
|
|
|
|
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,
|
2018-09-13 14:35:17 +02:00
|
|
|
gasPriceButtonGroupProps,
|
2021-06-23 23:35:25 +02:00
|
|
|
gasInputMode,
|
2018-11-05 18:01:46 +01:00
|
|
|
resetGasButtons,
|
2021-06-23 23:35:25 +02:00
|
|
|
updateGasPrice,
|
|
|
|
updateGasLimit,
|
2019-02-06 01:24:28 +01:00
|
|
|
gasPrice,
|
|
|
|
gasLimit,
|
|
|
|
insufficientBalance,
|
2021-06-23 23:35:25 +02:00
|
|
|
minimumGasLimit,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = this.props;
|
2021-06-21 21:02:51 +02:00
|
|
|
const { trackEvent } = 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) => {
|
2021-06-21 21:02:51 +02:00
|
|
|
trackEvent({
|
|
|
|
category: 'Transactions',
|
|
|
|
event: 'User Clicked Gas Estimate Button',
|
|
|
|
properties: {
|
|
|
|
gasEstimateType: opts.gasEstimateType.toLowerCase(),
|
2019-12-03 17:35:44 +01:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
await gasPriceButtonGroupProps.handleGasPriceSelection(opts);
|
2019-12-03 17:35:44 +01:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-12-03 17:35:44 +01:00
|
|
|
const gasFeeDisplay = (
|
|
|
|
<GasFeeDisplay
|
|
|
|
gasLoadingError={gasLoadingError}
|
|
|
|
gasTotal={gasTotal}
|
2021-06-23 23:35:25 +02:00
|
|
|
onReset={resetGasButtons}
|
2019-07-31 22:17:11 +02:00
|
|
|
/>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-12-03 17:35:44 +01:00
|
|
|
const advancedGasInputs = (
|
|
|
|
<div>
|
|
|
|
<AdvancedGasInputs
|
2021-06-23 23:35:25 +02:00
|
|
|
updateCustomGasPrice={updateGasPrice}
|
|
|
|
updateCustomGasLimit={updateGasLimit}
|
2019-12-03 17:35:44 +01:00
|
|
|
customGasPrice={gasPrice}
|
|
|
|
customGasLimit={gasLimit}
|
|
|
|
insufficientBalance={insufficientBalance}
|
2021-06-23 23:35:25 +02:00
|
|
|
minimumGasLimit={minimumGasLimit}
|
2019-12-03 17:35:44 +01:00
|
|
|
customPriceIsSafe
|
|
|
|
isSpeedUp={false}
|
|
|
|
/>
|
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-08-19 16:03:15 +02:00
|
|
|
// Tests should behave in same way as mainnet, but are using Localhost
|
2021-06-23 23:35:25 +02:00
|
|
|
switch (gasInputMode) {
|
|
|
|
case GAS_INPUT_MODES.BASIC:
|
|
|
|
return gasPriceButtonGroup;
|
|
|
|
case GAS_INPUT_MODES.INLINE:
|
|
|
|
return advancedGasInputs;
|
|
|
|
case GAS_INPUT_MODES.CUSTOM:
|
|
|
|
default:
|
|
|
|
return gasFeeDisplay;
|
2019-02-06 01:24:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
render() {
|
2021-06-23 23:35:25 +02:00
|
|
|
const { gasFeeError, gasInputMode, 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>
|
2021-06-23 23:35:25 +02:00
|
|
|
{gasInputMode === GAS_INPUT_MODES.BASIC || advancedInlineGasShown ? (
|
2020-11-03 00:41:28 +01:00
|
|
|
<SendRowWrapper>{this.renderAdvancedOptionsButton()}</SendRowWrapper>
|
|
|
|
) : null}
|
2020-10-29 17:31:48 +01:00
|
|
|
</>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-04-11 16:21:54 +02:00
|
|
|
}
|
|
|
|
}
|