2021-02-04 19:15:23 +01:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2021-04-28 21:53:59 +02:00
|
|
|
import { ENVIRONMENT_TYPE_NOTIFICATION } from '../../../shared/constants/app';
|
|
|
|
import { getEnvironmentType } from '../../../app/scripts/lib/util';
|
2021-07-31 03:29:21 +02:00
|
|
|
import ConfirmPageContainer from '../../components/app/confirm-page-container';
|
2021-02-04 19:15:23 +01:00
|
|
|
import { isBalanceSufficient } from '../send/send.utils';
|
2021-08-04 15:24:40 +02:00
|
|
|
import {
|
|
|
|
addHexes,
|
|
|
|
hexToDecimal,
|
|
|
|
hexWEIToDecGWEI,
|
|
|
|
} from '../../helpers/utils/conversions.util';
|
2021-05-03 19:51:09 +02:00
|
|
|
import {
|
|
|
|
CONFIRM_TRANSACTION_ROUTE,
|
|
|
|
DEFAULT_ROUTE,
|
|
|
|
} from '../../helpers/constants/routes';
|
2018-07-06 20:58:41 +02:00
|
|
|
import {
|
|
|
|
INSUFFICIENT_FUNDS_ERROR_KEY,
|
|
|
|
TRANSACTION_ERROR_KEY,
|
2019-05-23 15:56:40 +02:00
|
|
|
GAS_LIMIT_TOO_LOW_ERROR_KEY,
|
2021-04-28 20:02:01 +02:00
|
|
|
ETH_GAS_PRICE_FETCH_WARNING_KEY,
|
|
|
|
GAS_PRICE_FETCH_FAILURE_ERROR_KEY,
|
2021-02-04 19:15:23 +01:00
|
|
|
} from '../../helpers/constants/error-keys';
|
|
|
|
import UserPreferencedCurrencyDisplay from '../../components/app/user-preferenced-currency-display';
|
|
|
|
import { PRIMARY, SECONDARY } from '../../helpers/constants/common';
|
|
|
|
import TextField from '../../components/ui/text-field';
|
2020-11-07 08:38:12 +01:00
|
|
|
import {
|
2021-03-10 21:16:44 +01:00
|
|
|
TRANSACTION_TYPES,
|
2020-11-07 08:38:12 +01:00
|
|
|
TRANSACTION_STATUSES,
|
2021-04-28 21:53:59 +02:00
|
|
|
} from '../../../shared/constants/transaction';
|
2021-03-10 21:16:44 +01:00
|
|
|
import { getTransactionTypeTitle } from '../../helpers/utils/transactions.util';
|
2021-05-21 22:07:06 +02:00
|
|
|
import { toBuffer } from '../../../shared/modules/buffer-utils';
|
2018-06-23 08:52:45 +02:00
|
|
|
|
2021-06-30 18:58:18 +02:00
|
|
|
import TransactionDetail from '../../components/app/transaction-detail/transaction-detail.component';
|
|
|
|
import TransactionDetailItem from '../../components/app/transaction-detail-item/transaction-detail-item.component';
|
|
|
|
import InfoTooltip from '../../components/ui/info-tooltip/info-tooltip';
|
2021-08-17 00:48:24 +02:00
|
|
|
import LoadingHeartBeat from '../../components/ui/loading-heartbeat';
|
2021-07-26 17:35:51 +02:00
|
|
|
import GasTiming from '../../components/app/gas-timing/gas-timing.component';
|
2021-10-21 21:17:03 +02:00
|
|
|
import LedgerInstructionField from '../../components/app/ledger-instruction-field';
|
2021-06-30 18:58:18 +02:00
|
|
|
|
2021-09-01 20:02:01 +02:00
|
|
|
import {
|
|
|
|
COLORS,
|
|
|
|
FONT_STYLE,
|
|
|
|
TYPOGRAPHY,
|
|
|
|
} from '../../helpers/constants/design-system';
|
2021-07-31 02:45:18 +02:00
|
|
|
import {
|
|
|
|
disconnectGasFeeEstimatePoller,
|
|
|
|
getGasFeeEstimatesAndStartPolling,
|
2021-08-04 23:53:13 +02:00
|
|
|
addPollingTokenToAppState,
|
|
|
|
removePollingTokenFromAppState,
|
2021-07-31 02:45:18 +02:00
|
|
|
} from '../../store/actions';
|
2021-07-16 17:00:03 +02:00
|
|
|
|
2021-09-01 20:02:01 +02:00
|
|
|
import Typography from '../../components/ui/typography/typography';
|
2021-10-19 21:31:56 +02:00
|
|
|
import { MIN_GAS_LIMIT_DEC } from '../send/send.constants';
|
2021-09-01 20:02:01 +02:00
|
|
|
|
2021-08-17 00:48:24 +02:00
|
|
|
const renderHeartBeatIfNotInTest = () =>
|
|
|
|
process.env.IN_TEST === 'true' ? null : <LoadingHeartBeat />;
|
|
|
|
|
2018-06-23 08:52:45 +02:00
|
|
|
export default class ConfirmTransactionBase extends Component {
|
|
|
|
static contextTypes = {
|
|
|
|
t: PropTypes.func,
|
2019-03-05 16:45:01 +01:00
|
|
|
metricsEvent: PropTypes.func,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-06-23 08:52:45 +02:00
|
|
|
|
|
|
|
static propTypes = {
|
2018-07-06 20:58:41 +02:00
|
|
|
// react-router props
|
2018-06-23 08:52:45 +02:00
|
|
|
history: PropTypes.object,
|
|
|
|
// Redux props
|
2018-07-06 20:58:41 +02:00
|
|
|
balance: PropTypes.string,
|
|
|
|
cancelTransaction: PropTypes.func,
|
2018-09-20 02:48:28 +02:00
|
|
|
cancelAllTransactions: PropTypes.func,
|
2018-07-06 20:58:41 +02:00
|
|
|
clearConfirmTransaction: PropTypes.func,
|
|
|
|
conversionRate: PropTypes.number,
|
|
|
|
fromAddress: PropTypes.string,
|
|
|
|
fromName: PropTypes.string,
|
2018-10-17 01:03:29 +02:00
|
|
|
hexTransactionAmount: PropTypes.string,
|
2021-07-31 02:45:18 +02:00
|
|
|
hexMinimumTransactionFee: PropTypes.string,
|
|
|
|
hexMaximumTransactionFee: PropTypes.string,
|
2018-10-17 01:03:29 +02:00
|
|
|
hexTransactionTotal: PropTypes.string,
|
2018-07-06 20:58:41 +02:00
|
|
|
methodData: PropTypes.object,
|
|
|
|
nonce: PropTypes.string,
|
2019-09-27 06:30:36 +02:00
|
|
|
useNonceField: PropTypes.bool,
|
|
|
|
customNonceValue: PropTypes.string,
|
|
|
|
updateCustomNonce: PropTypes.func,
|
2018-06-23 08:52:45 +02:00
|
|
|
sendTransaction: PropTypes.func,
|
|
|
|
showTransactionConfirmedModal: PropTypes.func,
|
2018-09-24 07:07:19 +02:00
|
|
|
showRejectTransactionsConfirmationModal: PropTypes.func,
|
2018-07-06 20:58:41 +02:00
|
|
|
toAddress: PropTypes.string,
|
|
|
|
tokenData: PropTypes.object,
|
|
|
|
tokenProps: PropTypes.object,
|
|
|
|
toName: PropTypes.string,
|
2019-11-01 18:54:00 +01:00
|
|
|
toEns: PropTypes.string,
|
2019-08-08 20:45:30 +02:00
|
|
|
toNickname: PropTypes.string,
|
2018-07-06 20:58:41 +02:00
|
|
|
transactionStatus: PropTypes.string,
|
|
|
|
txData: PropTypes.object,
|
2018-09-20 02:48:28 +02:00
|
|
|
unapprovedTxCount: PropTypes.number,
|
2018-11-13 18:19:12 +01:00
|
|
|
currentNetworkUnapprovedTxs: PropTypes.object,
|
2019-02-08 14:50:25 +01:00
|
|
|
customGas: PropTypes.object,
|
2018-06-23 08:52:45 +02:00
|
|
|
// Component props
|
2019-04-08 16:02:51 +02:00
|
|
|
actionKey: PropTypes.string,
|
2018-06-23 08:52:45 +02:00
|
|
|
contentComponent: PropTypes.node,
|
2018-07-06 20:58:41 +02:00
|
|
|
dataComponent: PropTypes.node,
|
|
|
|
hideData: PropTypes.bool,
|
|
|
|
hideSubtitle: PropTypes.bool,
|
2018-06-23 08:52:45 +02:00
|
|
|
identiconAddress: PropTypes.string,
|
|
|
|
onEdit: PropTypes.func,
|
2018-10-17 01:03:29 +02:00
|
|
|
subtitleComponent: PropTypes.node,
|
2018-07-06 20:58:41 +02:00
|
|
|
title: PropTypes.string,
|
2021-03-10 21:16:44 +01:00
|
|
|
type: PropTypes.string,
|
2019-09-27 06:30:36 +02:00
|
|
|
getNextNonce: PropTypes.func,
|
|
|
|
nextNonce: PropTypes.number,
|
2019-11-01 18:54:00 +01:00
|
|
|
tryReverseResolveAddress: PropTypes.func.isRequired,
|
2019-11-05 16:13:48 +01:00
|
|
|
hideSenderToRecipient: PropTypes.bool,
|
|
|
|
showAccountInHeader: PropTypes.bool,
|
2020-06-01 19:54:32 +02:00
|
|
|
mostRecentOverviewPage: PropTypes.string.isRequired,
|
2021-04-28 20:02:01 +02:00
|
|
|
isEthGasPrice: PropTypes.bool,
|
|
|
|
noGasPrice: PropTypes.bool,
|
2021-05-03 19:51:09 +02:00
|
|
|
setDefaultHomeActiveTabName: PropTypes.func,
|
2021-07-31 03:29:21 +02:00
|
|
|
primaryTotalTextOverride: PropTypes.string,
|
|
|
|
secondaryTotalTextOverride: PropTypes.string,
|
2021-08-06 01:59:58 +02:00
|
|
|
gasIsLoading: PropTypes.bool,
|
2021-08-06 03:07:04 +02:00
|
|
|
primaryTotalTextOverrideMaxAmount: PropTypes.string,
|
|
|
|
useNativeCurrencyAsPrimaryCurrency: PropTypes.bool,
|
2021-08-06 21:31:30 +02:00
|
|
|
maxFeePerGas: PropTypes.string,
|
|
|
|
maxPriorityFeePerGas: PropTypes.string,
|
2021-08-07 00:18:53 +02:00
|
|
|
baseFeePerGas: PropTypes.string,
|
2021-08-14 02:13:21 +02:00
|
|
|
isMainnet: PropTypes.bool,
|
2021-08-17 00:45:55 +02:00
|
|
|
gasFeeIsCustom: PropTypes.bool,
|
2021-09-20 22:19:35 +02:00
|
|
|
showLedgerSteps: PropTypes.bool.isRequired,
|
2021-09-15 23:54:51 +02:00
|
|
|
nativeCurrency: PropTypes.string,
|
2021-10-06 20:29:57 +02:00
|
|
|
supportsEIP1559: PropTypes.bool,
|
2021-10-21 21:17:03 +02:00
|
|
|
hardwareWalletRequiresConnection: PropTypes.bool,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-06-23 08:52:45 +02:00
|
|
|
|
2018-08-03 23:44:57 +02:00
|
|
|
state = {
|
|
|
|
submitting: false,
|
2018-08-28 21:18:57 +02:00
|
|
|
submitError: null,
|
2019-09-27 06:30:36 +02:00
|
|
|
submitWarning: '',
|
2021-04-28 20:02:01 +02:00
|
|
|
ethGasPriceWarning: '',
|
2021-07-08 22:23:00 +02:00
|
|
|
editingGas: false,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-08-03 23:44:57 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
componentDidUpdate(prevProps) {
|
2018-06-23 08:52:45 +02:00
|
|
|
const {
|
|
|
|
transactionStatus,
|
|
|
|
showTransactionConfirmedModal,
|
|
|
|
history,
|
|
|
|
clearConfirmTransaction,
|
2019-09-27 06:30:36 +02:00
|
|
|
nextNonce,
|
|
|
|
customNonceValue,
|
2020-03-12 14:50:37 +01:00
|
|
|
toAddress,
|
|
|
|
tryReverseResolveAddress,
|
2021-04-28 20:02:01 +02:00
|
|
|
isEthGasPrice,
|
2021-05-03 19:51:09 +02:00
|
|
|
setDefaultHomeActiveTabName,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = this.props;
|
2020-03-12 14:50:37 +01:00
|
|
|
const {
|
|
|
|
customNonceValue: prevCustomNonceValue,
|
|
|
|
nextNonce: prevNextNonce,
|
|
|
|
toAddress: prevToAddress,
|
|
|
|
transactionStatus: prevTxStatus,
|
2021-04-28 20:02:01 +02:00
|
|
|
isEthGasPrice: prevIsEthGasPrice,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = prevProps;
|
|
|
|
const statusUpdated = transactionStatus !== prevTxStatus;
|
2020-11-03 00:41:28 +01:00
|
|
|
const txDroppedOrConfirmed =
|
2020-11-03 23:57:51 +01:00
|
|
|
transactionStatus === TRANSACTION_STATUSES.DROPPED ||
|
2021-02-04 19:15:23 +01:00
|
|
|
transactionStatus === TRANSACTION_STATUSES.CONFIRMED;
|
2020-11-03 00:41:28 +01:00
|
|
|
|
|
|
|
if (
|
|
|
|
nextNonce !== prevNextNonce ||
|
|
|
|
customNonceValue !== prevCustomNonceValue
|
|
|
|
) {
|
2021-01-05 18:46:30 +01:00
|
|
|
if (nextNonce !== null && customNonceValue > nextNonce) {
|
2020-11-03 00:41:28 +01:00
|
|
|
this.setState({
|
|
|
|
submitWarning: this.context.t('nextNonceWarning', [nextNonce]),
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-09-27 06:30:36 +02:00
|
|
|
} else {
|
2021-02-04 19:15:23 +01:00
|
|
|
this.setState({ submitWarning: '' });
|
2019-09-27 06:30:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-27 11:29:55 +02:00
|
|
|
if (statusUpdated && txDroppedOrConfirmed) {
|
2018-06-23 08:52:45 +02:00
|
|
|
showTransactionConfirmedModal({
|
2018-09-17 19:34:29 +02:00
|
|
|
onSubmit: () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
clearConfirmTransaction();
|
2021-05-03 19:51:09 +02:00
|
|
|
setDefaultHomeActiveTabName('Activity').then(() => {
|
|
|
|
history.push(DEFAULT_ROUTE);
|
|
|
|
});
|
2018-06-23 08:52:45 +02:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-03-12 14:50:37 +01:00
|
|
|
}
|
2018-06-23 08:52:45 +02:00
|
|
|
|
2020-03-12 14:50:37 +01:00
|
|
|
if (toAddress && toAddress !== prevToAddress) {
|
2021-02-04 19:15:23 +01:00
|
|
|
tryReverseResolveAddress(toAddress);
|
2018-06-23 08:52:45 +02:00
|
|
|
}
|
2021-04-28 20:02:01 +02:00
|
|
|
|
|
|
|
if (isEthGasPrice !== prevIsEthGasPrice) {
|
|
|
|
if (isEthGasPrice) {
|
|
|
|
this.setState({
|
|
|
|
ethGasPriceWarning: this.context.t(ETH_GAS_PRICE_FETCH_WARNING_KEY),
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.setState({
|
|
|
|
ethGasPriceWarning: '',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2018-06-23 08:52:45 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
getErrorKey() {
|
2018-06-23 08:52:45 +02:00
|
|
|
const {
|
|
|
|
balance,
|
|
|
|
conversionRate,
|
2021-07-31 02:45:18 +02:00
|
|
|
hexMaximumTransactionFee,
|
2020-11-03 00:41:28 +01:00
|
|
|
txData: { simulationFails, txParams: { value: amount } = {} } = {},
|
2019-05-23 15:56:40 +02:00
|
|
|
customGas,
|
2021-04-28 20:02:01 +02:00
|
|
|
noGasPrice,
|
2021-08-17 00:45:55 +02:00
|
|
|
gasFeeIsCustom,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = this.props;
|
2018-06-23 08:52:45 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
const insufficientBalance =
|
|
|
|
balance &&
|
|
|
|
!isBalanceSufficient({
|
|
|
|
amount,
|
2021-07-31 02:45:18 +02:00
|
|
|
gasTotal: hexMaximumTransactionFee || '0x0',
|
2020-11-03 00:41:28 +01:00
|
|
|
balance,
|
|
|
|
conversionRate,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-06-23 08:52:45 +02:00
|
|
|
|
|
|
|
if (insufficientBalance) {
|
|
|
|
return {
|
|
|
|
valid: false,
|
2018-07-06 20:58:41 +02:00
|
|
|
errorKey: INSUFFICIENT_FUNDS_ERROR_KEY,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-06-23 08:52:45 +02:00
|
|
|
}
|
|
|
|
|
2021-10-19 21:31:56 +02:00
|
|
|
if (hexToDecimal(customGas.gasLimit) < Number(MIN_GAS_LIMIT_DEC)) {
|
2019-05-23 15:56:40 +02:00
|
|
|
return {
|
|
|
|
valid: false,
|
|
|
|
errorKey: GAS_LIMIT_TOO_LOW_ERROR_KEY,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-05-23 15:56:40 +02:00
|
|
|
}
|
|
|
|
|
2018-06-23 08:52:45 +02:00
|
|
|
if (simulationFails) {
|
|
|
|
return {
|
2018-08-09 01:55:25 +02:00
|
|
|
valid: true,
|
2020-11-03 00:41:28 +01:00
|
|
|
errorKey: simulationFails.errorKey
|
|
|
|
? simulationFails.errorKey
|
|
|
|
: TRANSACTION_ERROR_KEY,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-06-23 08:52:45 +02:00
|
|
|
}
|
|
|
|
|
2021-08-17 00:45:55 +02:00
|
|
|
if (noGasPrice && !gasFeeIsCustom) {
|
2021-04-28 20:02:01 +02:00
|
|
|
return {
|
|
|
|
valid: false,
|
|
|
|
errorKey: GAS_PRICE_FETCH_FAILURE_ERROR_KEY,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-06-23 08:52:45 +02:00
|
|
|
return {
|
|
|
|
valid: true,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-06-23 08:52:45 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
handleEditGas() {
|
|
|
|
const {
|
|
|
|
actionKey,
|
|
|
|
txData: { origin },
|
|
|
|
methodData = {},
|
2021-02-04 19:15:23 +01:00
|
|
|
} = this.props;
|
2019-03-05 16:45:01 +01:00
|
|
|
|
|
|
|
this.context.metricsEvent({
|
|
|
|
eventOpts: {
|
|
|
|
category: 'Transactions',
|
|
|
|
action: 'Confirm Screen',
|
|
|
|
name: 'User clicks "Edit" on gas',
|
|
|
|
},
|
|
|
|
customVariables: {
|
|
|
|
recipientKnown: null,
|
2020-11-03 00:41:28 +01:00
|
|
|
functionType:
|
2020-11-07 08:38:12 +01:00
|
|
|
actionKey ||
|
|
|
|
getMethodName(methodData.name) ||
|
2021-03-10 21:16:44 +01:00
|
|
|
TRANSACTION_TYPES.CONTRACT_INTERACTION,
|
2019-03-05 16:45:01 +01:00
|
|
|
origin,
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-06-23 08:52:45 +02:00
|
|
|
|
2021-07-31 03:29:21 +02:00
|
|
|
this.setState({ editingGas: true });
|
2021-07-08 22:23:00 +02:00
|
|
|
}
|
|
|
|
|
2021-07-31 03:29:21 +02:00
|
|
|
handleCloseEditGas() {
|
2021-07-08 22:23:00 +02:00
|
|
|
this.setState({ editingGas: false });
|
2018-06-23 08:52:45 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderDetails() {
|
2018-06-23 08:52:45 +02:00
|
|
|
const {
|
2018-10-17 01:03:29 +02:00
|
|
|
primaryTotalTextOverride,
|
|
|
|
secondaryTotalTextOverride,
|
2021-07-31 02:45:18 +02:00
|
|
|
hexMinimumTransactionFee,
|
2021-08-06 21:31:30 +02:00
|
|
|
hexMaximumTransactionFee,
|
2018-10-17 01:03:29 +02:00
|
|
|
hexTransactionTotal,
|
2019-09-27 06:30:36 +02:00
|
|
|
useNonceField,
|
|
|
|
customNonceValue,
|
|
|
|
updateCustomNonce,
|
|
|
|
nextNonce,
|
|
|
|
getNextNonce,
|
2021-07-16 17:00:03 +02:00
|
|
|
txData,
|
2021-08-06 03:07:04 +02:00
|
|
|
useNativeCurrencyAsPrimaryCurrency,
|
|
|
|
primaryTotalTextOverrideMaxAmount,
|
2021-08-06 21:31:30 +02:00
|
|
|
maxFeePerGas,
|
|
|
|
maxPriorityFeePerGas,
|
2021-08-14 02:13:21 +02:00
|
|
|
isMainnet,
|
2021-09-20 22:19:35 +02:00
|
|
|
showLedgerSteps,
|
2021-10-06 20:29:57 +02:00
|
|
|
supportsEIP1559,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = this.props;
|
2021-06-13 00:25:24 +02:00
|
|
|
const { t } = this.context;
|
2018-06-23 08:52:45 +02:00
|
|
|
|
2021-08-06 03:07:04 +02:00
|
|
|
const renderTotalMaxAmount = () => {
|
|
|
|
if (
|
|
|
|
primaryTotalTextOverrideMaxAmount === undefined &&
|
|
|
|
secondaryTotalTextOverride === undefined
|
|
|
|
) {
|
|
|
|
// Native Send
|
|
|
|
return (
|
|
|
|
<UserPreferencedCurrencyDisplay
|
|
|
|
type={PRIMARY}
|
2021-08-10 22:45:09 +02:00
|
|
|
key="total-max-amount"
|
2021-08-06 21:31:30 +02:00
|
|
|
value={addHexes(txData.txParams.value, hexMaximumTransactionFee)}
|
2021-08-06 03:07:04 +02:00
|
|
|
hideLabel={!useNativeCurrencyAsPrimaryCurrency}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Token send
|
|
|
|
return useNativeCurrencyAsPrimaryCurrency
|
|
|
|
? primaryTotalTextOverrideMaxAmount
|
|
|
|
: secondaryTotalTextOverride;
|
|
|
|
};
|
|
|
|
|
|
|
|
const renderTotalDetailTotal = () => {
|
|
|
|
if (
|
|
|
|
primaryTotalTextOverride === undefined &&
|
|
|
|
secondaryTotalTextOverride === undefined
|
|
|
|
) {
|
|
|
|
return (
|
|
|
|
<UserPreferencedCurrencyDisplay
|
|
|
|
type={PRIMARY}
|
2021-08-10 22:45:09 +02:00
|
|
|
key="total-detail-value"
|
2021-08-06 03:07:04 +02:00
|
|
|
value={hexTransactionTotal}
|
|
|
|
hideLabel={!useNativeCurrencyAsPrimaryCurrency}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return useNativeCurrencyAsPrimaryCurrency
|
|
|
|
? primaryTotalTextOverride
|
|
|
|
: secondaryTotalTextOverride;
|
|
|
|
};
|
|
|
|
|
|
|
|
const renderTotalDetailText = () => {
|
|
|
|
if (
|
|
|
|
primaryTotalTextOverride === undefined &&
|
|
|
|
secondaryTotalTextOverride === undefined
|
|
|
|
) {
|
|
|
|
return (
|
|
|
|
<UserPreferencedCurrencyDisplay
|
|
|
|
type={SECONDARY}
|
2021-08-10 22:45:09 +02:00
|
|
|
key="total-detail-text"
|
2021-08-06 03:07:04 +02:00
|
|
|
value={hexTransactionTotal}
|
|
|
|
hideLabel={Boolean(useNativeCurrencyAsPrimaryCurrency)}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return useNativeCurrencyAsPrimaryCurrency
|
|
|
|
? secondaryTotalTextOverride
|
|
|
|
: primaryTotalTextOverride;
|
|
|
|
};
|
|
|
|
|
2021-06-30 18:58:18 +02:00
|
|
|
const nonceField = useNonceField ? (
|
|
|
|
<div>
|
|
|
|
<div className="confirm-detail-row">
|
|
|
|
<div className="confirm-detail-row__label">
|
|
|
|
{t('nonceFieldHeading')}
|
|
|
|
</div>
|
|
|
|
<div className="custom-nonce-input">
|
|
|
|
<TextField
|
|
|
|
type="number"
|
|
|
|
min="0"
|
|
|
|
placeholder={
|
|
|
|
typeof nextNonce === 'number' ? nextNonce.toString() : null
|
|
|
|
}
|
|
|
|
onChange={({ target: { value } }) => {
|
|
|
|
if (!value.length || Number(value) < 0) {
|
|
|
|
updateCustomNonce('');
|
|
|
|
} else {
|
|
|
|
updateCustomNonce(String(Math.floor(value)));
|
|
|
|
}
|
|
|
|
getNextNonce();
|
|
|
|
}}
|
|
|
|
fullWidth
|
|
|
|
margin="dense"
|
|
|
|
value={customNonceValue || ''}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
) : null;
|
|
|
|
|
2018-06-23 08:52:45 +02:00
|
|
|
return (
|
2021-01-28 18:17:26 +01:00
|
|
|
<div className="confirm-page-container-content__details">
|
2021-07-31 03:29:21 +02:00
|
|
|
<TransactionDetail
|
|
|
|
onEdit={() => this.handleEditGas()}
|
|
|
|
rows={[
|
|
|
|
<TransactionDetailItem
|
|
|
|
key="gas-item"
|
|
|
|
detailTitle={
|
|
|
|
txData.dappSuggestedGasFees ? (
|
|
|
|
<>
|
2021-09-01 20:02:01 +02:00
|
|
|
{t('transactionDetailGasHeading')}
|
2021-07-31 03:29:21 +02:00
|
|
|
<InfoTooltip
|
|
|
|
contentText={t('transactionDetailDappGasTooltip')}
|
|
|
|
position="top"
|
|
|
|
>
|
|
|
|
<i className="fa fa-info-circle" />
|
|
|
|
</InfoTooltip>
|
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
{t('transactionDetailGasHeading')}
|
|
|
|
<InfoTooltip
|
|
|
|
contentText={
|
|
|
|
<>
|
2021-08-14 02:13:21 +02:00
|
|
|
<p>
|
|
|
|
{t('transactionDetailGasTooltipIntro', [
|
|
|
|
isMainnet ? t('networkNameEthereum') : '',
|
|
|
|
])}
|
|
|
|
</p>
|
2021-07-31 03:29:21 +02:00
|
|
|
<p>{t('transactionDetailGasTooltipExplanation')}</p>
|
|
|
|
<p>
|
|
|
|
<a
|
|
|
|
href="https://community.metamask.io/t/what-is-gas-why-do-transactions-take-so-long/3172"
|
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
>
|
|
|
|
{t('transactionDetailGasTooltipConversion')}
|
|
|
|
</a>
|
|
|
|
</p>
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
position="top"
|
|
|
|
>
|
|
|
|
<i className="fa fa-info-circle" />
|
|
|
|
</InfoTooltip>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
2021-09-01 20:02:01 +02:00
|
|
|
detailTitleColor={COLORS.BLACK}
|
2021-07-31 03:29:21 +02:00
|
|
|
detailText={
|
2021-08-17 00:48:24 +02:00
|
|
|
<div className="confirm-page-container-content__currency-container">
|
|
|
|
{renderHeartBeatIfNotInTest()}
|
|
|
|
<UserPreferencedCurrencyDisplay
|
|
|
|
type={SECONDARY}
|
|
|
|
value={hexMinimumTransactionFee}
|
|
|
|
hideLabel={Boolean(useNativeCurrencyAsPrimaryCurrency)}
|
|
|
|
/>
|
|
|
|
</div>
|
2021-07-31 03:29:21 +02:00
|
|
|
}
|
|
|
|
detailTotal={
|
2021-08-17 00:48:24 +02:00
|
|
|
<div className="confirm-page-container-content__currency-container">
|
|
|
|
{renderHeartBeatIfNotInTest()}
|
|
|
|
<UserPreferencedCurrencyDisplay
|
|
|
|
type={PRIMARY}
|
|
|
|
value={hexMinimumTransactionFee}
|
|
|
|
hideLabel={!useNativeCurrencyAsPrimaryCurrency}
|
|
|
|
/>
|
|
|
|
</div>
|
2021-07-31 03:29:21 +02:00
|
|
|
}
|
2021-08-06 03:07:04 +02:00
|
|
|
subText={t('editGasSubTextFee', [
|
|
|
|
<b key="editGasSubTextFeeLabel">
|
|
|
|
{t('editGasSubTextFeeLabel')}
|
|
|
|
</b>,
|
2021-08-17 00:48:24 +02:00
|
|
|
<div
|
|
|
|
key="editGasSubTextFeeValue"
|
|
|
|
className="confirm-page-container-content__currency-container"
|
|
|
|
>
|
|
|
|
{renderHeartBeatIfNotInTest()}
|
|
|
|
<UserPreferencedCurrencyDisplay
|
|
|
|
key="editGasSubTextFeeAmount"
|
|
|
|
type={PRIMARY}
|
|
|
|
value={hexMaximumTransactionFee}
|
|
|
|
hideLabel={!useNativeCurrencyAsPrimaryCurrency}
|
|
|
|
/>
|
|
|
|
</div>,
|
2021-08-06 03:07:04 +02:00
|
|
|
])}
|
2021-07-31 03:29:21 +02:00
|
|
|
subTitle={
|
2021-09-01 20:02:01 +02:00
|
|
|
<>
|
|
|
|
{txData.dappSuggestedGasFees ? (
|
|
|
|
<Typography
|
|
|
|
variant={TYPOGRAPHY.H7}
|
|
|
|
fontStyle={FONT_STYLE.ITALIC}
|
|
|
|
color={COLORS.GRAY}
|
|
|
|
>
|
|
|
|
{t('transactionDetailDappGasMoreInfo')}
|
|
|
|
</Typography>
|
|
|
|
) : (
|
|
|
|
''
|
2021-08-04 15:24:40 +02:00
|
|
|
)}
|
2021-10-06 20:29:57 +02:00
|
|
|
{supportsEIP1559 && (
|
|
|
|
<GasTiming
|
|
|
|
maxPriorityFeePerGas={hexWEIToDecGWEI(
|
|
|
|
maxPriorityFeePerGas ||
|
|
|
|
txData.txParams.maxPriorityFeePerGas,
|
|
|
|
)}
|
|
|
|
maxFeePerGas={hexWEIToDecGWEI(
|
|
|
|
maxFeePerGas || txData.txParams.maxFeePerGas,
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
)}
|
2021-09-01 20:02:01 +02:00
|
|
|
</>
|
2021-07-31 03:29:21 +02:00
|
|
|
}
|
|
|
|
/>,
|
|
|
|
<TransactionDetailItem
|
|
|
|
key="total-item"
|
2021-08-06 03:07:04 +02:00
|
|
|
detailTitle={t('total')}
|
|
|
|
detailText={renderTotalDetailText()}
|
|
|
|
detailTotal={renderTotalDetailTotal()}
|
|
|
|
subTitle={t('transactionDetailGasTotalSubtitle')}
|
|
|
|
subText={t('editGasSubTextAmount', [
|
|
|
|
<b key="editGasSubTextAmountLabel">
|
|
|
|
{t('editGasSubTextAmountLabel')}
|
|
|
|
</b>,
|
|
|
|
renderTotalMaxAmount(),
|
|
|
|
])}
|
2021-07-31 03:29:21 +02:00
|
|
|
/>,
|
|
|
|
]}
|
|
|
|
/>
|
2021-06-30 18:58:18 +02:00
|
|
|
{nonceField}
|
2021-10-21 21:17:03 +02:00
|
|
|
{showLedgerSteps ? (
|
|
|
|
<LedgerInstructionField
|
|
|
|
showDataInstruction={Boolean(txData.txParams?.data)}
|
|
|
|
/>
|
|
|
|
) : null}
|
2021-01-28 18:17:26 +01:00
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-06-23 08:52:45 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderData(functionType) {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { t } = this.context;
|
2018-06-23 08:52:45 +02:00
|
|
|
const {
|
2020-11-03 00:41:28 +01:00
|
|
|
txData: { txParams: { data } = {} } = {},
|
|
|
|
methodData: { params } = {},
|
2018-06-23 08:52:45 +02:00
|
|
|
hideData,
|
|
|
|
dataComponent,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = this.props;
|
2018-06-23 08:52:45 +02:00
|
|
|
|
|
|
|
if (hideData) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return null;
|
2018-06-23 08:52:45 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
return (
|
|
|
|
dataComponent || (
|
|
|
|
<div className="confirm-page-container-content__data">
|
|
|
|
<div className="confirm-page-container-content__data-box-label">
|
|
|
|
{`${t('functionType')}:`}
|
|
|
|
<span className="confirm-page-container-content__function-type">
|
|
|
|
{functionType}
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
{params && (
|
2018-07-14 22:47:07 +02:00
|
|
|
<div className="confirm-page-container-content__data-box">
|
|
|
|
<div className="confirm-page-container-content__data-field-label">
|
2020-11-03 00:41:28 +01:00
|
|
|
{`${t('parameters')}:`}
|
2018-07-14 22:47:07 +02:00
|
|
|
</div>
|
|
|
|
<div>
|
2020-11-03 00:41:28 +01:00
|
|
|
<pre>{JSON.stringify(params, null, 2)}</pre>
|
2018-07-14 22:47:07 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
2020-11-03 00:41:28 +01:00
|
|
|
)}
|
|
|
|
<div className="confirm-page-container-content__data-box-label">
|
2021-04-16 17:05:13 +02:00
|
|
|
{`${t('hexData')}: ${toBuffer(data).length} bytes`}
|
2020-11-03 00:41:28 +01:00
|
|
|
</div>
|
|
|
|
<div className="confirm-page-container-content__data-box">{data}</div>
|
2018-06-23 08:52:45 +02:00
|
|
|
</div>
|
2020-11-03 00:41:28 +01:00
|
|
|
)
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-06-23 08:52:45 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
handleEdit() {
|
|
|
|
const {
|
|
|
|
txData,
|
|
|
|
tokenData,
|
|
|
|
tokenProps,
|
|
|
|
onEdit,
|
|
|
|
actionKey,
|
|
|
|
txData: { origin },
|
|
|
|
methodData = {},
|
2021-02-04 19:15:23 +01:00
|
|
|
} = this.props;
|
2019-03-05 16:45:01 +01:00
|
|
|
|
|
|
|
this.context.metricsEvent({
|
|
|
|
eventOpts: {
|
|
|
|
category: 'Transactions',
|
|
|
|
action: 'Confirm Screen',
|
|
|
|
name: 'Edit Transaction',
|
|
|
|
},
|
|
|
|
customVariables: {
|
|
|
|
recipientKnown: null,
|
2020-11-03 00:41:28 +01:00
|
|
|
functionType:
|
2020-11-07 08:38:12 +01:00
|
|
|
actionKey ||
|
|
|
|
getMethodName(methodData.name) ||
|
2021-03-10 21:16:44 +01:00
|
|
|
TRANSACTION_TYPES.CONTRACT_INTERACTION,
|
2019-03-05 16:45:01 +01:00
|
|
|
origin,
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-03-05 16:45:01 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
onEdit({ txData, tokenData, tokenProps });
|
2018-06-23 08:52:45 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
handleCancelAll() {
|
2018-09-24 07:07:19 +02:00
|
|
|
const {
|
|
|
|
cancelAllTransactions,
|
|
|
|
clearConfirmTransaction,
|
|
|
|
history,
|
2020-06-01 19:54:32 +02:00
|
|
|
mostRecentOverviewPage,
|
2018-09-24 07:07:19 +02:00
|
|
|
showRejectTransactionsConfirmationModal,
|
|
|
|
unapprovedTxCount,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = this.props;
|
2018-09-20 02:48:28 +02:00
|
|
|
|
2018-09-24 07:07:19 +02:00
|
|
|
showRejectTransactionsConfirmationModal({
|
|
|
|
unapprovedTxCount,
|
2019-11-04 19:03:57 +01:00
|
|
|
onSubmit: async () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
this._removeBeforeUnload();
|
|
|
|
await cancelAllTransactions();
|
|
|
|
clearConfirmTransaction();
|
|
|
|
history.push(mostRecentOverviewPage);
|
2018-09-24 07:07:19 +02:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-09-20 02:48:28 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
handleCancel() {
|
2019-09-27 06:30:36 +02:00
|
|
|
const {
|
|
|
|
txData,
|
|
|
|
cancelTransaction,
|
|
|
|
history,
|
2020-06-01 19:54:32 +02:00
|
|
|
mostRecentOverviewPage,
|
2019-09-27 06:30:36 +02:00
|
|
|
clearConfirmTransaction,
|
|
|
|
updateCustomNonce,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = this.props;
|
2018-06-23 08:52:45 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
this._removeBeforeUnload();
|
|
|
|
updateCustomNonce('');
|
2021-01-28 18:17:26 +01:00
|
|
|
cancelTransaction(txData).then(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
clearConfirmTransaction();
|
|
|
|
history.push(mostRecentOverviewPage);
|
|
|
|
});
|
2018-06-23 08:52:45 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
handleSubmit() {
|
2019-09-27 06:30:36 +02:00
|
|
|
const {
|
|
|
|
sendTransaction,
|
|
|
|
clearConfirmTransaction,
|
|
|
|
txData,
|
|
|
|
history,
|
2020-06-01 19:54:32 +02:00
|
|
|
mostRecentOverviewPage,
|
2019-09-27 06:30:36 +02:00
|
|
|
updateCustomNonce,
|
2021-08-06 21:31:30 +02:00
|
|
|
maxFeePerGas,
|
|
|
|
maxPriorityFeePerGas,
|
2021-08-07 00:18:53 +02:00
|
|
|
baseFeePerGas,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = this.props;
|
|
|
|
const { submitting } = this.state;
|
2018-08-03 23:44:57 +02:00
|
|
|
|
|
|
|
if (submitting) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return;
|
2018-08-03 23:44:57 +02:00
|
|
|
}
|
|
|
|
|
2021-08-07 00:18:53 +02:00
|
|
|
if (baseFeePerGas) {
|
|
|
|
txData.estimatedBaseFee = baseFeePerGas;
|
|
|
|
}
|
|
|
|
|
2021-08-06 21:31:30 +02:00
|
|
|
if (maxFeePerGas) {
|
|
|
|
txData.txParams = {
|
|
|
|
...txData.txParams,
|
|
|
|
maxFeePerGas,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (maxPriorityFeePerGas) {
|
|
|
|
txData.txParams = {
|
|
|
|
...txData.txParams,
|
|
|
|
maxPriorityFeePerGas,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
this.setState(
|
|
|
|
{
|
|
|
|
submitting: true,
|
|
|
|
submitError: null,
|
|
|
|
},
|
|
|
|
() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
this._removeBeforeUnload();
|
2019-03-05 16:45:01 +01:00
|
|
|
|
2021-06-25 00:37:44 +02:00
|
|
|
sendTransaction(txData)
|
|
|
|
.then(() => {
|
|
|
|
clearConfirmTransaction();
|
|
|
|
this.setState(
|
|
|
|
{
|
2020-11-03 00:41:28 +01:00
|
|
|
submitting: false,
|
2021-06-25 00:37:44 +02:00
|
|
|
},
|
|
|
|
() => {
|
|
|
|
history.push(mostRecentOverviewPage);
|
|
|
|
updateCustomNonce('');
|
|
|
|
},
|
|
|
|
);
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
this.setState({
|
|
|
|
submitting: false,
|
|
|
|
submitError: error.message,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2021-06-25 00:37:44 +02:00
|
|
|
updateCustomNonce('');
|
|
|
|
});
|
2020-11-03 00:41:28 +01:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-06-23 08:52:45 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderTitleComponent() {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { title, hexTransactionAmount } = this.props;
|
2018-10-17 01:03:29 +02:00
|
|
|
|
|
|
|
// Title string passed in by props takes priority
|
|
|
|
if (title) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return null;
|
2018-10-17 01:03:29 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
return (
|
2021-01-28 18:17:26 +01:00
|
|
|
<UserPreferencedCurrencyDisplay
|
|
|
|
value={hexTransactionAmount}
|
|
|
|
type={PRIMARY}
|
|
|
|
showEthLogo
|
|
|
|
ethLogoHeight="26"
|
|
|
|
hideLabel
|
|
|
|
/>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-10-17 01:03:29 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderSubtitleComponent() {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { subtitleComponent, hexTransactionAmount } = this.props;
|
2018-10-17 01:03:29 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
return (
|
|
|
|
subtitleComponent || (
|
|
|
|
<UserPreferencedCurrencyDisplay
|
|
|
|
value={hexTransactionAmount}
|
|
|
|
type={SECONDARY}
|
|
|
|
showEthLogo
|
|
|
|
hideLabel
|
|
|
|
/>
|
|
|
|
)
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-10-17 01:03:29 +02:00
|
|
|
}
|
2018-11-17 01:54:55 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
handleNextTx(txId) {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { history, clearConfirmTransaction } = this.props;
|
2019-06-18 14:17:14 +02:00
|
|
|
|
2018-11-13 18:19:12 +01:00
|
|
|
if (txId) {
|
2021-02-04 19:15:23 +01:00
|
|
|
clearConfirmTransaction();
|
|
|
|
history.push(`${CONFIRM_TRANSACTION_ROUTE}/${txId}`);
|
2018-11-13 18:19:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
getNavigateTxData() {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { currentNetworkUnapprovedTxs, txData: { id } = {} } = this.props;
|
|
|
|
const enumUnapprovedTxs = Object.keys(currentNetworkUnapprovedTxs);
|
|
|
|
const currentPosition = enumUnapprovedTxs.indexOf(id ? id.toString() : '');
|
2018-11-13 18:19:12 +01:00
|
|
|
|
|
|
|
return {
|
|
|
|
totalTx: enumUnapprovedTxs.length,
|
|
|
|
positionOfCurrentTx: currentPosition + 1,
|
|
|
|
nextTxId: enumUnapprovedTxs[currentPosition + 1],
|
|
|
|
prevTxId: enumUnapprovedTxs[currentPosition - 1],
|
|
|
|
showNavigation: enumUnapprovedTxs.length > 1,
|
|
|
|
firstTx: enumUnapprovedTxs[0],
|
|
|
|
lastTx: enumUnapprovedTxs[enumUnapprovedTxs.length - 1],
|
|
|
|
ofText: this.context.t('ofTextNofM'),
|
|
|
|
requestsWaitingText: this.context.t('requestsAwaitingAcknowledgement'),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-11-13 18:19:12 +01:00
|
|
|
}
|
2018-10-17 01:03:29 +02:00
|
|
|
|
2019-11-04 19:03:57 +01:00
|
|
|
_beforeUnload = () => {
|
2021-06-25 00:37:44 +02:00
|
|
|
const { txData: { id } = {}, cancelTransaction } = this.props;
|
2021-02-04 19:15:23 +01:00
|
|
|
cancelTransaction({ id });
|
|
|
|
};
|
2019-11-04 19:03:57 +01:00
|
|
|
|
2021-08-04 23:53:13 +02:00
|
|
|
_beforeUnloadForGasPolling = () => {
|
|
|
|
this._isMounted = false;
|
|
|
|
if (this.state.pollingToken) {
|
|
|
|
disconnectGasFeeEstimatePoller(this.state.pollingToken);
|
|
|
|
removePollingTokenFromAppState(this.state.pollingToken);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-11-04 19:03:57 +01:00
|
|
|
_removeBeforeUnload = () => {
|
2020-01-24 20:12:58 +01:00
|
|
|
if (getEnvironmentType() === ENVIRONMENT_TYPE_NOTIFICATION) {
|
2021-02-04 19:15:23 +01:00
|
|
|
window.removeEventListener('beforeunload', this._beforeUnload);
|
2019-11-04 19:03:57 +01:00
|
|
|
}
|
2021-08-04 23:53:13 +02:00
|
|
|
window.removeEventListener('beforeunload', this._beforeUnloadForGasPolling);
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-11-04 19:03:57 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
componentDidMount() {
|
2021-07-31 02:45:18 +02:00
|
|
|
this._isMounted = true;
|
2020-11-03 00:41:28 +01:00
|
|
|
const {
|
|
|
|
toAddress,
|
|
|
|
txData: { origin } = {},
|
|
|
|
getNextNonce,
|
|
|
|
tryReverseResolveAddress,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = this.props;
|
|
|
|
const { metricsEvent } = this.context;
|
2019-03-05 16:45:01 +01:00
|
|
|
metricsEvent({
|
|
|
|
eventOpts: {
|
|
|
|
category: 'Transactions',
|
|
|
|
action: 'Confirm Screen',
|
|
|
|
name: 'Confirm: Started',
|
|
|
|
},
|
|
|
|
customVariables: {
|
|
|
|
origin,
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-03-25 17:19:23 +01:00
|
|
|
|
2020-01-24 20:12:58 +01:00
|
|
|
if (getEnvironmentType() === ENVIRONMENT_TYPE_NOTIFICATION) {
|
2021-02-04 19:15:23 +01:00
|
|
|
window.addEventListener('beforeunload', this._beforeUnload);
|
2019-03-25 17:19:23 +01:00
|
|
|
}
|
2019-09-27 06:30:36 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
getNextNonce();
|
2020-03-12 14:50:37 +01:00
|
|
|
if (toAddress) {
|
2021-02-04 19:15:23 +01:00
|
|
|
tryReverseResolveAddress(toAddress);
|
2020-03-12 14:50:37 +01:00
|
|
|
}
|
2021-07-31 02:45:18 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This makes a request to get estimates and begin polling, keeping track of the poll
|
|
|
|
* token in component state.
|
|
|
|
* It then disconnects polling upon componentWillUnmount. If the hook is unmounted
|
|
|
|
* while waiting for `getGasFeeEstimatesAndStartPolling` to resolve, the `_isMounted`
|
|
|
|
* flag ensures that a call to disconnect happens after promise resolution.
|
|
|
|
*/
|
|
|
|
getGasFeeEstimatesAndStartPolling().then((pollingToken) => {
|
|
|
|
if (this._isMounted) {
|
2021-08-04 23:53:13 +02:00
|
|
|
addPollingTokenToAppState(pollingToken);
|
2021-07-31 02:45:18 +02:00
|
|
|
this.setState({ pollingToken });
|
|
|
|
} else {
|
|
|
|
disconnectGasFeeEstimatePoller(pollingToken);
|
2021-08-04 23:53:13 +02:00
|
|
|
removePollingTokenFromAppState(this.state.pollingToken);
|
2021-07-31 02:45:18 +02:00
|
|
|
}
|
|
|
|
});
|
2021-08-04 23:53:13 +02:00
|
|
|
window.addEventListener('beforeunload', this._beforeUnloadForGasPolling);
|
2019-03-05 16:45:01 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
componentWillUnmount() {
|
2021-08-04 23:53:13 +02:00
|
|
|
this._beforeUnloadForGasPolling();
|
2021-02-04 19:15:23 +01:00
|
|
|
this._removeBeforeUnload();
|
2019-10-31 17:27:22 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
render() {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { t } = this.context;
|
2018-06-23 08:52:45 +02:00
|
|
|
const {
|
|
|
|
fromName,
|
|
|
|
fromAddress,
|
|
|
|
toName,
|
|
|
|
toAddress,
|
2019-11-01 18:54:00 +01:00
|
|
|
toEns,
|
2019-08-08 20:45:30 +02:00
|
|
|
toNickname,
|
2018-06-28 20:23:31 +02:00
|
|
|
methodData,
|
2018-06-23 08:52:45 +02:00
|
|
|
title,
|
|
|
|
hideSubtitle,
|
|
|
|
identiconAddress,
|
|
|
|
contentComponent,
|
|
|
|
onEdit,
|
|
|
|
nonce,
|
2019-09-27 06:30:36 +02:00
|
|
|
customNonceValue,
|
2018-09-20 02:48:28 +02:00
|
|
|
unapprovedTxCount,
|
2021-03-10 21:16:44 +01:00
|
|
|
type,
|
2019-11-05 16:13:48 +01:00
|
|
|
hideSenderToRecipient,
|
|
|
|
showAccountInHeader,
|
2021-01-28 18:59:45 +01:00
|
|
|
txData,
|
2021-08-06 01:59:58 +02:00
|
|
|
gasIsLoading,
|
2021-08-17 00:45:55 +02:00
|
|
|
gasFeeIsCustom,
|
2021-09-15 23:54:51 +02:00
|
|
|
nativeCurrency,
|
2021-10-21 21:17:03 +02:00
|
|
|
hardwareWalletRequiresConnection,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = this.props;
|
2021-04-28 20:02:01 +02:00
|
|
|
const {
|
|
|
|
submitting,
|
|
|
|
submitError,
|
|
|
|
submitWarning,
|
|
|
|
ethGasPriceWarning,
|
2021-07-08 22:23:00 +02:00
|
|
|
editingGas,
|
2021-04-28 20:02:01 +02:00
|
|
|
} = this.state;
|
2018-06-23 08:52:45 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const { name } = methodData;
|
|
|
|
const { valid, errorKey } = this.getErrorKey();
|
2020-11-03 00:41:28 +01:00
|
|
|
const {
|
|
|
|
totalTx,
|
|
|
|
positionOfCurrentTx,
|
|
|
|
nextTxId,
|
|
|
|
prevTxId,
|
|
|
|
showNavigation,
|
|
|
|
firstTx,
|
|
|
|
lastTx,
|
|
|
|
ofText,
|
|
|
|
requestsWaitingText,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = this.getNavigateTxData();
|
2020-03-19 05:03:20 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
let functionType = getMethodName(name);
|
2020-03-19 05:03:20 +01:00
|
|
|
if (!functionType) {
|
2021-03-10 21:16:44 +01:00
|
|
|
if (type) {
|
2021-09-15 23:54:51 +02:00
|
|
|
functionType = getTransactionTypeTitle(t, type, nativeCurrency);
|
2020-03-23 15:54:57 +01:00
|
|
|
} else {
|
2021-02-04 19:15:23 +01:00
|
|
|
functionType = t('contractInteraction');
|
2020-03-23 15:54:57 +01:00
|
|
|
}
|
2020-03-19 05:03:20 +01:00
|
|
|
}
|
2018-06-23 08:52:45 +02:00
|
|
|
return (
|
|
|
|
<ConfirmPageContainer
|
|
|
|
fromName={fromName}
|
|
|
|
fromAddress={fromAddress}
|
2019-11-05 16:13:48 +01:00
|
|
|
showAccountInHeader={showAccountInHeader}
|
2018-06-23 08:52:45 +02:00
|
|
|
toName={toName}
|
|
|
|
toAddress={toAddress}
|
2019-11-01 18:54:00 +01:00
|
|
|
toEns={toEns}
|
2019-08-08 20:45:30 +02:00
|
|
|
toNickname={toNickname}
|
2021-07-12 19:13:09 +02:00
|
|
|
showEdit={Boolean(onEdit)}
|
2020-03-19 05:03:20 +01:00
|
|
|
action={functionType}
|
2018-10-17 01:03:29 +02:00
|
|
|
title={title}
|
|
|
|
titleComponent={this.renderTitleComponent()}
|
|
|
|
subtitleComponent={this.renderSubtitleComponent()}
|
2018-06-23 08:52:45 +02:00
|
|
|
hideSubtitle={hideSubtitle}
|
|
|
|
detailsComponent={this.renderDetails()}
|
2020-03-19 05:03:20 +01:00
|
|
|
dataComponent={this.renderData(functionType)}
|
2018-06-23 08:52:45 +02:00
|
|
|
contentComponent={contentComponent}
|
2019-09-27 06:30:36 +02:00
|
|
|
nonce={customNonceValue || nonce}
|
2018-09-20 02:48:28 +02:00
|
|
|
unapprovedTxCount={unapprovedTxCount}
|
2018-06-23 08:52:45 +02:00
|
|
|
identiconAddress={identiconAddress}
|
2021-01-28 18:17:26 +01:00
|
|
|
errorMessage={submitError}
|
|
|
|
errorKey={errorKey}
|
|
|
|
warning={submitWarning}
|
2018-11-13 18:19:12 +01:00
|
|
|
totalTx={totalTx}
|
|
|
|
positionOfCurrentTx={positionOfCurrentTx}
|
|
|
|
nextTxId={nextTxId}
|
|
|
|
prevTxId={prevTxId}
|
|
|
|
showNavigation={showNavigation}
|
|
|
|
onNextTx={(txId) => this.handleNextTx(txId)}
|
|
|
|
firstTx={firstTx}
|
|
|
|
lastTx={lastTx}
|
|
|
|
ofText={ofText}
|
|
|
|
requestsWaitingText={requestsWaitingText}
|
2021-10-21 21:17:03 +02:00
|
|
|
disabled={
|
|
|
|
!valid ||
|
|
|
|
submitting ||
|
|
|
|
hardwareWalletRequiresConnection ||
|
|
|
|
(gasIsLoading && !gasFeeIsCustom)
|
|
|
|
}
|
2018-06-23 08:52:45 +02:00
|
|
|
onEdit={() => this.handleEdit()}
|
2018-09-20 02:48:28 +02:00
|
|
|
onCancelAll={() => this.handleCancelAll()}
|
2018-06-23 08:52:45 +02:00
|
|
|
onCancel={() => this.handleCancel()}
|
|
|
|
onSubmit={() => this.handleSubmit()}
|
2019-11-05 16:13:48 +01:00
|
|
|
hideSenderToRecipient={hideSenderToRecipient}
|
2021-01-28 18:59:45 +01:00
|
|
|
origin={txData.origin}
|
2021-04-28 20:02:01 +02:00
|
|
|
ethGasPriceWarning={ethGasPriceWarning}
|
2021-07-08 22:23:00 +02:00
|
|
|
editingGas={editingGas}
|
2021-07-31 03:29:21 +02:00
|
|
|
handleCloseEditGas={() => this.handleCloseEditGas()}
|
2021-07-12 21:35:54 +02:00
|
|
|
currentTransaction={txData}
|
2018-06-23 08:52:45 +02:00
|
|
|
/>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-06-23 08:52:45 +02:00
|
|
|
}
|
|
|
|
}
|
2019-02-19 06:36:12 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getMethodName(camelCase) {
|
2019-02-19 06:36:12 +01:00
|
|
|
if (!camelCase || typeof camelCase !== 'string') {
|
2021-02-04 19:15:23 +01:00
|
|
|
return '';
|
2019-02-19 06:36:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return camelCase
|
2020-11-03 00:41:28 +01:00
|
|
|
.replace(/([a-z])([A-Z])/gu, '$1 $2')
|
|
|
|
.replace(/([A-Z])([a-z])/gu, ' $1$2')
|
2021-02-04 19:15:23 +01:00
|
|
|
.replace(/ +/gu, ' ');
|
2019-02-19 06:36:12 +01:00
|
|
|
}
|