2021-02-04 19:15:23 +01:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { Redirect } from 'react-router-dom';
|
|
|
|
import Loading from '../../components/ui/loading-screen';
|
2018-06-23 08:52:45 +02:00
|
|
|
import {
|
2018-06-25 21:06:57 +02:00
|
|
|
CONFIRM_TRANSACTION_ROUTE,
|
|
|
|
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,
|
2022-03-17 19:35:40 +01:00
|
|
|
CONFIRM_SAFE_TRANSFER_FROM_PATH,
|
2022-07-12 01:32:55 +02:00
|
|
|
CONFIRM_SET_APPROVAL_FOR_ALL_PATH,
|
2021-02-04 19:15:23 +01:00
|
|
|
} from '../../helpers/constants/routes';
|
2021-04-28 21:53:59 +02:00
|
|
|
import { MESSAGE_TYPE } from '../../../shared/constants/app';
|
2023-01-18 15:47:29 +01:00
|
|
|
import { TransactionType } from '../../../shared/constants/transaction';
|
2018-06-23 08:52:45 +02:00
|
|
|
|
|
|
|
export default class ConfirmTransactionSwitch extends Component {
|
|
|
|
static propTypes = {
|
2018-07-06 20:58:41 +02:00
|
|
|
txData: PropTypes.object,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-06-23 08:52:45 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
redirectToTransaction() {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { txData } = this.props;
|
2021-03-10 21:16:44 +01:00
|
|
|
const { id, txParams: { data } = {}, type } = txData;
|
2018-07-06 20:58:41 +02:00
|
|
|
|
2023-01-18 15:47:29 +01:00
|
|
|
if (type === TransactionType.deployContract) {
|
2021-02-04 19:15:23 +01:00
|
|
|
const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_DEPLOY_CONTRACT_PATH}`;
|
|
|
|
return <Redirect to={{ pathname }} />;
|
2018-08-17 23:34:14 +02:00
|
|
|
}
|
|
|
|
|
2023-01-18 15:47:29 +01:00
|
|
|
if (type === TransactionType.simpleSend) {
|
2021-02-04 19:15:23 +01:00
|
|
|
const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_SEND_ETHER_PATH}`;
|
|
|
|
return <Redirect to={{ pathname }} />;
|
2019-01-10 17:24:37 +01:00
|
|
|
}
|
|
|
|
|
2018-07-14 22:47:07 +02:00
|
|
|
if (data) {
|
2021-03-10 21:16:44 +01:00
|
|
|
switch (type) {
|
2023-01-18 15:47:29 +01:00
|
|
|
case TransactionType.tokenMethodTransfer: {
|
2021-02-04 19:15:23 +01:00
|
|
|
const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_SEND_TOKEN_PATH}`;
|
|
|
|
return <Redirect to={{ pathname }} />;
|
2018-06-25 21:06:57 +02:00
|
|
|
}
|
2023-01-18 15:47:29 +01:00
|
|
|
case TransactionType.tokenMethodApprove: {
|
2021-02-04 19:15:23 +01:00
|
|
|
const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_APPROVE_PATH}`;
|
|
|
|
return <Redirect to={{ pathname }} />;
|
2018-06-25 21:06:57 +02:00
|
|
|
}
|
2023-01-18 15:47:29 +01:00
|
|
|
case TransactionType.tokenMethodSetApprovalForAll: {
|
2022-07-12 01:32:55 +02:00
|
|
|
const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_SET_APPROVAL_FOR_ALL_PATH}`;
|
|
|
|
return <Redirect to={{ pathname }} />;
|
|
|
|
}
|
2023-01-18 15:47:29 +01:00
|
|
|
case TransactionType.tokenMethodTransferFrom: {
|
2021-02-04 19:15:23 +01:00
|
|
|
const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_TRANSFER_FROM_PATH}`;
|
|
|
|
return <Redirect to={{ pathname }} />;
|
2022-03-17 19:35:40 +01:00
|
|
|
}
|
2023-01-18 15:47:29 +01:00
|
|
|
case TransactionType.tokenMethodSafeTransferFrom: {
|
2022-03-17 19:35:40 +01:00
|
|
|
const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_SAFE_TRANSFER_FROM_PATH}`;
|
|
|
|
return <Redirect to={{ pathname }} />;
|
2018-07-14 22:47:07 +02:00
|
|
|
}
|
2018-06-25 21:06:57 +02:00
|
|
|
default: {
|
2021-02-04 19:15:23 +01:00
|
|
|
const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_TOKEN_METHOD_PATH}`;
|
|
|
|
return <Redirect to={{ pathname }} />;
|
2018-06-25 21:06:57 +02:00
|
|
|
}
|
2018-06-23 08:52:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_SEND_ETHER_PATH}`;
|
|
|
|
return <Redirect to={{ pathname }} />;
|
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 { txData } = this.props;
|
2018-06-23 08:52:45 +02:00
|
|
|
if (txData.txParams) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return this.redirectToTransaction();
|
2018-06-23 08:52:45 +02:00
|
|
|
} else if (txData.msgParams) {
|
2021-02-04 19:15:23 +01:00
|
|
|
let pathname = `${CONFIRM_TRANSACTION_ROUTE}/${txData.id}${SIGNATURE_REQUEST_PATH}`;
|
2020-06-04 21:22:45 +02:00
|
|
|
if (txData.type === MESSAGE_TYPE.ETH_DECRYPT) {
|
2021-02-04 19:15:23 +01:00
|
|
|
pathname = `${CONFIRM_TRANSACTION_ROUTE}/${txData.id}${DECRYPT_MESSAGE_REQUEST_PATH}`;
|
2020-06-04 21:22:45 +02:00
|
|
|
} else if (txData.type === MESSAGE_TYPE.ETH_GET_ENCRYPTION_PUBLIC_KEY) {
|
2021-02-04 19:15:23 +01:00
|
|
|
pathname = `${CONFIRM_TRANSACTION_ROUTE}/${txData.id}${ENCRYPTION_PUBLIC_KEY_REQUEST_PATH}`;
|
2020-02-19 19:24:16 +01:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
return <Redirect to={{ pathname }} />;
|
2018-06-23 08:52:45 +02:00
|
|
|
}
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
return <Loading />;
|
2018-06-23 08:52:45 +02:00
|
|
|
}
|
|
|
|
}
|