2018-06-23 08:52:45 +02:00
|
|
|
import React, { Component } from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
import { Switch, Route } from 'react-router-dom'
|
2018-06-25 21:06:57 +02:00
|
|
|
import Loading from '../../loading-screen'
|
2018-06-23 08:52:45 +02:00
|
|
|
import ConfirmTransactionSwitch from '../confirm-transaction-switch'
|
|
|
|
import ConfirmTransactionBase from '../confirm-transaction-base'
|
|
|
|
import ConfirmSendEther from '../confirm-send-ether'
|
|
|
|
import ConfirmSendToken from '../confirm-send-token'
|
|
|
|
import ConfirmDeployContract from '../confirm-deploy-contract'
|
|
|
|
import ConfirmApprove from '../confirm-approve'
|
2018-07-14 22:47:07 +02:00
|
|
|
import ConfirmTokenTransactionBase from '../confirm-token-transaction-base'
|
2018-06-23 08:52:45 +02:00
|
|
|
import ConfTx from '../../../conf-tx'
|
|
|
|
import {
|
|
|
|
DEFAULT_ROUTE,
|
|
|
|
CONFIRM_TRANSACTION_ROUTE,
|
2018-06-25 21:06:57 +02:00
|
|
|
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'
|
|
|
|
|
|
|
|
export default class ConfirmTransaction extends Component {
|
|
|
|
static propTypes = {
|
|
|
|
history: PropTypes.object.isRequired,
|
|
|
|
totalUnapprovedCount: PropTypes.number.isRequired,
|
|
|
|
match: PropTypes.object,
|
|
|
|
send: PropTypes.object,
|
2018-06-25 21:06:57 +02:00
|
|
|
unconfirmedTransactions: PropTypes.array,
|
|
|
|
setTransactionToConfirm: PropTypes.func,
|
|
|
|
confirmTransaction: PropTypes.object,
|
2018-07-06 20:58:41 +02:00
|
|
|
clearConfirmTransaction: PropTypes.func,
|
|
|
|
}
|
|
|
|
|
|
|
|
getParamsTransactionId () {
|
|
|
|
const { match: { params: { id } = {} } } = this.props
|
|
|
|
return id || null
|
2018-06-23 08:52:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount () {
|
2018-06-25 21:06:57 +02:00
|
|
|
const {
|
|
|
|
totalUnapprovedCount = 0,
|
|
|
|
send = {},
|
|
|
|
history,
|
|
|
|
confirmTransaction: { txData: { id: transactionId } = {} },
|
|
|
|
} = this.props
|
2018-06-23 08:52:45 +02:00
|
|
|
|
|
|
|
if (!totalUnapprovedCount && !send.to) {
|
|
|
|
history.replace(DEFAULT_ROUTE)
|
2018-06-25 21:06:57 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!transactionId) {
|
|
|
|
this.setTransactionToConfirm()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate () {
|
|
|
|
const {
|
|
|
|
setTransactionToConfirm,
|
|
|
|
confirmTransaction: { txData: { id: transactionId } = {} },
|
2018-07-06 20:58:41 +02:00
|
|
|
clearConfirmTransaction,
|
2018-06-25 21:06:57 +02:00
|
|
|
} = this.props
|
2018-07-06 20:58:41 +02:00
|
|
|
const paramsTransactionId = this.getParamsTransactionId()
|
2018-06-25 21:06:57 +02:00
|
|
|
|
|
|
|
if (paramsTransactionId && transactionId && paramsTransactionId !== transactionId + '') {
|
2018-07-06 20:58:41 +02:00
|
|
|
clearConfirmTransaction()
|
2018-06-25 21:06:57 +02:00
|
|
|
setTransactionToConfirm(paramsTransactionId)
|
2018-07-06 20:58:41 +02:00
|
|
|
return
|
2018-06-25 21:06:57 +02:00
|
|
|
}
|
|
|
|
|
2018-06-26 06:29:16 +02:00
|
|
|
if (!transactionId) {
|
2018-06-25 21:06:57 +02:00
|
|
|
this.setTransactionToConfirm()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setTransactionToConfirm () {
|
|
|
|
const {
|
|
|
|
history,
|
|
|
|
unconfirmedTransactions,
|
|
|
|
setTransactionToConfirm,
|
|
|
|
} = this.props
|
2018-07-06 20:58:41 +02:00
|
|
|
const paramsTransactionId = this.getParamsTransactionId()
|
2018-06-25 21:06:57 +02:00
|
|
|
|
|
|
|
if (paramsTransactionId) {
|
|
|
|
// Check to make sure params ID is valid
|
2018-07-06 20:58:41 +02:00
|
|
|
const tx = unconfirmedTransactions.find(({ id }) => id + '' === paramsTransactionId)
|
2018-06-25 21:06:57 +02:00
|
|
|
|
|
|
|
if (!tx) {
|
|
|
|
history.replace(DEFAULT_ROUTE)
|
|
|
|
} else {
|
|
|
|
setTransactionToConfirm(paramsTransactionId)
|
|
|
|
}
|
|
|
|
} else if (unconfirmedTransactions.length) {
|
2018-06-26 06:29:16 +02:00
|
|
|
const totalUnconfirmed = unconfirmedTransactions.length
|
2018-06-28 20:23:31 +02:00
|
|
|
const transaction = unconfirmedTransactions[totalUnconfirmed - 1]
|
|
|
|
const { id: transactionId, loadingDefaults } = transaction
|
|
|
|
|
|
|
|
if (!loadingDefaults) {
|
|
|
|
setTransactionToConfirm(transactionId)
|
|
|
|
}
|
2018-06-23 08:52:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
2018-06-25 21:06:57 +02:00
|
|
|
const { confirmTransaction: { txData: { id } } = {} } = this.props
|
2018-07-06 20:58:41 +02:00
|
|
|
const paramsTransactionId = this.getParamsTransactionId()
|
2018-06-25 21:06:57 +02:00
|
|
|
|
2018-07-06 20:58:41 +02:00
|
|
|
// Show routes when state.confirmTransaction has been set and when either the ID in the params
|
|
|
|
// isn't specified or is specified and matches the ID in state.confirmTransaction in order to
|
|
|
|
// support URLs of /confirm-transaction or /confirm-transaction/<transactionId>
|
|
|
|
return id && (!paramsTransactionId || paramsTransactionId === id + '')
|
2018-06-25 21:06:57 +02:00
|
|
|
? (
|
|
|
|
<Switch>
|
|
|
|
<Route
|
|
|
|
exact
|
|
|
|
path={`${CONFIRM_TRANSACTION_ROUTE}/:id?${CONFIRM_DEPLOY_CONTRACT_PATH}`}
|
|
|
|
component={ConfirmDeployContract}
|
|
|
|
/>
|
|
|
|
<Route
|
|
|
|
exact
|
|
|
|
path={`${CONFIRM_TRANSACTION_ROUTE}/:id?${CONFIRM_TOKEN_METHOD_PATH}`}
|
|
|
|
component={ConfirmTransactionBase}
|
|
|
|
/>
|
|
|
|
<Route
|
|
|
|
exact
|
|
|
|
path={`${CONFIRM_TRANSACTION_ROUTE}/:id?${CONFIRM_SEND_ETHER_PATH}`}
|
|
|
|
component={ConfirmSendEther}
|
|
|
|
/>
|
|
|
|
<Route
|
|
|
|
exact
|
|
|
|
path={`${CONFIRM_TRANSACTION_ROUTE}/:id?${CONFIRM_SEND_TOKEN_PATH}`}
|
|
|
|
component={ConfirmSendToken}
|
|
|
|
/>
|
|
|
|
<Route
|
|
|
|
exact
|
|
|
|
path={`${CONFIRM_TRANSACTION_ROUTE}/:id?${CONFIRM_APPROVE_PATH}`}
|
|
|
|
component={ConfirmApprove}
|
|
|
|
/>
|
2018-07-14 22:47:07 +02:00
|
|
|
<Route
|
|
|
|
exact
|
|
|
|
path={`${CONFIRM_TRANSACTION_ROUTE}/:id?${CONFIRM_TRANSFER_FROM_PATH}`}
|
|
|
|
component={ConfirmTokenTransactionBase}
|
|
|
|
/>
|
2018-06-25 21:06:57 +02:00
|
|
|
<Route
|
|
|
|
exact
|
|
|
|
path={`${CONFIRM_TRANSACTION_ROUTE}/:id?${SIGNATURE_REQUEST_PATH}`}
|
|
|
|
component={ConfTx}
|
|
|
|
/>
|
2018-07-06 20:58:41 +02:00
|
|
|
<Route path="*" component={ConfirmTransactionSwitch} />
|
2018-06-25 21:06:57 +02:00
|
|
|
</Switch>
|
|
|
|
)
|
|
|
|
: <Loading />
|
2018-06-23 08:52:45 +02:00
|
|
|
}
|
|
|
|
}
|