2021-02-04 19:15:23 +01:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import PageContainer from '../../../components/ui/page-container';
|
|
|
|
import { Tabs, Tab } from '../../../components/ui/tabs';
|
|
|
|
import { calcGasTotal } from '../../send/send.utils';
|
|
|
|
import { sumHexWEIsToUnformattedFiat } from '../../../helpers/utils/conversions.util';
|
|
|
|
import AdvancedGasInputs from '../../../components/app/gas-customization/advanced-gas-inputs';
|
|
|
|
import BasicTabContent from '../../../components/app/gas-customization/gas-modal-page-container/basic-tab-content';
|
|
|
|
import { GAS_ESTIMATE_TYPES } from '../../../helpers/constants/common';
|
2020-11-04 17:14:08 +01:00
|
|
|
|
|
|
|
export default class GasModalPageContainer extends Component {
|
|
|
|
static contextTypes = {
|
|
|
|
t: PropTypes.func,
|
|
|
|
trackEvent: PropTypes.func,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-11-04 17:14:08 +01:00
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
insufficientBalance: PropTypes.bool,
|
|
|
|
gasPriceButtonGroupProps: PropTypes.object,
|
|
|
|
infoRowProps: PropTypes.shape({
|
|
|
|
originalTotalFiat: PropTypes.string,
|
|
|
|
originalTotalEth: PropTypes.string,
|
|
|
|
newTotalFiat: PropTypes.string,
|
|
|
|
newTotalEth: PropTypes.string,
|
|
|
|
sendAmount: PropTypes.string,
|
|
|
|
transactionFee: PropTypes.string,
|
|
|
|
extraInfoRow: PropTypes.shape({
|
|
|
|
label: PropTypes.string,
|
|
|
|
value: PropTypes.string,
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
onSubmit: PropTypes.func,
|
|
|
|
cancelAndClose: PropTypes.func,
|
|
|
|
showCustomPriceTooLowWarning: PropTypes.bool,
|
|
|
|
disableSave: PropTypes.bool,
|
|
|
|
customGasLimitMessage: PropTypes.string,
|
|
|
|
customTotalSupplement: PropTypes.string,
|
2020-12-07 16:58:06 +01:00
|
|
|
usdConversionRate: PropTypes.number,
|
2020-11-04 17:14:08 +01:00
|
|
|
customGasPrice: PropTypes.string,
|
|
|
|
customGasLimit: PropTypes.string,
|
|
|
|
setSwapsCustomizationModalPrice: PropTypes.func,
|
|
|
|
setSwapsCustomizationModalLimit: PropTypes.func,
|
|
|
|
gasEstimateLoadingHasFailed: PropTypes.bool,
|
2020-11-10 21:20:39 +01:00
|
|
|
minimumGasLimit: PropTypes.number.isRequired,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-11-04 17:14:08 +01:00
|
|
|
|
|
|
|
state = {
|
|
|
|
gasSpeedType: '',
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-11-04 17:14:08 +01:00
|
|
|
|
|
|
|
setGasSpeedType(gasEstimateType) {
|
|
|
|
if (gasEstimateType === GAS_ESTIMATE_TYPES.AVERAGE) {
|
2021-02-04 19:15:23 +01:00
|
|
|
this.setState({ gasSpeedType: 'average' });
|
2020-11-04 17:14:08 +01:00
|
|
|
} else {
|
2021-02-04 19:15:23 +01:00
|
|
|
this.setState({ gasSpeedType: 'fast' });
|
2020-11-04 17:14:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
renderBasicTabContent(gasPriceButtonGroupProps) {
|
|
|
|
return (
|
|
|
|
<BasicTabContent
|
|
|
|
gasPriceButtonGroupProps={{
|
|
|
|
...gasPriceButtonGroupProps,
|
2020-11-12 23:57:29 +01:00
|
|
|
handleGasPriceSelection: ({ gasPrice, gasEstimateType }) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
this.setGasSpeedType(gasEstimateType);
|
|
|
|
this.props.setSwapsCustomizationModalPrice(gasPrice);
|
2020-11-04 17:14:08 +01:00
|
|
|
},
|
|
|
|
}}
|
|
|
|
/>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-04 17:14:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
renderAdvancedTabContent() {
|
|
|
|
const {
|
|
|
|
insufficientBalance,
|
|
|
|
showCustomPriceTooLowWarning,
|
|
|
|
infoRowProps: { transactionFee },
|
|
|
|
customGasLimitMessage,
|
|
|
|
setSwapsCustomizationModalPrice,
|
|
|
|
setSwapsCustomizationModalLimit,
|
|
|
|
customGasPrice,
|
|
|
|
customGasLimit,
|
2020-11-10 21:20:39 +01:00
|
|
|
minimumGasLimit,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = this.props;
|
2020-11-04 17:14:08 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="advanced-tab">
|
|
|
|
<div className="advanced-tab__transaction-data-summary">
|
|
|
|
<div className="advanced-tab__transaction-data-summary__titles">
|
|
|
|
<span>{this.context.t('newTransactionFee')}</span>
|
|
|
|
</div>
|
|
|
|
<div className="advanced-tab__transaction-data-summary__container">
|
|
|
|
<div className="advanced-tab__transaction-data-summary__fee">
|
|
|
|
{transactionFee}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="advanced-tab__fee-chart">
|
|
|
|
<div className="advanced-tab__gas-inputs">
|
|
|
|
<AdvancedGasInputs
|
|
|
|
updateCustomGasPrice={(updatedPrice) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
this.setState({ gasSpeedType: 'custom' });
|
|
|
|
setSwapsCustomizationModalPrice(updatedPrice);
|
2020-11-04 17:14:08 +01:00
|
|
|
}}
|
|
|
|
updateCustomGasLimit={(updatedLimit) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
this.setState({ gasSpeedType: 'custom' });
|
|
|
|
setSwapsCustomizationModalLimit(updatedLimit);
|
2020-11-04 17:14:08 +01:00
|
|
|
}}
|
|
|
|
customGasPrice={customGasPrice}
|
|
|
|
customGasLimit={customGasLimit}
|
|
|
|
insufficientBalance={insufficientBalance}
|
|
|
|
customPriceIsSafe={!showCustomPriceTooLowWarning}
|
|
|
|
customGasLimitMessage={customGasLimitMessage}
|
2020-11-10 21:20:39 +01:00
|
|
|
minimumGasLimit={minimumGasLimit}
|
2020-11-04 17:14:08 +01:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-04 17:14:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
renderInfoRows(
|
|
|
|
newTotalFiat,
|
|
|
|
newTotalEth,
|
|
|
|
sendAmount,
|
|
|
|
transactionFee,
|
|
|
|
extraInfoRow,
|
|
|
|
) {
|
|
|
|
return (
|
|
|
|
<div className="gas-modal-content__info-row-wrapper">
|
|
|
|
<div className="gas-modal-content__info-row">
|
2021-07-02 15:48:34 +02:00
|
|
|
<div
|
|
|
|
className="gas-modal-content__info-row__send-info"
|
|
|
|
data-testid="gas-modal-content__info-row__send-info"
|
|
|
|
>
|
2020-11-04 17:14:08 +01:00
|
|
|
<span className="gas-modal-content__info-row__send-info__label">
|
|
|
|
{this.context.t('sendAmount')}
|
|
|
|
</span>
|
|
|
|
<span className="gas-modal-content__info-row__send-info__value">
|
|
|
|
{sendAmount}
|
|
|
|
</span>
|
|
|
|
</div>
|
2021-07-02 15:48:34 +02:00
|
|
|
<div
|
|
|
|
className="gas-modal-content__info-row__transaction-info"
|
|
|
|
data-testid="gas-modal-content__info-row__transaction-info"
|
|
|
|
>
|
2020-11-04 17:14:08 +01:00
|
|
|
<span className="gas-modal-content__info-row__transaction-info__label">
|
|
|
|
{this.context.t('transactionFee')}
|
|
|
|
</span>
|
|
|
|
<span className="gas-modal-content__info-row__transaction-info__value">
|
|
|
|
{transactionFee}
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
{extraInfoRow && (
|
|
|
|
<div className="gas-modal-content__info-row__transaction-info">
|
|
|
|
<span className="gas-modal-content__info-row__transaction-info__label">
|
|
|
|
{extraInfoRow.label}
|
|
|
|
</span>
|
|
|
|
<span className="gas-modal-content__info-row__transaction-info__value">
|
|
|
|
{extraInfoRow.value}
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
)}
|
2021-07-02 15:48:34 +02:00
|
|
|
<div
|
|
|
|
className="gas-modal-content__info-row__total-info"
|
|
|
|
data-testid="gas-modal-content__info-row__total-info"
|
|
|
|
>
|
2020-11-04 17:14:08 +01:00
|
|
|
<span className="gas-modal-content__info-row__total-info__label">
|
|
|
|
{this.context.t('newTotal')}
|
|
|
|
</span>
|
|
|
|
<span className="gas-modal-content__info-row__total-info__value">
|
|
|
|
{newTotalEth}
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
<div className="gas-modal-content__info-row__fiat-total-info">
|
|
|
|
<span className="gas-modal-content__info-row__fiat-total-info__value">
|
|
|
|
{newTotalFiat}
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-04 17:14:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
renderTabs() {
|
|
|
|
const {
|
|
|
|
gasPriceButtonGroupProps,
|
|
|
|
infoRowProps: {
|
|
|
|
newTotalFiat,
|
|
|
|
newTotalEth,
|
|
|
|
sendAmount,
|
|
|
|
transactionFee,
|
|
|
|
extraInfoRow,
|
|
|
|
},
|
|
|
|
gasEstimateLoadingHasFailed,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = this.props;
|
2020-11-04 17:14:08 +01:00
|
|
|
|
|
|
|
const basicTabInfo = {
|
|
|
|
name: this.context.t('basic'),
|
|
|
|
content: this.renderBasicTabContent({
|
|
|
|
...gasPriceButtonGroupProps,
|
|
|
|
handleGasPriceSelection: this.props.setSwapsCustomizationModalPrice,
|
|
|
|
}),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-11-04 17:14:08 +01:00
|
|
|
const advancedTabInfo = {
|
|
|
|
name: this.context.t('advanced'),
|
|
|
|
content: this.renderAdvancedTabContent(),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-11-04 17:14:08 +01:00
|
|
|
|
|
|
|
const tabsToRender = gasEstimateLoadingHasFailed
|
|
|
|
? [advancedTabInfo]
|
2021-02-04 19:15:23 +01:00
|
|
|
: [basicTabInfo, advancedTabInfo];
|
2020-11-04 17:14:08 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Tabs>
|
|
|
|
{tabsToRender.map(({ name, content }, i) => (
|
|
|
|
<Tab name={name} key={`gas-modal-tab-${i}`}>
|
|
|
|
<div className="gas-modal-content">
|
|
|
|
{content}
|
|
|
|
{this.renderInfoRows(
|
|
|
|
newTotalFiat,
|
|
|
|
newTotalEth,
|
|
|
|
sendAmount,
|
|
|
|
transactionFee,
|
|
|
|
extraInfoRow,
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</Tab>
|
|
|
|
))}
|
|
|
|
</Tabs>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-04 17:14:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
cancelAndClose,
|
|
|
|
onSubmit,
|
|
|
|
disableSave,
|
|
|
|
customGasPrice,
|
|
|
|
customGasLimit,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = this.props;
|
2020-11-04 17:14:08 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="gas-modal-page-container">
|
|
|
|
<PageContainer
|
|
|
|
title={this.context.t('customGas')}
|
|
|
|
subtitle={this.context.t('customGasSubTitle')}
|
|
|
|
tabsComponent={this.renderTabs()}
|
|
|
|
disabled={disableSave}
|
|
|
|
onCancel={() => cancelAndClose()}
|
|
|
|
onClose={() => cancelAndClose()}
|
|
|
|
onSubmit={() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const newSwapGasTotal = calcGasTotal(
|
|
|
|
customGasLimit,
|
|
|
|
customGasPrice,
|
|
|
|
);
|
2020-11-04 17:14:08 +01:00
|
|
|
|
|
|
|
this.context.trackEvent({
|
|
|
|
event: 'Gas Fees Changed',
|
|
|
|
category: 'swaps',
|
|
|
|
properties: {
|
|
|
|
speed_set: this.state.gasSpeedType,
|
2020-11-10 18:39:45 +01:00
|
|
|
gas_fees: sumHexWEIsToUnformattedFiat(
|
|
|
|
[newSwapGasTotal, this.props.customTotalSupplement],
|
2020-11-04 17:14:08 +01:00
|
|
|
'usd',
|
2020-11-10 18:39:45 +01:00
|
|
|
this.props.usdConversionRate,
|
2020-11-04 17:14:08 +01:00
|
|
|
)?.slice(1),
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
onSubmit(customGasLimit, customGasPrice);
|
2020-11-04 17:14:08 +01:00
|
|
|
}}
|
|
|
|
submitText={this.context.t('save')}
|
|
|
|
headerCloseText={this.context.t('close')}
|
|
|
|
hideCancel
|
|
|
|
/>
|
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-04 17:14:08 +01:00
|
|
|
}
|
|
|
|
}
|