2018-06-23 08:52:45 +02:00
|
|
|
import React, { Component } from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
import { Redirect } 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 {
|
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,
|
2019-03-22 00:03:30 +01:00
|
|
|
} from '../../helpers/constants/routes'
|
2021-01-20 17:13:14 +01:00
|
|
|
import { MESSAGE_TYPE } from '../../../../shared/constants/app'
|
2020-11-03 23:57:51 +01:00
|
|
|
import { TRANSACTION_CATEGORIES } 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,
|
2018-06-23 08:52:45 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
redirectToTransaction() {
|
|
|
|
const { txData } = this.props
|
2019-06-18 14:17:14 +02:00
|
|
|
const { id, txParams: { data } = {}, transactionCategory } = txData
|
2018-07-06 20:58:41 +02:00
|
|
|
|
2020-11-03 23:57:51 +01:00
|
|
|
if (transactionCategory === TRANSACTION_CATEGORIES.DEPLOY_CONTRACT) {
|
2018-11-13 18:19:12 +01:00
|
|
|
const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_DEPLOY_CONTRACT_PATH}`
|
2018-08-17 23:34:14 +02:00
|
|
|
return <Redirect to={{ pathname }} />
|
|
|
|
}
|
|
|
|
|
2020-11-03 23:57:51 +01:00
|
|
|
if (transactionCategory === TRANSACTION_CATEGORIES.SENT_ETHER) {
|
2019-01-10 17:24:37 +01:00
|
|
|
const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_SEND_ETHER_PATH}`
|
|
|
|
return <Redirect to={{ pathname }} />
|
|
|
|
}
|
|
|
|
|
2018-07-14 22:47:07 +02:00
|
|
|
if (data) {
|
2019-06-18 14:17:14 +02:00
|
|
|
switch (transactionCategory) {
|
2020-11-03 23:57:51 +01:00
|
|
|
case TRANSACTION_CATEGORIES.TOKEN_METHOD_TRANSFER: {
|
2018-06-25 21:06:57 +02:00
|
|
|
const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_SEND_TOKEN_PATH}`
|
|
|
|
return <Redirect to={{ pathname }} />
|
|
|
|
}
|
2020-11-03 23:57:51 +01:00
|
|
|
case TRANSACTION_CATEGORIES.TOKEN_METHOD_APPROVE: {
|
2018-06-25 21:06:57 +02:00
|
|
|
const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_APPROVE_PATH}`
|
|
|
|
return <Redirect to={{ pathname }} />
|
|
|
|
}
|
2020-11-03 23:57:51 +01:00
|
|
|
case TRANSACTION_CATEGORIES.TOKEN_METHOD_TRANSFER_FROM: {
|
2018-07-14 22:47:07 +02:00
|
|
|
const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_TRANSFER_FROM_PATH}`
|
|
|
|
return <Redirect to={{ pathname }} />
|
|
|
|
}
|
2018-06-25 21:06:57 +02:00
|
|
|
default: {
|
|
|
|
const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_TOKEN_METHOD_PATH}`
|
|
|
|
return <Redirect to={{ pathname }} />
|
|
|
|
}
|
2018-06-23 08:52:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-25 21:06:57 +02: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() {
|
2018-07-06 20:58:41 +02:00
|
|
|
const { txData } = this.props
|
2018-06-23 08:52:45 +02:00
|
|
|
if (txData.txParams) {
|
2018-06-28 20:23:31 +02:00
|
|
|
return this.redirectToTransaction()
|
2018-06-23 08:52:45 +02:00
|
|
|
} else if (txData.msgParams) {
|
2020-02-19 19:24:16 +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) {
|
2020-02-19 19:24:16 +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) {
|
2020-02-19 19:24:16 +01:00
|
|
|
pathname = `${CONFIRM_TRANSACTION_ROUTE}/${txData.id}${ENCRYPTION_PUBLIC_KEY_REQUEST_PATH}`
|
|
|
|
}
|
2018-06-25 21:06:57 +02:00
|
|
|
return <Redirect to={{ pathname }} />
|
2018-06-23 08:52:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return <Loading />
|
|
|
|
}
|
|
|
|
}
|