2018-06-23 08:52:45 +02:00
|
|
|
import React, { Component } from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
import { Redirect } from 'react-router-dom'
|
|
|
|
import Loading from '../../loading-screen'
|
|
|
|
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,
|
2018-06-23 08:52:45 +02:00
|
|
|
} from '../../../routes'
|
2018-07-31 07:03:20 +02:00
|
|
|
import { isConfirmDeployContract } from '../../../helpers/transactions.util'
|
2018-07-14 22:47:07 +02:00
|
|
|
import {
|
|
|
|
TOKEN_METHOD_TRANSFER,
|
|
|
|
TOKEN_METHOD_APPROVE,
|
|
|
|
TOKEN_METHOD_TRANSFER_FROM,
|
2018-07-31 07:03:20 +02:00
|
|
|
} from '../../../constants/transactions'
|
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,
|
|
|
|
methodData: PropTypes.object,
|
2018-08-17 23:34:14 +02:00
|
|
|
fetchingData: PropTypes.bool,
|
|
|
|
isEtherTransaction: PropTypes.bool,
|
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,
|
|
|
|
methodData: { name },
|
2018-08-17 23:34:14 +02:00
|
|
|
fetchingData,
|
2018-06-28 20:23:31 +02:00
|
|
|
} = this.props
|
2018-07-14 22:47:07 +02:00
|
|
|
const { id, txParams: { data } = {} } = txData
|
2018-07-06 20:58:41 +02:00
|
|
|
|
2018-08-17 23:34:14 +02:00
|
|
|
if (fetchingData) {
|
2018-06-28 20:23:31 +02:00
|
|
|
return <Loading />
|
|
|
|
}
|
|
|
|
|
2018-11-13 18:19:12 +01:00
|
|
|
if (isConfirmDeployContract(txData)) {
|
|
|
|
const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_DEPLOY_CONTRACT_PATH}`
|
2018-08-17 23:34:14 +02:00
|
|
|
return <Redirect to={{ pathname }} />
|
|
|
|
}
|
|
|
|
|
2018-07-14 22:47:07 +02:00
|
|
|
if (data) {
|
|
|
|
const methodName = name && name.toLowerCase()
|
2018-06-23 08:52:45 +02:00
|
|
|
|
2018-07-14 22:47:07 +02:00
|
|
|
switch (methodName) {
|
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) {
|
2018-06-25 21:06:57 +02:00
|
|
|
const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${txData.id}${SIGNATURE_REQUEST_PATH}`
|
|
|
|
return <Redirect to={{ pathname }} />
|
2018-06-23 08:52:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return <Loading />
|
|
|
|
}
|
|
|
|
}
|