mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-02 14:15:06 +01:00
78f4684b2a
* MetaMetrics: add EVENT.CATEGORIES const * MetaMetrics: add EVENT.CATEGORIES.INPAGE_PROVIDER * MetaMetrics: add EVENT.CATEGORIES.AUTH * MetaMetrics: add EVENT.CATEGORIES.ACCOUNTS pt. 1 * MetaMetrics: add EVENT.CATEGORIES.ACCOUNTS pt. 2 confirm we want to use 'Accounts' instead of 'Account' * MetaMetrics: add EVENT.CATEGORIES.MESSAGES * MetaMetrics: add EVENT.CATEGORIES.RETENTION const * MetaMetrics: add EVENT.CATEGORIES.SETTINGS * MetaMask: add missing EVENT.CATEGORIES.SNAPS * MetaMetrics: add EVENT.CATEGORIES.WALLET const * MetaMetrics: add EVENT.CATEGORIES.ONBOARDING const * MetaMetrics: add EVENT.CATEGORIES.ONBOARDING & EVENT.CATEGORIES.TRANSACTIONS consts * MetaMetrics: use EVENT.CATEGORIES * ducks/swaps: revert slice name * MetaMetrics: add missing EVENT.CATEGORIES.NETWORK
241 lines
7.1 KiB
JavaScript
241 lines
7.1 KiB
JavaScript
import React, { Component } from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import PageContainer from '../../../ui/page-container';
|
|
import { Tabs, Tab } from '../../../ui/tabs';
|
|
import {
|
|
disconnectGasFeeEstimatePoller,
|
|
getGasFeeEstimatesAndStartPolling,
|
|
addPollingTokenToAppState,
|
|
removePollingTokenFromAppState,
|
|
} from '../../../../store/actions';
|
|
import { EVENT } from '../../../../../shared/constants/metametrics';
|
|
import AdvancedTabContent from './advanced-tab-content';
|
|
import BasicTabContent from './basic-tab-content';
|
|
|
|
export default class GasModalPageContainer extends Component {
|
|
static contextTypes = {
|
|
t: PropTypes.func,
|
|
trackEvent: PropTypes.func,
|
|
};
|
|
|
|
static propTypes = {
|
|
hideBasic: PropTypes.bool,
|
|
updateCustomGasPrice: PropTypes.func,
|
|
updateCustomGasLimit: PropTypes.func,
|
|
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,
|
|
}),
|
|
onSubmit: PropTypes.func,
|
|
customModalGasPriceInHex: PropTypes.string,
|
|
customModalGasLimitInHex: PropTypes.string,
|
|
cancelAndClose: PropTypes.func,
|
|
customPriceIsSafe: PropTypes.bool,
|
|
isSpeedUp: PropTypes.bool,
|
|
isRetry: PropTypes.bool,
|
|
disableSave: PropTypes.bool,
|
|
customPriceIsExcessive: PropTypes.bool.isRequired,
|
|
};
|
|
|
|
constructor(props) {
|
|
super(props);
|
|
this.state = {
|
|
pollingToken: undefined,
|
|
};
|
|
}
|
|
|
|
componentDidMount() {
|
|
this._isMounted = true;
|
|
getGasFeeEstimatesAndStartPolling().then((pollingToken) => {
|
|
if (this._isMounted) {
|
|
addPollingTokenToAppState(pollingToken);
|
|
this.setState({ pollingToken });
|
|
} else {
|
|
disconnectGasFeeEstimatePoller(pollingToken);
|
|
removePollingTokenFromAppState(pollingToken);
|
|
}
|
|
});
|
|
window.addEventListener('beforeunload', this._beforeUnload);
|
|
}
|
|
|
|
_beforeUnload = () => {
|
|
this._isMounted = false;
|
|
if (this.state.pollingToken) {
|
|
disconnectGasFeeEstimatePoller(this.state.pollingToken);
|
|
removePollingTokenFromAppState(this.state.pollingToken);
|
|
}
|
|
};
|
|
|
|
componentWillUnmount() {
|
|
this._beforeUnload();
|
|
window.removeEventListener('beforeunload', this._beforeUnload);
|
|
}
|
|
|
|
renderBasicTabContent(gasPriceButtonGroupProps) {
|
|
return (
|
|
<BasicTabContent gasPriceButtonGroupProps={gasPriceButtonGroupProps} />
|
|
);
|
|
}
|
|
|
|
renderAdvancedTabContent() {
|
|
const {
|
|
updateCustomGasPrice,
|
|
updateCustomGasLimit,
|
|
customModalGasPriceInHex,
|
|
customModalGasLimitInHex,
|
|
insufficientBalance,
|
|
customPriceIsSafe,
|
|
isSpeedUp,
|
|
isRetry,
|
|
customPriceIsExcessive,
|
|
infoRowProps: { transactionFee },
|
|
} = this.props;
|
|
|
|
return (
|
|
<AdvancedTabContent
|
|
updateCustomGasPrice={updateCustomGasPrice}
|
|
updateCustomGasLimit={updateCustomGasLimit}
|
|
customModalGasPriceInHex={customModalGasPriceInHex}
|
|
customModalGasLimitInHex={customModalGasLimitInHex}
|
|
transactionFee={transactionFee}
|
|
insufficientBalance={insufficientBalance}
|
|
customPriceIsSafe={customPriceIsSafe}
|
|
isSpeedUp={isSpeedUp}
|
|
isRetry={isRetry}
|
|
customPriceIsExcessive={customPriceIsExcessive}
|
|
/>
|
|
);
|
|
}
|
|
|
|
renderInfoRows(newTotalFiat, newTotalEth, sendAmount, transactionFee) {
|
|
return (
|
|
<div className="gas-modal-content__info-row-wrapper">
|
|
<div className="gas-modal-content__info-row">
|
|
<div className="gas-modal-content__info-row__send-info">
|
|
<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>
|
|
<div className="gas-modal-content__info-row__transaction-info">
|
|
<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>
|
|
<div className="gas-modal-content__info-row__total-info">
|
|
<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>
|
|
);
|
|
}
|
|
|
|
renderTabs() {
|
|
const {
|
|
gasPriceButtonGroupProps,
|
|
hideBasic,
|
|
infoRowProps: { newTotalFiat, newTotalEth, sendAmount, transactionFee },
|
|
} = this.props;
|
|
|
|
let tabsToRender;
|
|
if (hideBasic) {
|
|
tabsToRender = [
|
|
{
|
|
name: this.context.t('advanced'),
|
|
content: this.renderAdvancedTabContent(),
|
|
},
|
|
];
|
|
} else {
|
|
tabsToRender = [
|
|
{
|
|
name: this.context.t('basic'),
|
|
content: this.renderBasicTabContent(gasPriceButtonGroupProps),
|
|
},
|
|
{
|
|
name: this.context.t('advanced'),
|
|
content: this.renderAdvancedTabContent(),
|
|
},
|
|
];
|
|
}
|
|
|
|
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,
|
|
)}
|
|
</div>
|
|
</Tab>
|
|
))}
|
|
</Tabs>
|
|
);
|
|
}
|
|
|
|
render() {
|
|
const {
|
|
cancelAndClose,
|
|
onSubmit,
|
|
customModalGasPriceInHex,
|
|
customModalGasLimitInHex,
|
|
disableSave,
|
|
isSpeedUp,
|
|
} = this.props;
|
|
|
|
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={() => {
|
|
if (isSpeedUp) {
|
|
this.context.trackEvent({
|
|
category: EVENT.CATEGORIES.NAVIGATION,
|
|
event: 'Saved "Speed Up"',
|
|
properties: {
|
|
action: 'Activity Log',
|
|
legacy_event: true,
|
|
},
|
|
});
|
|
}
|
|
onSubmit(customModalGasLimitInHex, customModalGasPriceInHex);
|
|
}}
|
|
submitText={this.context.t('save')}
|
|
headerCloseText={this.context.t('close')}
|
|
hideCancel
|
|
/>
|
|
</div>
|
|
);
|
|
}
|
|
}
|