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.
161 lines
5.1 KiB
161 lines
5.1 KiB
7 years ago
|
import React, { Component } from 'react'
|
||
|
import PropTypes from 'prop-types'
|
||
|
import { Switch, Route } from 'react-router-dom'
|
||
6 years ago
|
import Loading from '../../components/ui/loading-screen'
|
||
7 years ago
|
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'
|
||
6 years ago
|
import ConfirmTokenTransactionBase from '../confirm-token-transaction-base'
|
||
6 years ago
|
import ConfTx from './conf-tx'
|
||
7 years ago
|
import {
|
||
|
DEFAULT_ROUTE,
|
||
|
CONFIRM_TRANSACTION_ROUTE,
|
||
7 years ago
|
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'
|
||
7 years ago
|
|
||
|
export default class ConfirmTransaction extends Component {
|
||
|
static propTypes = {
|
||
|
history: PropTypes.object.isRequired,
|
||
|
totalUnapprovedCount: PropTypes.number.isRequired,
|
||
|
match: PropTypes.object,
|
||
|
send: PropTypes.object,
|
||
7 years ago
|
unconfirmedTransactions: PropTypes.array,
|
||
|
setTransactionToConfirm: PropTypes.func,
|
||
|
confirmTransaction: PropTypes.object,
|
||
7 years ago
|
clearConfirmTransaction: PropTypes.func,
|
||
6 years ago
|
fetchBasicGasAndTimeEstimates: PropTypes.func,
|
||
7 years ago
|
}
|
||
|
|
||
|
getParamsTransactionId () {
|
||
|
const { match: { params: { id } = {} } } = this.props
|
||
|
return id || null
|
||
7 years ago
|
}
|
||
|
|
||
|
componentDidMount () {
|
||
7 years ago
|
const {
|
||
|
totalUnapprovedCount = 0,
|
||
|
send = {},
|
||
|
history,
|
||
|
confirmTransaction: { txData: { id: transactionId } = {} },
|
||
6 years ago
|
fetchBasicGasAndTimeEstimates,
|
||
7 years ago
|
} = this.props
|
||
7 years ago
|
|
||
|
if (!totalUnapprovedCount && !send.to) {
|
||
|
history.replace(DEFAULT_ROUTE)
|
||
7 years ago
|
return
|
||
|
}
|
||
|
|
||
|
if (!transactionId) {
|
||
6 years ago
|
fetchBasicGasAndTimeEstimates()
|
||
7 years ago
|
this.setTransactionToConfirm()
|
||
|
}
|
||
|
}
|
||
|
|
||
|
componentDidUpdate () {
|
||
|
const {
|
||
|
setTransactionToConfirm,
|
||
|
confirmTransaction: { txData: { id: transactionId } = {} },
|
||
7 years ago
|
clearConfirmTransaction,
|
||
7 years ago
|
} = this.props
|
||
7 years ago
|
const paramsTransactionId = this.getParamsTransactionId()
|
||
7 years ago
|
|
||
|
if (paramsTransactionId && transactionId && paramsTransactionId !== transactionId + '') {
|
||
7 years ago
|
clearConfirmTransaction()
|
||
7 years ago
|
setTransactionToConfirm(paramsTransactionId)
|
||
7 years ago
|
return
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
if (!transactionId) {
|
||
7 years ago
|
this.setTransactionToConfirm()
|
||
|
}
|
||
|
}
|
||
|
|
||
|
setTransactionToConfirm () {
|
||
|
const {
|
||
|
history,
|
||
|
unconfirmedTransactions,
|
||
|
setTransactionToConfirm,
|
||
|
} = this.props
|
||
7 years ago
|
const paramsTransactionId = this.getParamsTransactionId()
|
||
7 years ago
|
|
||
|
if (paramsTransactionId) {
|
||
|
// Check to make sure params ID is valid
|
||
7 years ago
|
const tx = unconfirmedTransactions.find(({ id }) => id + '' === paramsTransactionId)
|
||
7 years ago
|
|
||
|
if (!tx) {
|
||
|
history.replace(DEFAULT_ROUTE)
|
||
|
} else {
|
||
|
setTransactionToConfirm(paramsTransactionId)
|
||
|
}
|
||
|
} else if (unconfirmedTransactions.length) {
|
||
7 years ago
|
const totalUnconfirmed = unconfirmedTransactions.length
|
||
7 years ago
|
const transaction = unconfirmedTransactions[totalUnconfirmed - 1]
|
||
|
const { id: transactionId, loadingDefaults } = transaction
|
||
|
|
||
|
if (!loadingDefaults) {
|
||
|
setTransactionToConfirm(transactionId)
|
||
|
}
|
||
7 years ago
|
}
|
||
|
}
|
||
|
|
||
|
render () {
|
||
7 years ago
|
const { confirmTransaction: { txData: { id } } = {} } = this.props
|
||
7 years ago
|
const paramsTransactionId = this.getParamsTransactionId()
|
||
7 years ago
|
|
||
7 years ago
|
// 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 + '')
|
||
7 years ago
|
? (
|
||
|
<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}
|
||
|
/>
|
||
6 years ago
|
<Route
|
||
|
exact
|
||
|
path={`${CONFIRM_TRANSACTION_ROUTE}/:id?${CONFIRM_TRANSFER_FROM_PATH}`}
|
||
|
component={ConfirmTokenTransactionBase}
|
||
|
/>
|
||
7 years ago
|
<Route
|
||
|
exact
|
||
|
path={`${CONFIRM_TRANSACTION_ROUTE}/:id?${SIGNATURE_REQUEST_PATH}`}
|
||
|
component={ConfTx}
|
||
|
/>
|
||
7 years ago
|
<Route path="*" component={ConfirmTransactionSwitch} />
|
||
7 years ago
|
</Switch>
|
||
|
)
|
||
|
: <Loading />
|
||
7 years ago
|
}
|
||
|
}
|