2018-06-23 08:52:45 +02:00
|
|
|
import React, { Component } from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
import { Switch, Route } from 'react-router-dom'
|
2019-03-22 00:03:30 +01:00
|
|
|
import Loading from '../../components/ui/loading-screen'
|
2018-06-23 08:52:45 +02:00
|
|
|
import ConfirmTransactionSwitch from '../confirm-transaction-switch'
|
|
|
|
import ConfirmTransactionBase from '../confirm-transaction-base'
|
|
|
|
import ConfirmSendEther from '../confirm-send-ether'
|
|
|
|
import ConfirmSendToken from '../confirm-send-token'
|
|
|
|
import ConfirmDeployContract from '../confirm-deploy-contract'
|
|
|
|
import ConfirmApprove from '../confirm-approve'
|
2020-01-09 04:34:58 +01:00
|
|
|
import ConfirmTokenTransactionBaseContainer from '../confirm-token-transaction-base'
|
2020-02-19 19:24:16 +01:00
|
|
|
import ConfirmDecryptMessage from '../confirm-decrypt-message'
|
|
|
|
import ConfirmEncryptionPublicKey from '../confirm-encryption-public-key'
|
|
|
|
|
2018-06-23 08:52:45 +02:00
|
|
|
import {
|
|
|
|
CONFIRM_TRANSACTION_ROUTE,
|
2018-06-25 21:06:57 +02:00
|
|
|
CONFIRM_DEPLOY_CONTRACT_PATH,
|
|
|
|
CONFIRM_SEND_ETHER_PATH,
|
|
|
|
CONFIRM_SEND_TOKEN_PATH,
|
|
|
|
CONFIRM_APPROVE_PATH,
|
2018-07-14 22:47:07 +02:00
|
|
|
CONFIRM_TRANSFER_FROM_PATH,
|
2018-06-25 21:06:57 +02:00
|
|
|
CONFIRM_TOKEN_METHOD_PATH,
|
|
|
|
SIGNATURE_REQUEST_PATH,
|
2020-02-19 19:24:16 +01:00
|
|
|
DECRYPT_MESSAGE_REQUEST_PATH,
|
|
|
|
ENCRYPTION_PUBLIC_KEY_REQUEST_PATH,
|
2019-03-22 00:03:30 +01:00
|
|
|
} from '../../helpers/constants/routes'
|
2020-08-18 21:18:25 +02:00
|
|
|
import ConfTx from './conf-tx'
|
2018-06-23 08:52:45 +02:00
|
|
|
|
|
|
|
export default class ConfirmTransaction extends Component {
|
2019-09-24 23:08:38 +02:00
|
|
|
static contextTypes = {
|
|
|
|
metricsEvent: PropTypes.func,
|
|
|
|
}
|
|
|
|
|
2018-06-23 08:52:45 +02:00
|
|
|
static propTypes = {
|
|
|
|
history: PropTypes.object.isRequired,
|
|
|
|
totalUnapprovedCount: PropTypes.number.isRequired,
|
|
|
|
send: PropTypes.object,
|
2018-06-25 21:06:57 +02:00
|
|
|
setTransactionToConfirm: PropTypes.func,
|
2018-07-06 20:58:41 +02:00
|
|
|
clearConfirmTransaction: PropTypes.func,
|
2020-12-03 00:25:19 +01:00
|
|
|
fetchBasicGasEstimates: PropTypes.func,
|
2020-06-01 19:54:32 +02:00
|
|
|
mostRecentOverviewPage: PropTypes.string.isRequired,
|
2019-06-18 14:17:14 +02:00
|
|
|
transaction: PropTypes.object,
|
|
|
|
getContractMethodData: PropTypes.func,
|
|
|
|
transactionId: PropTypes.string,
|
|
|
|
paramsTransactionId: PropTypes.string,
|
2019-06-28 05:53:12 +02:00
|
|
|
getTokenParams: PropTypes.func,
|
|
|
|
isTokenMethodAction: PropTypes.bool,
|
2018-07-06 20:58:41 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
componentDidMount() {
|
2018-06-25 21:06:57 +02:00
|
|
|
const {
|
|
|
|
totalUnapprovedCount = 0,
|
|
|
|
send = {},
|
|
|
|
history,
|
2020-06-01 19:54:32 +02:00
|
|
|
mostRecentOverviewPage,
|
2019-06-28 05:53:12 +02:00
|
|
|
transaction: { txParams: { data, to } = {} } = {},
|
2020-12-03 00:25:19 +01:00
|
|
|
fetchBasicGasEstimates,
|
2019-06-18 14:17:14 +02:00
|
|
|
getContractMethodData,
|
|
|
|
transactionId,
|
|
|
|
paramsTransactionId,
|
2019-06-28 05:53:12 +02:00
|
|
|
getTokenParams,
|
|
|
|
isTokenMethodAction,
|
2018-06-25 21:06:57 +02:00
|
|
|
} = this.props
|
2018-06-23 08:52:45 +02:00
|
|
|
|
|
|
|
if (!totalUnapprovedCount && !send.to) {
|
2020-06-01 19:54:32 +02:00
|
|
|
history.replace(mostRecentOverviewPage)
|
2018-06-25 21:06:57 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-12-03 00:25:19 +01:00
|
|
|
fetchBasicGasEstimates()
|
2019-06-18 14:17:14 +02:00
|
|
|
getContractMethodData(data)
|
2019-06-28 05:53:12 +02:00
|
|
|
if (isTokenMethodAction) {
|
|
|
|
getTokenParams(to)
|
|
|
|
}
|
2019-08-26 14:04:48 +02:00
|
|
|
const txId = transactionId || paramsTransactionId
|
2019-11-20 01:03:20 +01:00
|
|
|
if (txId) {
|
|
|
|
this.props.setTransactionToConfirm(txId)
|
|
|
|
}
|
2018-06-25 21:06:57 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
componentDidUpdate(prevProps) {
|
2018-06-25 21:06:57 +02:00
|
|
|
const {
|
|
|
|
setTransactionToConfirm,
|
2019-06-18 14:17:14 +02:00
|
|
|
transaction: { txData: { txParams: { data } = {} } = {} },
|
2018-07-06 20:58:41 +02:00
|
|
|
clearConfirmTransaction,
|
2019-06-18 14:17:14 +02:00
|
|
|
getContractMethodData,
|
|
|
|
paramsTransactionId,
|
|
|
|
transactionId,
|
|
|
|
history,
|
2020-06-01 19:54:32 +02:00
|
|
|
mostRecentOverviewPage,
|
2019-06-18 14:17:14 +02:00
|
|
|
totalUnapprovedCount,
|
2018-06-25 21:06:57 +02:00
|
|
|
} = this.props
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
if (
|
|
|
|
paramsTransactionId &&
|
|
|
|
transactionId &&
|
|
|
|
prevProps.paramsTransactionId !== paramsTransactionId
|
|
|
|
) {
|
2018-07-06 20:58:41 +02:00
|
|
|
clearConfirmTransaction()
|
2019-06-18 14:17:14 +02:00
|
|
|
getContractMethodData(data)
|
2018-06-25 21:06:57 +02:00
|
|
|
setTransactionToConfirm(paramsTransactionId)
|
2020-11-03 00:41:28 +01:00
|
|
|
} else if (
|
|
|
|
prevProps.transactionId &&
|
|
|
|
!transactionId &&
|
|
|
|
!totalUnapprovedCount
|
|
|
|
) {
|
2020-06-01 19:54:32 +02:00
|
|
|
history.replace(mostRecentOverviewPage)
|
2020-11-03 00:41:28 +01:00
|
|
|
} else if (
|
|
|
|
prevProps.transactionId &&
|
|
|
|
transactionId &&
|
|
|
|
prevProps.transactionId !== transactionId
|
|
|
|
) {
|
2020-06-01 19:54:32 +02:00
|
|
|
history.replace(mostRecentOverviewPage)
|
2018-06-23 08:52:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
render() {
|
2019-06-18 14:17:14 +02:00
|
|
|
const { transactionId, paramsTransactionId } = this.props
|
2018-07-06 20:58:41 +02:00
|
|
|
// Show routes when state.confirmTransaction has been set and when either the ID in the params
|
|
|
|
// isn't specified or is specified and matches the ID in state.confirmTransaction in order to
|
|
|
|
// support URLs of /confirm-transaction or /confirm-transaction/<transactionId>
|
2020-11-03 00:41:28 +01:00
|
|
|
return transactionId &&
|
|
|
|
(!paramsTransactionId || paramsTransactionId === transactionId) ? (
|
|
|
|
<Switch>
|
|
|
|
<Route
|
|
|
|
exact
|
|
|
|
path={`${CONFIRM_TRANSACTION_ROUTE}/:id?${CONFIRM_DEPLOY_CONTRACT_PATH}`}
|
|
|
|
component={ConfirmDeployContract}
|
|
|
|
/>
|
|
|
|
<Route
|
|
|
|
exact
|
|
|
|
path={`${CONFIRM_TRANSACTION_ROUTE}/:id?${CONFIRM_TOKEN_METHOD_PATH}`}
|
|
|
|
component={ConfirmTransactionBase}
|
|
|
|
/>
|
|
|
|
<Route
|
|
|
|
exact
|
|
|
|
path={`${CONFIRM_TRANSACTION_ROUTE}/:id?${CONFIRM_SEND_ETHER_PATH}`}
|
|
|
|
component={ConfirmSendEther}
|
|
|
|
/>
|
|
|
|
<Route
|
|
|
|
exact
|
|
|
|
path={`${CONFIRM_TRANSACTION_ROUTE}/:id?${CONFIRM_SEND_TOKEN_PATH}`}
|
|
|
|
component={ConfirmSendToken}
|
|
|
|
/>
|
|
|
|
<Route
|
|
|
|
exact
|
|
|
|
path={`${CONFIRM_TRANSACTION_ROUTE}/:id?${CONFIRM_APPROVE_PATH}`}
|
|
|
|
component={ConfirmApprove}
|
|
|
|
/>
|
|
|
|
<Route
|
|
|
|
exact
|
|
|
|
path={`${CONFIRM_TRANSACTION_ROUTE}/:id?${CONFIRM_TRANSFER_FROM_PATH}`}
|
|
|
|
component={ConfirmTokenTransactionBaseContainer}
|
|
|
|
/>
|
|
|
|
<Route
|
|
|
|
exact
|
|
|
|
path={`${CONFIRM_TRANSACTION_ROUTE}/:id?${SIGNATURE_REQUEST_PATH}`}
|
|
|
|
component={ConfTx}
|
|
|
|
/>
|
|
|
|
<Route
|
|
|
|
exact
|
|
|
|
path={`${CONFIRM_TRANSACTION_ROUTE}/:id?${DECRYPT_MESSAGE_REQUEST_PATH}`}
|
|
|
|
component={ConfirmDecryptMessage}
|
|
|
|
/>
|
|
|
|
<Route
|
|
|
|
exact
|
|
|
|
path={`${CONFIRM_TRANSACTION_ROUTE}/:id?${ENCRYPTION_PUBLIC_KEY_REQUEST_PATH}`}
|
|
|
|
component={ConfirmEncryptionPublicKey}
|
|
|
|
/>
|
|
|
|
<Route path="*" component={ConfirmTransactionSwitch} />
|
|
|
|
</Switch>
|
|
|
|
) : (
|
|
|
|
<Loading />
|
|
|
|
)
|
2018-06-23 08:52:45 +02:00
|
|
|
}
|
|
|
|
}
|