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';
|
|
|
|
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,
|
2021-04-28 20:02:01 +02:00
|
|
|
isEthGasPrice: PropTypes.bool,
|
|
|
|
noGasPrice: PropTypes.bool,
|
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-04-28 20:02:01 +02:00
|
|
|
const {
|
|
|
|
showCustomizeGasModal,
|
|
|
|
isMainnet,
|
|
|
|
isEthGasPrice,
|
|
|
|
noGasPrice,
|
|
|
|
} = this.props;
|
2020-08-19 16:03:15 +02:00
|
|
|
// Tests should behave in same way as mainnet, but are using Localhost
|
|
|
|
if (!isMainnet && !process.env.IN_TEST) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return null;
|
2020-08-19 16:03:15 +02:00
|
|
|
}
|
2021-04-28 20:02:01 +02:00
|
|
|
if (isEthGasPrice || noGasPrice) {
|
|
|
|
return null;
|
|
|
|
}
|
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
|
|
|
});
|
|
|
|
showCustomizeGasModal();
|
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
|
|
|
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,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = this.props;
|
2019-05-20 18:38:08 +02:00
|
|
|
|
|
|
|
setAmountToMax({
|
|
|
|
balance,
|
|
|
|
gasTotal,
|
2020-05-29 19:46:10 +02:00
|
|
|
sendToken,
|
2019-05-20 18:38:08 +02:00
|
|
|
tokenBalance,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-05-20 18:38:08 +02: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,
|
|
|
|
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,
|
2021-04-28 20:02:01 +02:00
|
|
|
isEthGasPrice,
|
|
|
|
noGasPrice,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = this.props;
|
2021-06-21 21:02:51 +02:00
|
|
|
const { trackEvent } = this.context;
|
2021-04-28 20:02:01 +02:00
|
|
|
const gasPriceFetchFailure = isEthGasPrice || noGasPrice;
|
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
|
|
|
if (maxModeOn) {
|
2021-02-04 19:15:23 +01:00
|
|
|
this.setMaxAmount();
|
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}
|
|
|
|
onReset={() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
resetGasButtons();
|
2019-07-31 22:17:11 +02:00
|
|
|
if (maxModeOn) {
|
2021-02-04 19:15:23 +01:00
|
|
|
this.setMaxAmount();
|
2019-07-31 22:17:11 +02:00
|
|
|
}
|
|
|
|
}}
|
2019-12-03 17:35:44 +01:00
|
|
|
onClick={() => showCustomizeGasModal()}
|
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
|
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>
|
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-04-28 20:02:01 +02:00
|
|
|
if (
|
|
|
|
advancedInlineGasShown ||
|
|
|
|
(!isMainnet && !process.env.IN_TEST) ||
|
|
|
|
gasPriceFetchFailure
|
|
|
|
) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return advancedGasInputs;
|
2019-02-06 01:24:28 +01:00
|
|
|
} else if (gasButtonGroupShown) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return gasPriceButtonGroup;
|
2019-02-06 01:24:28 +01:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
return gasFeeDisplay;
|
2019-02-06 01:24:28 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
gasFeeError,
|
|
|
|
gasButtonGroupShown,
|
|
|
|
advancedInlineGasShown,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = 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
|
|
|
</>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-04-11 16:21:54 +02:00
|
|
|
}
|
|
|
|
}
|