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.
93 lines
2.7 KiB
93 lines
2.7 KiB
7 years ago
|
import React, { Component } from 'react'
|
||
|
import PropTypes from 'prop-types'
|
||
|
import { Redirect } from 'react-router-dom'
|
||
6 years ago
|
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,
|
||
6 years ago
|
} from '../../helpers/constants/routes'
|
||
|
import { isConfirmDeployContract } from '../../helpers/utils/transactions.util'
|
||
6 years ago
|
import {
|
||
|
TOKEN_METHOD_TRANSFER,
|
||
|
TOKEN_METHOD_APPROVE,
|
||
|
TOKEN_METHOD_TRANSFER_FROM,
|
||
6 years ago
|
} from '../../helpers/constants/transactions'
|
||
7 years ago
|
|
||
|
export default class ConfirmTransactionSwitch extends Component {
|
||
|
static propTypes = {
|
||
6 years ago
|
txData: PropTypes.object,
|
||
|
methodData: PropTypes.object,
|
||
6 years ago
|
fetchingData: PropTypes.bool,
|
||
|
isEtherTransaction: PropTypes.bool,
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
redirectToTransaction () {
|
||
|
const {
|
||
6 years ago
|
txData,
|
||
|
methodData: { name },
|
||
6 years ago
|
fetchingData,
|
||
6 years ago
|
isEtherTransaction,
|
||
7 years ago
|
} = this.props
|
||
6 years ago
|
const { id, txParams: { data } = {} } = txData
|
||
6 years ago
|
|
||
6 years ago
|
if (fetchingData) {
|
||
7 years ago
|
return <Loading />
|
||
|
}
|
||
|
|
||
6 years ago
|
if (isConfirmDeployContract(txData)) {
|
||
|
const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_DEPLOY_CONTRACT_PATH}`
|
||
6 years ago
|
return <Redirect to={{ pathname }} />
|
||
|
}
|
||
|
|
||
6 years ago
|
if (isEtherTransaction) {
|
||
|
const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_SEND_ETHER_PATH}`
|
||
|
return <Redirect to={{ pathname }} />
|
||
|
}
|
||
|
|
||
6 years ago
|
if (data) {
|
||
|
const methodName = name && name.toLowerCase()
|
||
7 years ago
|
|
||
6 years ago
|
switch (methodName) {
|
||
7 years ago
|
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 }} />
|
||
|
}
|
||
6 years ago
|
case TOKEN_METHOD_TRANSFER_FROM: {
|
||
|
const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_TRANSFER_FROM_PATH}`
|
||
|
return <Redirect to={{ pathname }} />
|
||
|
}
|
||
7 years ago
|
default: {
|
||
|
const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_TOKEN_METHOD_PATH}`
|
||
|
return <Redirect to={{ pathname }} />
|
||
|
}
|
||
7 years ago
|
}
|
||
|
}
|
||
|
|
||
7 years ago
|
const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_SEND_ETHER_PATH}`
|
||
|
return <Redirect to={{ pathname }} />
|
||
7 years ago
|
}
|
||
|
|
||
|
render () {
|
||
6 years ago
|
const { txData } = this.props
|
||
7 years ago
|
|
||
|
if (txData.txParams) {
|
||
7 years ago
|
return this.redirectToTransaction()
|
||
7 years ago
|
} else if (txData.msgParams) {
|
||
7 years ago
|
const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${txData.id}${SIGNATURE_REQUEST_PATH}`
|
||
|
return <Redirect to={{ pathname }} />
|
||
7 years ago
|
}
|
||
|
|
||
|
return <Loading />
|
||
|
}
|
||
|
}
|