2018-11-21 19:51:34 +01:00
|
|
|
import ethUtil from 'ethereumjs-util'
|
2018-06-23 08:52:45 +02:00
|
|
|
import React, { Component } from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
2019-03-25 17:19:23 +01:00
|
|
|
import { ENVIRONMENT_TYPE_NOTIFICATION } from '../../../../app/scripts/lib/enums'
|
|
|
|
import { getEnvironmentType } from '../../../../app/scripts/lib/util'
|
2019-03-22 00:03:30 +01:00
|
|
|
import ConfirmPageContainer, { ConfirmDetailRow } from '../../components/app/confirm-page-container'
|
2019-04-17 21:15:13 +02:00
|
|
|
import { isBalanceSufficient } from '../send/send.utils'
|
2020-06-01 19:54:32 +02:00
|
|
|
import { CONFIRM_TRANSACTION_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,
|
2019-03-22 00:03:30 +01:00
|
|
|
} from '../../helpers/constants/error-keys'
|
|
|
|
import { CONFIRMED_STATUS, DROPPED_STATUS } from '../../helpers/constants/transactions'
|
|
|
|
import UserPreferencedCurrencyDisplay from '../../components/app/user-preferenced-currency-display'
|
|
|
|
import { PRIMARY, SECONDARY } from '../../helpers/constants/common'
|
Use `AdvancedGasInputs` in `AdvancedTabContent` (#7186)
* Use `AdvancedGasInputs` in `AdvancedTabContent`
The `AdvancedGasInputs` component was originally extracted from the
`AdvancedTabContent` component, duplicating much of the rendering
logic. They have since evolved separately, with bugs being fixed in one
place but not the other.
The inputs and outputs expected weren't exactly the same, as the
`AdvancedGasInputs` component converts the input custom gas price and
limit, and it converts them both in the setter methods as well.
The `GasModalPageContainer` had to be adjusted to avoid converting
these values multiple times.
Both components dealt with input debouncing separately, both in less
than ideal ways. `AdvancedTabContent` didn't debounce either field, but
it did debounce the check for whether the gas limit field was below the
minimum value. So if a less-than-minimum value was set, it would be
propogated upwards and could be saved if the user clicked 'Save'
quickly enough. After a second delay it would snap back to the minimum
value. The `AdvancedGasInputs` component debounced both fields, but
it would replace any gas limit below the minimum with the minimum
value. This led to a problem where a brief pause during typing would
reset the field to 21000.
The `AdvancedGasInputs` approach was chosen, except that it was
updated to no longer change the gas limit if it was below the minimum.
Instead it displays an error. Parent components were checked to ensure
they would detect the error case of the gas limit being set too low,
and prevent the form submission in those cases. Of the three parents,
one had already dealt with it correctly, one needed to convert the
gas limit from hex first, and another needed the gas limit check added.
Closes #6872
* Cleanup send components
Empty README files have been removed, and a mistake in the index file
for the send page has been corrected. The Gas Slider component class
name was updated as well; it looks like it was originally created from
`AdvancedTabContent`, so it still had that class name.
2019-10-23 14:23:15 +02:00
|
|
|
import { hexToDecimal } from '../../helpers/utils/conversions.util'
|
2019-03-22 00:03:30 +01:00
|
|
|
import AdvancedGasInputs from '../../components/app/gas-customization/advanced-gas-inputs'
|
2019-09-27 06:30:36 +02:00
|
|
|
import TextField from '../../components/ui/text-field'
|
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,
|
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,
|
|
|
|
hexTransactionFee: PropTypes.string,
|
|
|
|
hexTransactionTotal: PropTypes.string,
|
2018-07-06 20:58:41 +02:00
|
|
|
isTxReprice: PropTypes.bool,
|
|
|
|
methodData: PropTypes.object,
|
|
|
|
nonce: PropTypes.string,
|
2019-09-27 06:30:36 +02:00
|
|
|
useNonceField: PropTypes.bool,
|
|
|
|
customNonceValue: PropTypes.string,
|
|
|
|
updateCustomNonce: PropTypes.func,
|
2018-08-30 04:13:25 +02:00
|
|
|
assetImage: PropTypes.string,
|
2018-06-23 08:52:45 +02:00
|
|
|
sendTransaction: PropTypes.func,
|
|
|
|
showCustomizeGasModal: 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
|
|
|
updateGasAndCalculate: PropTypes.func,
|
|
|
|
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,
|
|
|
|
detailsComponent: PropTypes.node,
|
|
|
|
errorKey: PropTypes.string,
|
2018-06-23 08:52:45 +02:00
|
|
|
errorMessage: PropTypes.string,
|
2018-10-17 01:03:29 +02:00
|
|
|
primaryTotalTextOverride: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
|
|
|
|
secondaryTotalTextOverride: PropTypes.string,
|
2018-07-06 20:58:41 +02:00
|
|
|
hideData: PropTypes.bool,
|
|
|
|
hideDetails: PropTypes.bool,
|
|
|
|
hideSubtitle: PropTypes.bool,
|
2018-06-23 08:52:45 +02:00
|
|
|
identiconAddress: PropTypes.string,
|
2018-07-06 20:58:41 +02:00
|
|
|
onCancel: PropTypes.func,
|
2018-06-23 08:52:45 +02:00
|
|
|
onEdit: PropTypes.func,
|
|
|
|
onEditGas: PropTypes.func,
|
|
|
|
onSubmit: PropTypes.func,
|
2019-03-05 16:45:01 +01:00
|
|
|
setMetaMetricsSendCount: PropTypes.func,
|
|
|
|
metaMetricsSendCount: PropTypes.number,
|
2018-07-06 20:58:41 +02:00
|
|
|
subtitle: PropTypes.string,
|
2018-10-17 01:03:29 +02:00
|
|
|
subtitleComponent: PropTypes.node,
|
2018-07-06 20:58:41 +02:00
|
|
|
summaryComponent: PropTypes.node,
|
|
|
|
title: PropTypes.string,
|
2018-10-17 01:03:29 +02:00
|
|
|
titleComponent: PropTypes.node,
|
2018-07-06 20:58:41 +02:00
|
|
|
valid: PropTypes.bool,
|
|
|
|
warning: PropTypes.string,
|
2019-02-06 01:24:28 +01:00
|
|
|
advancedInlineGasShown: PropTypes.bool,
|
|
|
|
insufficientBalance: PropTypes.bool,
|
2019-02-26 19:30:41 +01:00
|
|
|
hideFiatConversion: PropTypes.bool,
|
2019-06-18 14:17:14 +02:00
|
|
|
transactionCategory: 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,
|
2020-08-19 16:03:15 +02:00
|
|
|
isMainnet: PropTypes.bool,
|
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: '',
|
2018-08-03 23:44:57 +02:00
|
|
|
}
|
|
|
|
|
2019-04-27 11:29:55 +02:00
|
|
|
componentDidUpdate (prevProps) {
|
2018-06-23 08:52:45 +02:00
|
|
|
const {
|
|
|
|
transactionStatus,
|
|
|
|
showTransactionConfirmedModal,
|
|
|
|
history,
|
|
|
|
clearConfirmTransaction,
|
2020-06-01 19:54:32 +02:00
|
|
|
mostRecentOverviewPage,
|
2019-09-27 06:30:36 +02:00
|
|
|
nextNonce,
|
|
|
|
customNonceValue,
|
2020-03-12 14:50:37 +01:00
|
|
|
toAddress,
|
|
|
|
tryReverseResolveAddress,
|
2018-06-23 08:52:45 +02:00
|
|
|
} = this.props
|
2020-03-12 14:50:37 +01:00
|
|
|
const {
|
|
|
|
customNonceValue: prevCustomNonceValue,
|
|
|
|
nextNonce: prevNextNonce,
|
|
|
|
toAddress: prevToAddress,
|
|
|
|
transactionStatus: prevTxStatus,
|
|
|
|
} = prevProps
|
2019-04-27 11:29:55 +02:00
|
|
|
const statusUpdated = transactionStatus !== prevTxStatus
|
|
|
|
const txDroppedOrConfirmed = transactionStatus === DROPPED_STATUS || transactionStatus === CONFIRMED_STATUS
|
2018-06-23 08:52:45 +02:00
|
|
|
|
2020-03-12 14:50:37 +01:00
|
|
|
if (nextNonce !== prevNextNonce || customNonceValue !== prevCustomNonceValue) {
|
2019-09-27 06:30:36 +02:00
|
|
|
if (customNonceValue > nextNonce) {
|
|
|
|
this.setState({ submitWarning: this.context.t('nextNonceWarning', [nextNonce]) })
|
|
|
|
} else {
|
|
|
|
this.setState({ submitWarning: '' })
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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: () => {
|
2018-06-23 08:52:45 +02:00
|
|
|
clearConfirmTransaction()
|
2020-06-01 19:54:32 +02:00
|
|
|
history.push(mostRecentOverviewPage)
|
2018-06-23 08:52:45 +02: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) {
|
|
|
|
tryReverseResolveAddress(toAddress)
|
2018-06-23 08:52:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-06 20:58:41 +02:00
|
|
|
getErrorKey () {
|
2018-06-23 08:52:45 +02:00
|
|
|
const {
|
|
|
|
balance,
|
|
|
|
conversionRate,
|
2018-10-17 01:03:29 +02:00
|
|
|
hexTransactionFee,
|
2018-06-23 08:52:45 +02:00
|
|
|
txData: {
|
|
|
|
simulationFails,
|
|
|
|
txParams: {
|
|
|
|
value: amount,
|
|
|
|
} = {},
|
|
|
|
} = {},
|
2019-05-23 15:56:40 +02:00
|
|
|
customGas,
|
2018-06-23 08:52:45 +02:00
|
|
|
} = this.props
|
|
|
|
|
|
|
|
const insufficientBalance = balance && !isBalanceSufficient({
|
|
|
|
amount,
|
2018-10-17 01:03:29 +02:00
|
|
|
gasTotal: hexTransactionFee || '0x0',
|
2018-06-23 08:52:45 +02:00
|
|
|
balance,
|
|
|
|
conversionRate,
|
|
|
|
})
|
|
|
|
|
|
|
|
if (insufficientBalance) {
|
|
|
|
return {
|
|
|
|
valid: false,
|
2018-07-06 20:58:41 +02:00
|
|
|
errorKey: INSUFFICIENT_FUNDS_ERROR_KEY,
|
2018-06-23 08:52:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Use `AdvancedGasInputs` in `AdvancedTabContent` (#7186)
* Use `AdvancedGasInputs` in `AdvancedTabContent`
The `AdvancedGasInputs` component was originally extracted from the
`AdvancedTabContent` component, duplicating much of the rendering
logic. They have since evolved separately, with bugs being fixed in one
place but not the other.
The inputs and outputs expected weren't exactly the same, as the
`AdvancedGasInputs` component converts the input custom gas price and
limit, and it converts them both in the setter methods as well.
The `GasModalPageContainer` had to be adjusted to avoid converting
these values multiple times.
Both components dealt with input debouncing separately, both in less
than ideal ways. `AdvancedTabContent` didn't debounce either field, but
it did debounce the check for whether the gas limit field was below the
minimum value. So if a less-than-minimum value was set, it would be
propogated upwards and could be saved if the user clicked 'Save'
quickly enough. After a second delay it would snap back to the minimum
value. The `AdvancedGasInputs` component debounced both fields, but
it would replace any gas limit below the minimum with the minimum
value. This led to a problem where a brief pause during typing would
reset the field to 21000.
The `AdvancedGasInputs` approach was chosen, except that it was
updated to no longer change the gas limit if it was below the minimum.
Instead it displays an error. Parent components were checked to ensure
they would detect the error case of the gas limit being set too low,
and prevent the form submission in those cases. Of the three parents,
one had already dealt with it correctly, one needed to convert the
gas limit from hex first, and another needed the gas limit check added.
Closes #6872
* Cleanup send components
Empty README files have been removed, and a mistake in the index file
for the send page has been corrected. The Gas Slider component class
name was updated as well; it looks like it was originally created from
`AdvancedTabContent`, so it still had that class name.
2019-10-23 14:23:15 +02:00
|
|
|
if (hexToDecimal(customGas.gasLimit) < 21000) {
|
2019-05-23 15:56:40 +02:00
|
|
|
return {
|
|
|
|
valid: false,
|
|
|
|
errorKey: GAS_LIMIT_TOO_LOW_ERROR_KEY,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-23 08:52:45 +02:00
|
|
|
if (simulationFails) {
|
|
|
|
return {
|
2018-08-09 01:55:25 +02:00
|
|
|
valid: true,
|
2018-09-18 05:04:10 +02:00
|
|
|
errorKey: simulationFails.errorKey ? simulationFails.errorKey : TRANSACTION_ERROR_KEY,
|
2018-06-23 08:52:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
valid: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handleEditGas () {
|
2019-04-08 16:02:51 +02:00
|
|
|
const { onEditGas, showCustomizeGasModal, actionKey, txData: { origin }, methodData = {} } = 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,
|
2019-04-08 16:02:51 +02:00
|
|
|
functionType: actionKey || getMethodName(methodData.name) || 'contractInteraction',
|
2019-03-05 16:45:01 +01:00
|
|
|
origin,
|
|
|
|
},
|
|
|
|
})
|
2018-06-23 08:52:45 +02:00
|
|
|
|
|
|
|
if (onEditGas) {
|
|
|
|
onEditGas()
|
|
|
|
} else {
|
2018-07-06 20:58:41 +02:00
|
|
|
showCustomizeGasModal()
|
2018-06-23 08:52:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
renderDetails () {
|
|
|
|
const {
|
|
|
|
detailsComponent,
|
2018-10-17 01:03:29 +02:00
|
|
|
primaryTotalTextOverride,
|
|
|
|
secondaryTotalTextOverride,
|
|
|
|
hexTransactionFee,
|
|
|
|
hexTransactionTotal,
|
2018-06-23 08:52:45 +02:00
|
|
|
hideDetails,
|
2019-09-27 06:30:36 +02:00
|
|
|
useNonceField,
|
|
|
|
customNonceValue,
|
|
|
|
updateCustomNonce,
|
2019-02-06 01:24:28 +01:00
|
|
|
advancedInlineGasShown,
|
2019-02-08 14:50:25 +01:00
|
|
|
customGas,
|
2019-02-06 01:24:28 +01:00
|
|
|
insufficientBalance,
|
2019-02-08 14:50:25 +01:00
|
|
|
updateGasAndCalculate,
|
2019-02-26 19:30:41 +01:00
|
|
|
hideFiatConversion,
|
2019-09-27 06:30:36 +02:00
|
|
|
nextNonce,
|
|
|
|
getNextNonce,
|
2020-08-19 16:03:15 +02:00
|
|
|
isMainnet,
|
2018-06-23 08:52:45 +02:00
|
|
|
} = this.props
|
|
|
|
|
|
|
|
if (hideDetails) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
2020-08-19 16:03:15 +02:00
|
|
|
const notMainnetOrTest = !(isMainnet || process.env.IN_TEST)
|
|
|
|
|
2018-06-23 08:52:45 +02:00
|
|
|
return (
|
|
|
|
detailsComponent || (
|
|
|
|
<div className="confirm-page-container-content__details">
|
|
|
|
<div className="confirm-page-container-content__gas-fee">
|
|
|
|
<ConfirmDetailRow
|
|
|
|
label="Gas Fee"
|
2018-10-17 01:03:29 +02:00
|
|
|
value={hexTransactionFee}
|
2020-08-19 16:03:15 +02:00
|
|
|
headerText={notMainnetOrTest ? '' : 'Edit'}
|
|
|
|
headerTextClassName={notMainnetOrTest ? '' : 'confirm-detail-row__header-text--edit'}
|
|
|
|
onHeaderClick={notMainnetOrTest ? null : () => this.handleEditGas()}
|
2019-02-26 19:30:41 +01:00
|
|
|
secondaryText={hideFiatConversion ? this.context.t('noConversionRateAvailable') : ''}
|
2018-06-23 08:52:45 +02:00
|
|
|
/>
|
2020-08-19 16:03:15 +02:00
|
|
|
{advancedInlineGasShown || notMainnetOrTest
|
2019-12-03 17:35:44 +01:00
|
|
|
? (
|
|
|
|
<AdvancedGasInputs
|
2020-02-15 21:34:12 +01:00
|
|
|
updateCustomGasPrice={(newGasPrice) => updateGasAndCalculate({ ...customGas, gasPrice: newGasPrice })}
|
|
|
|
updateCustomGasLimit={(newGasLimit) => updateGasAndCalculate({ ...customGas, gasLimit: newGasLimit })}
|
2019-12-03 17:35:44 +01:00
|
|
|
customGasPrice={customGas.gasPrice}
|
|
|
|
customGasLimit={customGas.gasLimit}
|
|
|
|
insufficientBalance={insufficientBalance}
|
|
|
|
customPriceIsSafe
|
|
|
|
isSpeedUp={false}
|
|
|
|
/>
|
|
|
|
)
|
2019-02-06 01:24:28 +01:00
|
|
|
: null
|
|
|
|
}
|
2018-06-23 08:52:45 +02:00
|
|
|
</div>
|
2019-09-27 06:30:36 +02:00
|
|
|
<div className={useNonceField ? 'confirm-page-container-content__gas-fee' : null}>
|
2018-06-23 08:52:45 +02:00
|
|
|
<ConfirmDetailRow
|
|
|
|
label="Total"
|
2018-10-17 01:03:29 +02:00
|
|
|
value={hexTransactionTotal}
|
|
|
|
primaryText={primaryTotalTextOverride}
|
2019-02-26 19:30:41 +01:00
|
|
|
secondaryText={hideFiatConversion ? this.context.t('noConversionRateAvailable') : secondaryTotalTextOverride}
|
2018-06-23 08:52:45 +02:00
|
|
|
headerText="Amount + Gas Fee"
|
|
|
|
headerTextClassName="confirm-detail-row__header-text--total"
|
2018-10-17 01:03:29 +02:00
|
|
|
primaryValueTextColor="#2f9ae0"
|
2018-06-23 08:52:45 +02:00
|
|
|
/>
|
|
|
|
</div>
|
2019-12-03 17:35:44 +01:00
|
|
|
{useNonceField ? (
|
|
|
|
<div>
|
|
|
|
<div className="confirm-detail-row">
|
|
|
|
<div className="confirm-detail-row__label">
|
|
|
|
{ this.context.t('nonceFieldHeading') }
|
|
|
|
</div>
|
|
|
|
<div className="custom-nonce-input">
|
|
|
|
<TextField
|
|
|
|
type="number"
|
|
|
|
min="0"
|
2020-05-19 01:48:38 +02:00
|
|
|
placeholder={ typeof nextNonce === 'number' ? nextNonce.toString() : null }
|
2019-12-03 17:35:44 +01:00
|
|
|
onChange={({ target: { value } }) => {
|
|
|
|
if (!value.length || Number(value) < 0) {
|
|
|
|
updateCustomNonce('')
|
|
|
|
} else {
|
|
|
|
updateCustomNonce(String(Math.floor(value)))
|
|
|
|
}
|
|
|
|
getNextNonce()
|
|
|
|
}}
|
|
|
|
fullWidth
|
|
|
|
margin="dense"
|
|
|
|
value={ customNonceValue || '' }
|
|
|
|
/>
|
|
|
|
</div>
|
2019-09-27 06:30:36 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
2019-12-03 17:35:44 +01:00
|
|
|
) : null}
|
2018-06-23 08:52:45 +02:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-03-19 05:03:20 +01:00
|
|
|
renderData (functionType) {
|
2018-06-23 08:52:45 +02:00
|
|
|
const { t } = this.context
|
|
|
|
const {
|
|
|
|
txData: {
|
|
|
|
txParams: {
|
|
|
|
data,
|
|
|
|
} = {},
|
|
|
|
} = {},
|
2018-06-28 20:23:31 +02:00
|
|
|
methodData: {
|
2018-06-23 08:52:45 +02:00
|
|
|
params,
|
|
|
|
} = {},
|
|
|
|
hideData,
|
|
|
|
dataComponent,
|
|
|
|
} = this.props
|
|
|
|
|
|
|
|
if (hideData) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
|
|
|
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">
|
2020-03-19 05:03:20 +01:00
|
|
|
{ functionType }
|
2018-06-23 08:52:45 +02:00
|
|
|
</span>
|
|
|
|
</div>
|
2018-07-14 22:47:07 +02:00
|
|
|
{
|
|
|
|
params && (
|
|
|
|
<div className="confirm-page-container-content__data-box">
|
|
|
|
<div className="confirm-page-container-content__data-field-label">
|
|
|
|
{ `${t('parameters')}:` }
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<pre>{ JSON.stringify(params, null, 2) }</pre>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
2018-06-23 08:52:45 +02:00
|
|
|
<div className="confirm-page-container-content__data-box-label">
|
2018-11-21 19:51:34 +01:00
|
|
|
{`${t('hexData')}: ${ethUtil.toBuffer(data).length} bytes`}
|
2018-06-23 08:52:45 +02:00
|
|
|
</div>
|
|
|
|
<div className="confirm-page-container-content__data-box">
|
|
|
|
{ data }
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
handleEdit () {
|
2019-04-08 16:02:51 +02:00
|
|
|
const { txData, tokenData, tokenProps, onEdit, actionKey, txData: { origin }, methodData = {} } = 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,
|
2019-04-08 16:02:51 +02:00
|
|
|
functionType: actionKey || getMethodName(methodData.name) || 'contractInteraction',
|
2019-03-05 16:45:01 +01:00
|
|
|
origin,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-06-23 08:52:45 +02:00
|
|
|
onEdit({ txData, tokenData, tokenProps })
|
|
|
|
}
|
|
|
|
|
2018-09-20 02:48:28 +02: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,
|
|
|
|
} = 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 () => {
|
|
|
|
this._removeBeforeUnload()
|
2018-09-24 07:07:19 +02:00
|
|
|
await cancelAllTransactions()
|
2018-09-20 02:48:28 +02:00
|
|
|
clearConfirmTransaction()
|
2020-06-01 19:54:32 +02:00
|
|
|
history.push(mostRecentOverviewPage)
|
2018-09-24 07:07:19 +02:00
|
|
|
},
|
|
|
|
})
|
2018-09-20 02:48:28 +02:00
|
|
|
}
|
|
|
|
|
2018-06-23 08:52:45 +02:00
|
|
|
handleCancel () {
|
2019-03-05 16:45:01 +01:00
|
|
|
const { metricsEvent } = this.context
|
2019-09-27 06:30:36 +02:00
|
|
|
const {
|
|
|
|
onCancel,
|
|
|
|
txData,
|
|
|
|
cancelTransaction,
|
|
|
|
history,
|
2020-06-01 19:54:32 +02:00
|
|
|
mostRecentOverviewPage,
|
2019-09-27 06:30:36 +02:00
|
|
|
clearConfirmTransaction,
|
|
|
|
actionKey,
|
|
|
|
txData: { origin },
|
|
|
|
methodData = {},
|
|
|
|
updateCustomNonce,
|
|
|
|
} = this.props
|
2018-06-23 08:52:45 +02:00
|
|
|
|
2019-11-04 19:03:57 +01:00
|
|
|
this._removeBeforeUnload()
|
2019-09-24 23:08:38 +02:00
|
|
|
metricsEvent({
|
|
|
|
eventOpts: {
|
|
|
|
category: 'Transactions',
|
|
|
|
action: 'Confirm Screen',
|
|
|
|
name: 'Cancel',
|
|
|
|
},
|
|
|
|
customVariables: {
|
|
|
|
recipientKnown: null,
|
|
|
|
functionType: actionKey || getMethodName(methodData.name) || 'contractInteraction',
|
|
|
|
origin,
|
|
|
|
},
|
|
|
|
})
|
2019-09-27 06:30:36 +02:00
|
|
|
updateCustomNonce('')
|
2018-06-23 08:52:45 +02:00
|
|
|
if (onCancel) {
|
|
|
|
onCancel(txData)
|
|
|
|
} else {
|
|
|
|
cancelTransaction(txData)
|
|
|
|
.then(() => {
|
|
|
|
clearConfirmTransaction()
|
2020-06-01 19:54:32 +02:00
|
|
|
history.push(mostRecentOverviewPage)
|
2018-06-23 08:52:45 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handleSubmit () {
|
2019-03-05 16:45:01 +01:00
|
|
|
const { metricsEvent } = this.context
|
2019-09-27 06:30:36 +02:00
|
|
|
const {
|
|
|
|
txData: { origin },
|
|
|
|
sendTransaction,
|
|
|
|
clearConfirmTransaction,
|
|
|
|
txData,
|
|
|
|
history,
|
|
|
|
onSubmit,
|
|
|
|
actionKey,
|
2020-06-01 19:54:32 +02:00
|
|
|
mostRecentOverviewPage,
|
2019-09-27 06:30:36 +02:00
|
|
|
metaMetricsSendCount = 0,
|
|
|
|
setMetaMetricsSendCount,
|
|
|
|
methodData = {},
|
|
|
|
updateCustomNonce,
|
|
|
|
} = this.props
|
2018-08-03 23:44:57 +02:00
|
|
|
const { submitting } = this.state
|
|
|
|
|
|
|
|
if (submitting) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-11-21 19:52:18 +01:00
|
|
|
this.setState({
|
|
|
|
submitting: true,
|
|
|
|
submitError: null,
|
|
|
|
}, () => {
|
2019-11-04 19:03:57 +01:00
|
|
|
this._removeBeforeUnload()
|
2019-03-05 16:45:01 +01:00
|
|
|
metricsEvent({
|
|
|
|
eventOpts: {
|
|
|
|
category: 'Transactions',
|
|
|
|
action: 'Confirm Screen',
|
|
|
|
name: 'Transaction Completed',
|
|
|
|
},
|
|
|
|
customVariables: {
|
|
|
|
recipientKnown: null,
|
2019-04-08 16:02:51 +02:00
|
|
|
functionType: actionKey || getMethodName(methodData.name) || 'contractInteraction',
|
2019-03-05 16:45:01 +01:00
|
|
|
origin,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
setMetaMetricsSendCount(metaMetricsSendCount + 1)
|
|
|
|
.then(() => {
|
|
|
|
if (onSubmit) {
|
|
|
|
Promise.resolve(onSubmit(txData))
|
|
|
|
.then(() => {
|
|
|
|
this.setState({
|
|
|
|
submitting: false,
|
|
|
|
})
|
2019-09-27 06:30:36 +02:00
|
|
|
updateCustomNonce('')
|
2019-03-05 16:45:01 +01:00
|
|
|
})
|
|
|
|
} else {
|
|
|
|
sendTransaction(txData)
|
|
|
|
.then(() => {
|
|
|
|
clearConfirmTransaction()
|
|
|
|
this.setState({
|
|
|
|
submitting: false,
|
|
|
|
}, () => {
|
2020-06-01 19:54:32 +02:00
|
|
|
history.push(mostRecentOverviewPage)
|
2019-09-27 06:30:36 +02:00
|
|
|
updateCustomNonce('')
|
2019-03-05 16:45:01 +01:00
|
|
|
})
|
|
|
|
})
|
2020-02-15 21:34:12 +01:00
|
|
|
.catch((error) => {
|
2019-03-05 16:45:01 +01:00
|
|
|
this.setState({
|
|
|
|
submitting: false,
|
|
|
|
submitError: error.message,
|
|
|
|
})
|
2019-10-02 20:12:04 +02:00
|
|
|
updateCustomNonce('')
|
2019-03-05 16:45:01 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
2018-11-21 19:52:18 +01:00
|
|
|
})
|
2018-06-23 08:52:45 +02:00
|
|
|
}
|
|
|
|
|
2018-10-17 01:03:29 +02:00
|
|
|
renderTitleComponent () {
|
|
|
|
const { title, titleComponent, hexTransactionAmount } = this.props
|
|
|
|
|
|
|
|
// Title string passed in by props takes priority
|
|
|
|
if (title) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
|
|
|
return titleComponent || (
|
|
|
|
<UserPreferencedCurrencyDisplay
|
|
|
|
value={hexTransactionAmount}
|
|
|
|
type={PRIMARY}
|
|
|
|
showEthLogo
|
|
|
|
ethLogoHeight="26"
|
|
|
|
hideLabel
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
renderSubtitleComponent () {
|
|
|
|
const { subtitle, subtitleComponent, hexTransactionAmount } = this.props
|
|
|
|
|
|
|
|
// Subtitle string passed in by props takes priority
|
|
|
|
if (subtitle) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
|
|
|
return subtitleComponent || (
|
|
|
|
<UserPreferencedCurrencyDisplay
|
|
|
|
value={hexTransactionAmount}
|
|
|
|
type={SECONDARY}
|
|
|
|
showEthLogo
|
|
|
|
hideLabel
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
2018-11-17 01:54:55 +01:00
|
|
|
|
2018-11-13 18:19:12 +01:00
|
|
|
handleNextTx (txId) {
|
|
|
|
const { history, clearConfirmTransaction } = this.props
|
2019-06-18 14:17:14 +02:00
|
|
|
|
2018-11-13 18:19:12 +01:00
|
|
|
if (txId) {
|
|
|
|
clearConfirmTransaction()
|
|
|
|
history.push(`${CONFIRM_TRANSACTION_ROUTE}/${txId}`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
getNavigateTxData () {
|
|
|
|
const { currentNetworkUnapprovedTxs, txData: { id } = {} } = this.props
|
2020-01-10 15:34:02 +01:00
|
|
|
const enumUnapprovedTxs = Object.keys(currentNetworkUnapprovedTxs)
|
2019-06-18 14:17:14 +02:00
|
|
|
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'),
|
|
|
|
}
|
|
|
|
}
|
2018-10-17 01:03:29 +02:00
|
|
|
|
2019-11-04 19:03:57 +01:00
|
|
|
_beforeUnload = () => {
|
|
|
|
const { txData: { origin, id } = {}, cancelTransaction } = this.props
|
|
|
|
const { metricsEvent } = this.context
|
|
|
|
metricsEvent({
|
|
|
|
eventOpts: {
|
|
|
|
category: 'Transactions',
|
|
|
|
action: 'Confirm Screen',
|
|
|
|
name: 'Cancel Tx Via Notification Close',
|
|
|
|
},
|
|
|
|
customVariables: {
|
|
|
|
origin,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
cancelTransaction({ id })
|
|
|
|
}
|
|
|
|
|
|
|
|
_removeBeforeUnload = () => {
|
2020-01-24 20:12:58 +01:00
|
|
|
if (getEnvironmentType() === ENVIRONMENT_TYPE_NOTIFICATION) {
|
2019-11-04 19:03:57 +01:00
|
|
|
window.removeEventListener('beforeunload', this._beforeUnload)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-05 16:45:01 +01:00
|
|
|
componentDidMount () {
|
2019-11-04 19:03:57 +01:00
|
|
|
const { toAddress, txData: { origin } = {}, getNextNonce, tryReverseResolveAddress } = this.props
|
2019-03-05 16:45:01 +01:00
|
|
|
const { metricsEvent } = this.context
|
|
|
|
metricsEvent({
|
|
|
|
eventOpts: {
|
|
|
|
category: 'Transactions',
|
|
|
|
action: 'Confirm Screen',
|
|
|
|
name: 'Confirm: Started',
|
|
|
|
},
|
|
|
|
customVariables: {
|
|
|
|
origin,
|
|
|
|
},
|
|
|
|
})
|
2019-03-25 17:19:23 +01:00
|
|
|
|
2020-01-24 20:12:58 +01:00
|
|
|
if (getEnvironmentType() === ENVIRONMENT_TYPE_NOTIFICATION) {
|
2019-11-04 19:03:57 +01:00
|
|
|
window.addEventListener('beforeunload', this._beforeUnload)
|
2019-03-25 17:19:23 +01:00
|
|
|
}
|
2019-09-27 06:30:36 +02:00
|
|
|
|
|
|
|
getNextNonce()
|
2020-03-12 14:50:37 +01:00
|
|
|
if (toAddress) {
|
|
|
|
tryReverseResolveAddress(toAddress)
|
|
|
|
}
|
2019-03-05 16:45:01 +01:00
|
|
|
}
|
|
|
|
|
2019-10-31 17:27:22 +01:00
|
|
|
componentWillUnmount () {
|
2019-11-04 19:03:57 +01:00
|
|
|
this._removeBeforeUnload()
|
2019-10-31 17:27:22 +01:00
|
|
|
}
|
|
|
|
|
2018-06-23 08:52:45 +02:00
|
|
|
render () {
|
2020-03-19 05:03:20 +01:00
|
|
|
const { t } = this.context
|
2018-06-23 08:52:45 +02:00
|
|
|
const {
|
|
|
|
isTxReprice,
|
|
|
|
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-08-03 23:44:57 +02:00
|
|
|
valid: propsValid = true,
|
2018-07-06 20:58:41 +02:00
|
|
|
errorMessage,
|
|
|
|
errorKey: propsErrorKey,
|
2018-06-23 08:52:45 +02:00
|
|
|
title,
|
|
|
|
subtitle,
|
|
|
|
hideSubtitle,
|
|
|
|
identiconAddress,
|
|
|
|
summaryComponent,
|
|
|
|
contentComponent,
|
|
|
|
onEdit,
|
|
|
|
nonce,
|
2019-09-27 06:30:36 +02:00
|
|
|
customNonceValue,
|
2018-08-30 04:13:25 +02:00
|
|
|
assetImage,
|
2018-06-23 08:52:45 +02:00
|
|
|
warning,
|
2018-09-20 02:48:28 +02:00
|
|
|
unapprovedTxCount,
|
2019-06-18 14:17:14 +02:00
|
|
|
transactionCategory,
|
2019-11-05 16:13:48 +01:00
|
|
|
hideSenderToRecipient,
|
|
|
|
showAccountInHeader,
|
2018-06-23 08:52:45 +02:00
|
|
|
} = this.props
|
2019-09-27 06:30:36 +02:00
|
|
|
const { submitting, submitError, submitWarning } = this.state
|
2018-06-23 08:52:45 +02:00
|
|
|
|
2018-06-28 20:23:31 +02:00
|
|
|
const { name } = methodData
|
2018-07-06 20:58:41 +02:00
|
|
|
const { valid, errorKey } = this.getErrorKey()
|
2018-11-13 18:19:12 +01:00
|
|
|
const { totalTx, positionOfCurrentTx, nextTxId, prevTxId, showNavigation, firstTx, lastTx, ofText, requestsWaitingText } = this.getNavigateTxData()
|
2020-03-19 05:03:20 +01:00
|
|
|
|
|
|
|
let functionType = getMethodName(name)
|
|
|
|
if (!functionType) {
|
2020-03-23 15:54:57 +01:00
|
|
|
if (transactionCategory) {
|
|
|
|
functionType = t(transactionCategory) || transactionCategory
|
|
|
|
} else {
|
|
|
|
functionType = t('contractInteraction')
|
|
|
|
}
|
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}
|
2018-06-23 08:52:45 +02:00
|
|
|
showEdit={onEdit && !isTxReprice}
|
2020-03-19 05:03:20 +01:00
|
|
|
action={functionType}
|
2018-10-17 01:03:29 +02:00
|
|
|
title={title}
|
|
|
|
titleComponent={this.renderTitleComponent()}
|
|
|
|
subtitle={subtitle}
|
|
|
|
subtitleComponent={this.renderSubtitleComponent()}
|
2018-06-23 08:52:45 +02:00
|
|
|
hideSubtitle={hideSubtitle}
|
|
|
|
summaryComponent={summaryComponent}
|
|
|
|
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-08-30 04:13:25 +02:00
|
|
|
assetImage={assetImage}
|
2018-06-23 08:52:45 +02:00
|
|
|
identiconAddress={identiconAddress}
|
2018-08-28 21:18:57 +02:00
|
|
|
errorMessage={errorMessage || submitError}
|
2018-07-06 20:58:41 +02:00
|
|
|
errorKey={propsErrorKey || errorKey}
|
2019-09-27 06:30:36 +02:00
|
|
|
warning={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}
|
2018-08-03 23:44:57 +02:00
|
|
|
disabled={!propsValid || !valid || submitting}
|
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}
|
2018-06-23 08:52:45 +02:00
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2019-02-19 06:36:12 +01:00
|
|
|
|
|
|
|
export function getMethodName (camelCase) {
|
|
|
|
if (!camelCase || typeof camelCase !== 'string') {
|
|
|
|
return ''
|
|
|
|
}
|
|
|
|
|
|
|
|
return camelCase
|
2020-08-14 13:48:42 +02:00
|
|
|
.replace(/([a-z])([A-Z])/ug, '$1 $2')
|
|
|
|
.replace(/([A-Z])([a-z])/ug, ' $1$2')
|
|
|
|
.replace(/ +/ug, ' ')
|
2019-02-19 06:36:12 +01:00
|
|
|
}
|