2021-02-04 19:15:23 +01:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { Switch, Route } from 'react-router-dom';
|
|
|
|
import Loading from '../../components/ui/loading-screen';
|
|
|
|
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';
|
|
|
|
import ConfirmTokenTransactionBaseContainer from '../confirm-token-transaction-base';
|
|
|
|
import ConfirmDecryptMessage from '../confirm-decrypt-message';
|
|
|
|
import ConfirmEncryptionPublicKey from '../confirm-encryption-public-key';
|
2020-02-19 19:24:16 +01:00
|
|
|
|
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,
|
2021-05-03 19:51:09 +02:00
|
|
|
DEFAULT_ROUTE,
|
2021-02-04 19:15:23 +01:00
|
|
|
} from '../../helpers/constants/routes';
|
|
|
|
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,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-09-24 23:08:38 +02:00
|
|
|
|
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,
|
2021-05-03 19:51:09 +02:00
|
|
|
setDefaultHomeActiveTabName: PropTypes.func,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
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,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = this.props;
|
2018-06-23 08:52:45 +02:00
|
|
|
|
|
|
|
if (!totalUnapprovedCount && !send.to) {
|
2021-02-04 19:15:23 +01:00
|
|
|
history.replace(mostRecentOverviewPage);
|
|
|
|
return;
|
2018-06-25 21:06:57 +02:00
|
|
|
}
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
fetchBasicGasEstimates();
|
|
|
|
getContractMethodData(data);
|
2019-06-28 05:53:12 +02:00
|
|
|
if (isTokenMethodAction) {
|
2021-02-04 19:15:23 +01:00
|
|
|
getTokenParams(to);
|
2019-06-28 05:53:12 +02:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
const txId = transactionId || paramsTransactionId;
|
2019-11-20 01:03:20 +01:00
|
|
|
if (txId) {
|
2021-02-04 19:15:23 +01:00
|
|
|
this.props.setTransactionToConfirm(txId);
|
2019-11-20 01:03:20 +01:00
|
|
|
}
|
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,
|
2021-05-03 19:51:09 +02:00
|
|
|
setDefaultHomeActiveTabName,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = this.props;
|
2018-06-25 21:06:57 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
if (
|
|
|
|
paramsTransactionId &&
|
|
|
|
transactionId &&
|
|
|
|
prevProps.paramsTransactionId !== paramsTransactionId
|
|
|
|
) {
|
2021-02-04 19:15:23 +01:00
|
|
|
clearConfirmTransaction();
|
|
|
|
getContractMethodData(data);
|
|
|
|
setTransactionToConfirm(paramsTransactionId);
|
2020-11-03 00:41:28 +01:00
|
|
|
} else if (
|
|
|
|
prevProps.transactionId &&
|
|
|
|
!transactionId &&
|
|
|
|
!totalUnapprovedCount
|
|
|
|
) {
|
2021-05-03 19:51:09 +02:00
|
|
|
setDefaultHomeActiveTabName('Activity').then(() => {
|
|
|
|
history.replace(DEFAULT_ROUTE);
|
|
|
|
});
|
2020-11-03 00:41:28 +01:00
|
|
|
} else if (
|
|
|
|
prevProps.transactionId &&
|
|
|
|
transactionId &&
|
|
|
|
prevProps.transactionId !== transactionId
|
|
|
|
) {
|
2021-02-04 19:15:23 +01:00
|
|
|
history.replace(mostRecentOverviewPage);
|
2018-06-23 08:52:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
render() {
|
2021-02-04 19:15:23 +01: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 />
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-06-23 08:52:45 +02:00
|
|
|
}
|
|
|
|
}
|