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'
|
2018-07-14 22:47:07 +02:00
|
|
|
import {
|
|
|
|
TOKEN_METHOD_TRANSFER,
|
|
|
|
TOKEN_METHOD_APPROVE,
|
|
|
|
TOKEN_METHOD_TRANSFER_FROM,
|
2019-06-18 14:17:14 +02:00
|
|
|
DEPLOY_CONTRACT_ACTION_KEY,
|
|
|
|
SEND_ETHER_ACTION_KEY,
|
2019-03-22 00:03:30 +01:00
|
|
|
} from '../../helpers/constants/transactions'
|
2020-06-04 21:22:45 +02:00
|
|
|
import { MESSAGE_TYPE } from '../../../../app/scripts/lib/enums'
|
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
|
|
|
}
|
|
|
|
|
2018-06-28 20:23:31 +02:00
|
|
|
redirectToTransaction () {
|
|
|
|
const {
|
2018-07-06 20:58:41 +02:00
|
|
|
txData,
|
2018-06-28 20:23:31 +02:00
|
|
|
} = this.props
|
2019-06-18 14:17:14 +02:00
|
|
|
const { id, txParams: { data } = {}, transactionCategory } = txData
|
2018-07-06 20:58:41 +02:00
|
|
|
|
2019-06-18 14:17:14 +02:00
|
|
|
if (transactionCategory === DEPLOY_CONTRACT_ACTION_KEY) {
|
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 }} />
|
|
|
|
}
|
|
|
|
|
2019-06-18 14:17:14 +02:00
|
|
|
if (transactionCategory === SEND_ETHER_ACTION_KEY) {
|
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) {
|
2018-06-25 21:06:57 +02:00
|
|
|
case TOKEN_METHOD_TRANSFER: {
|
|
|
|
const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_SEND_TOKEN_PATH}`
|
|
|
|
return <Redirect to={{ pathname }} />
|
|
|
|
}
|
|
|
|
case TOKEN_METHOD_APPROVE: {
|
|
|
|
const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_APPROVE_PATH}`
|
|
|
|
return <Redirect to={{ pathname }} />
|
|
|
|
}
|
2018-07-14 22:47:07 +02:00
|
|
|
case TOKEN_METHOD_TRANSFER_FROM: {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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 />
|
|
|
|
}
|
|
|
|
}
|