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'
|
2019-03-22 00:03:30 +01:00
|
|
|
import Loading from '../../components/ui/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'
|
2019-03-22 00:03:30 +01:00
|
|
|
import ConfTx from './conf-tx'
|
2018-06-23 08:52:45 +02:00
|
|
|
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,
|
2019-03-22 00:03:30 +01:00
|
|
|
} from '../../helpers/constants/routes'
|
2018-06-23 08:52:45 +02:00
|
|
|
|
|
|
|
export default class ConfirmTransaction extends Component {
|
2019-09-24 23:08:38 +02:00
|
|
|
static contextTypes = {
|
|
|
|
metricsEvent: PropTypes.func,
|
|
|
|
}
|
|
|
|
|
2018-06-23 08:52:45 +02:00
|
|
|
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,
|
2018-11-13 17:36:52 +01:00
|
|
|
fetchBasicGasAndTimeEstimates: PropTypes.func,
|
2019-06-18 14:17:14 +02:00
|
|
|
transaction: PropTypes.object,
|
|
|
|
getContractMethodData: PropTypes.func,
|
|
|
|
transactionId: PropTypes.string,
|
|
|
|
paramsTransactionId: PropTypes.string,
|
2019-06-28 05:53:12 +02:00
|
|
|
getTokenParams: PropTypes.func,
|
|
|
|
isTokenMethodAction: PropTypes.bool,
|
2019-09-24 23:08:38 +02:00
|
|
|
fullScreenVsPopupTestGroup: PropTypes.string,
|
|
|
|
trackABTest: PropTypes.bool,
|
2019-11-04 13:40:46 +01:00
|
|
|
conversionRate: PropTypes.number,
|
2018-07-06 20:58:41 +02:00
|
|
|
}
|
|
|
|
|
2018-06-23 08:52:45 +02:00
|
|
|
componentDidMount () {
|
2018-06-25 21:06:57 +02:00
|
|
|
const {
|
|
|
|
totalUnapprovedCount = 0,
|
|
|
|
send = {},
|
|
|
|
history,
|
2019-06-28 05:53:12 +02:00
|
|
|
transaction: { txParams: { data, to } = {} } = {},
|
2018-11-13 17:36:52 +01:00
|
|
|
fetchBasicGasAndTimeEstimates,
|
2019-06-18 14:17:14 +02:00
|
|
|
getContractMethodData,
|
|
|
|
transactionId,
|
|
|
|
paramsTransactionId,
|
2019-06-28 05:53:12 +02:00
|
|
|
getTokenParams,
|
|
|
|
isTokenMethodAction,
|
2019-09-24 23:08:38 +02:00
|
|
|
fullScreenVsPopupTestGroup,
|
|
|
|
trackABTest,
|
2018-06-25 21:06:57 +02:00
|
|
|
} = 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
|
|
|
|
}
|
|
|
|
|
2019-06-18 14:17:14 +02:00
|
|
|
fetchBasicGasAndTimeEstimates()
|
|
|
|
getContractMethodData(data)
|
2019-06-28 05:53:12 +02:00
|
|
|
if (isTokenMethodAction) {
|
|
|
|
getTokenParams(to)
|
|
|
|
}
|
2019-08-26 14:04:48 +02:00
|
|
|
const txId = transactionId || paramsTransactionId
|
2019-11-20 01:03:20 +01:00
|
|
|
if (txId) {
|
|
|
|
this.props.setTransactionToConfirm(txId)
|
|
|
|
}
|
2019-09-24 23:08:38 +02:00
|
|
|
|
|
|
|
if (trackABTest) {
|
|
|
|
this.context.metricsEvent({
|
|
|
|
eventOpts: {
|
|
|
|
category: 'abtesting',
|
|
|
|
action: 'fullScreenVsPopup',
|
|
|
|
name: fullScreenVsPopupTestGroup === 'fullScreen' ? 'fullscreen' : 'original',
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2018-06-25 21:06:57 +02:00
|
|
|
}
|
|
|
|
|
2019-06-18 14:17:14 +02:00
|
|
|
componentDidUpdate (prevProps) {
|
2018-06-25 21:06:57 +02:00
|
|
|
const {
|
|
|
|
setTransactionToConfirm,
|
2019-06-18 14:17:14 +02:00
|
|
|
transaction: { txData: { txParams: { data } = {} } = {} },
|
2018-07-06 20:58:41 +02:00
|
|
|
clearConfirmTransaction,
|
2019-06-18 14:17:14 +02:00
|
|
|
getContractMethodData,
|
|
|
|
paramsTransactionId,
|
|
|
|
transactionId,
|
|
|
|
history,
|
|
|
|
totalUnapprovedCount,
|
2018-06-25 21:06:57 +02:00
|
|
|
} = this.props
|
|
|
|
|
2019-06-18 14:17:14 +02:00
|
|
|
if (paramsTransactionId && transactionId && prevProps.paramsTransactionId !== paramsTransactionId) {
|
2018-07-06 20:58:41 +02:00
|
|
|
clearConfirmTransaction()
|
2019-06-18 14:17:14 +02:00
|
|
|
getContractMethodData(data)
|
2018-06-25 21:06:57 +02:00
|
|
|
setTransactionToConfirm(paramsTransactionId)
|
2018-07-06 20:58:41 +02:00
|
|
|
return
|
2019-06-18 14:17:14 +02:00
|
|
|
} else if (prevProps.transactionId && !transactionId && !totalUnapprovedCount) {
|
|
|
|
history.replace(DEFAULT_ROUTE)
|
|
|
|
return
|
|
|
|
} else if (prevProps.transactionId && transactionId && prevProps.transactionId !== transactionId) {
|
|
|
|
history.replace(DEFAULT_ROUTE)
|
|
|
|
return
|
2018-06-23 08:52:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
2019-06-18 14:17:14 +02:00
|
|
|
const { transactionId, paramsTransactionId } = this.props
|
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>
|
2019-06-18 14:17:14 +02:00
|
|
|
return transactionId && (!paramsTransactionId || paramsTransactionId === transactionId)
|
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
|
|
|
}
|
|
|
|
}
|