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,
|
2021-02-04 19:15:23 +01:00
|
|
|
} from '../../helpers/constants/routes';
|
|
|
|
import { MESSAGE_TYPE } from '../../../../shared/constants/app';
|
2021-03-10 21:16:44 +01:00
|
|
|
import { TRANSACTION_TYPES } 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
|
|
|
|
2021-03-10 21:16:44 +01:00
|
|
|
if (type === TRANSACTION_TYPES.DEPLOY_CONTRACT) {
|
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
|
|
|
}
|
|
|
|
|
2021-03-10 21:16:44 +01:00
|
|
|
if (type === TRANSACTION_TYPES.SENT_ETHER) {
|
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) {
|
|
|
|
case TRANSACTION_TYPES.TOKEN_METHOD_TRANSFER: {
|
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
|
|
|
}
|
2021-03-10 21:16:44 +01:00
|
|
|
case TRANSACTION_TYPES.TOKEN_METHOD_APPROVE: {
|
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
|
|
|
}
|
2021-03-10 21:16:44 +01:00
|
|
|
case TRANSACTION_TYPES.TOKEN_METHOD_TRANSFER_FROM: {
|
2021-02-04 19:15:23 +01:00
|
|
|
const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_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
|
|
|
}
|
|
|
|
}
|