You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
2.9 KiB
81 lines
2.9 KiB
4 years ago
|
import React, { Component } from 'react';
|
||
|
import PropTypes from 'prop-types';
|
||
|
import { Redirect } from 'react-router-dom';
|
||
|
import Loading from '../../components/ui/loading-screen';
|
||
7 years ago
|
import {
|
||
7 years ago
|
CONFIRM_TRANSACTION_ROUTE,
|
||
|
CONFIRM_DEPLOY_CONTRACT_PATH,
|
||
|
CONFIRM_SEND_ETHER_PATH,
|
||
|
CONFIRM_SEND_TOKEN_PATH,
|
||
|
CONFIRM_APPROVE_PATH,
|
||
6 years ago
|
CONFIRM_TRANSFER_FROM_PATH,
|
||
7 years ago
|
CONFIRM_TOKEN_METHOD_PATH,
|
||
|
SIGNATURE_REQUEST_PATH,
|
||
5 years ago
|
DECRYPT_MESSAGE_REQUEST_PATH,
|
||
|
ENCRYPTION_PUBLIC_KEY_REQUEST_PATH,
|
||
4 years ago
|
} from '../../helpers/constants/routes';
|
||
4 years ago
|
import { MESSAGE_TYPE } from '../../../shared/constants/app';
|
||
|
import { TRANSACTION_TYPES } from '../../../shared/constants/transaction';
|
||
7 years ago
|
|
||
|
export default class ConfirmTransactionSwitch extends Component {
|
||
|
static propTypes = {
|
||
7 years ago
|
txData: PropTypes.object,
|
||
4 years ago
|
};
|
||
7 years ago
|
|
||
4 years ago
|
redirectToTransaction() {
|
||
4 years ago
|
const { txData } = this.props;
|
||
4 years ago
|
const { id, txParams: { data } = {}, type } = txData;
|
||
7 years ago
|
|
||
4 years ago
|
if (type === TRANSACTION_TYPES.DEPLOY_CONTRACT) {
|
||
4 years ago
|
const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_DEPLOY_CONTRACT_PATH}`;
|
||
|
return <Redirect to={{ pathname }} />;
|
||
6 years ago
|
}
|
||
|
|
||
4 years ago
|
if (type === TRANSACTION_TYPES.SENT_ETHER) {
|
||
4 years ago
|
const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_SEND_ETHER_PATH}`;
|
||
|
return <Redirect to={{ pathname }} />;
|
||
6 years ago
|
}
|
||
|
|
||
6 years ago
|
if (data) {
|
||
4 years ago
|
switch (type) {
|
||
|
case TRANSACTION_TYPES.TOKEN_METHOD_TRANSFER: {
|
||
4 years ago
|
const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_SEND_TOKEN_PATH}`;
|
||
|
return <Redirect to={{ pathname }} />;
|
||
7 years ago
|
}
|
||
4 years ago
|
case TRANSACTION_TYPES.TOKEN_METHOD_APPROVE: {
|
||
4 years ago
|
const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_APPROVE_PATH}`;
|
||
|
return <Redirect to={{ pathname }} />;
|
||
7 years ago
|
}
|
||
4 years ago
|
case TRANSACTION_TYPES.TOKEN_METHOD_TRANSFER_FROM: {
|
||
4 years ago
|
const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_TRANSFER_FROM_PATH}`;
|
||
|
return <Redirect to={{ pathname }} />;
|
||
6 years ago
|
}
|
||
7 years ago
|
default: {
|
||
4 years ago
|
const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_TOKEN_METHOD_PATH}`;
|
||
|
return <Redirect to={{ pathname }} />;
|
||
7 years ago
|
}
|
||
7 years ago
|
}
|
||
|
}
|
||
|
|
||
4 years ago
|
const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_SEND_ETHER_PATH}`;
|
||
|
return <Redirect to={{ pathname }} />;
|
||
7 years ago
|
}
|
||
|
|
||
4 years ago
|
render() {
|
||
4 years ago
|
const { txData } = this.props;
|
||
7 years ago
|
if (txData.txParams) {
|
||
4 years ago
|
return this.redirectToTransaction();
|
||
7 years ago
|
} else if (txData.msgParams) {
|
||
4 years ago
|
let pathname = `${CONFIRM_TRANSACTION_ROUTE}/${txData.id}${SIGNATURE_REQUEST_PATH}`;
|
||
5 years ago
|
if (txData.type === MESSAGE_TYPE.ETH_DECRYPT) {
|
||
4 years ago
|
pathname = `${CONFIRM_TRANSACTION_ROUTE}/${txData.id}${DECRYPT_MESSAGE_REQUEST_PATH}`;
|
||
5 years ago
|
} else if (txData.type === MESSAGE_TYPE.ETH_GET_ENCRYPTION_PUBLIC_KEY) {
|
||
4 years ago
|
pathname = `${CONFIRM_TRANSACTION_ROUTE}/${txData.id}${ENCRYPTION_PUBLIC_KEY_REQUEST_PATH}`;
|
||
5 years ago
|
}
|
||
4 years ago
|
return <Redirect to={{ pathname }} />;
|
||
7 years ago
|
}
|
||
|
|
||
4 years ago
|
return <Loading />;
|
||
7 years ago
|
}
|
||
|
}
|