Refactor data flow, signature request routing

feature/default_network_editable
Alexander Tseung 7 years ago
parent ea9d51e427
commit e89549846f
  1. 15
      ui/app/components/pages/confirm-transaction-base/confirm-transaction-base.component.js
  2. 2
      ui/app/components/pages/confirm-transaction-base/confirm-transaction-base.container.js
  3. 59
      ui/app/components/pages/confirm-transaction-switch/confirm-transaction-switch.component.js
  4. 5
      ui/app/components/pages/confirm-transaction-switch/confirm-transaction-switch.container.js
  5. 126
      ui/app/components/pages/confirm-transaction/confirm-transaction.component.js
  6. 17
      ui/app/components/pages/confirm-transaction/confirm-transaction.container.js
  7. 3
      ui/app/conf-tx.js
  8. 48
      ui/app/ducks/confirm-transaction.duck.js
  9. 27
      ui/app/routes.js

@ -36,7 +36,6 @@ export default class ConfirmTransactionBase extends Component {
balance: PropTypes.string, balance: PropTypes.string,
currentCurrency: PropTypes.string, currentCurrency: PropTypes.string,
conversionRate: PropTypes.number, conversionRate: PropTypes.number,
setTransactionToConfirm: PropTypes.func,
clearConfirmTransaction: PropTypes.func, clearConfirmTransaction: PropTypes.func,
cancelTransaction: PropTypes.func, cancelTransaction: PropTypes.func,
clearSend: PropTypes.func, clearSend: PropTypes.func,
@ -66,20 +65,12 @@ export default class ConfirmTransactionBase extends Component {
onSubmit: PropTypes.func, onSubmit: PropTypes.func,
} }
componentDidMount () { componentDidUpdate () {
const { match: { params: { id } = {} }, setTransactionToConfirm } = this.props
setTransactionToConfirm(id)
}
componentDidUpdate (prevProps) {
const { const {
transactionStatus, transactionStatus,
showTransactionConfirmedModal, showTransactionConfirmedModal,
history, history,
clearConfirmTransaction, clearConfirmTransaction,
match: { params: { id } = {} },
setTransactionToConfirm,
txData,
} = this.props } = this.props
if (transactionStatus === 'dropped') { if (transactionStatus === 'dropped') {
@ -92,10 +83,6 @@ export default class ConfirmTransactionBase extends Component {
return return
} }
if (id && id !== txData.id + '') {
setTransactionToConfirm(id)
}
} }
getError () { getError () {

@ -4,7 +4,6 @@ import { withRouter } from 'react-router-dom'
import R from 'ramda' import R from 'ramda'
import ConfirmTransactionBase from './confirm-transaction-base.component' import ConfirmTransactionBase from './confirm-transaction-base.component'
import { import {
setTransactionToConfirm,
clearConfirmTransaction, clearConfirmTransaction,
updateGasAndCalculate, updateGasAndCalculate,
} from '../../../ducks/confirm-transaction.duck' } from '../../../ducks/confirm-transaction.duck'
@ -72,7 +71,6 @@ const mapStateToProps = (state, props) => {
const mapDispatchToProps = dispatch => { const mapDispatchToProps = dispatch => {
return { return {
setTransactionToConfirm: transactionId => dispatch(setTransactionToConfirm(transactionId)),
clearConfirmTransaction: () => dispatch(clearConfirmTransaction()), clearConfirmTransaction: () => dispatch(clearConfirmTransaction()),
clearSend: () => dispatch(clearSend()), clearSend: () => dispatch(clearSend()),
showTransactionConfirmedModal: ({ onHide }) => { showTransactionConfirmedModal: ({ onHide }) => {

@ -1,39 +1,30 @@
import React, { Component } from 'react' import React, { Component } from 'react'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import { Redirect } from 'react-router-dom' import { Redirect } from 'react-router-dom'
import R from 'ramda'
import Loading from '../../loading-screen' import Loading from '../../loading-screen'
import { import {
CONFIRM_DEPLOY_CONTRACT_ROUTE, CONFIRM_TRANSACTION_ROUTE,
CONFIRM_SEND_ETHER_ROUTE, CONFIRM_DEPLOY_CONTRACT_PATH,
CONFIRM_SEND_TOKEN_ROUTE, CONFIRM_SEND_ETHER_PATH,
CONFIRM_APPROVE_ROUTE, CONFIRM_SEND_TOKEN_PATH,
CONFIRM_TOKEN_METHOD_ROUTE, CONFIRM_APPROVE_PATH,
SIGNATURE_REQUEST_ROUTE, CONFIRM_TOKEN_METHOD_PATH,
SIGNATURE_REQUEST_PATH,
} from '../../../routes' } from '../../../routes'
import { isConfirmDeployContract, getTokenData } from './confirm-transaction-switch.util' import { isConfirmDeployContract, getTokenData } from './confirm-transaction-switch.util'
import { TOKEN_METHOD_TRANSFER, TOKEN_METHOD_APPROVE } from './confirm-transaction-switch.constants' import { TOKEN_METHOD_TRANSFER, TOKEN_METHOD_APPROVE } from './confirm-transaction-switch.constants'
export default class ConfirmTransactionSwitch extends Component { export default class ConfirmTransactionSwitch extends Component {
static propTypes = { static propTypes = {
unconfirmedTransactions: PropTypes.array, confirmTransaction: PropTypes.object,
match: PropTypes.object,
}
getTransaction () {
const { unconfirmedTransactions, match } = this.props
const { params: { id: paramsTransactionId } = {} } = match
return paramsTransactionId
? R.find(({ id }) => id + '' === paramsTransactionId)(unconfirmedTransactions)
: unconfirmedTransactions[0]
} }
redirectToTransaction (txData) { redirectToTransaction (txData) {
const { id, txParams: { data } } = txData const { id, txParams: { data } } = txData
if (isConfirmDeployContract(txData)) { if (isConfirmDeployContract(txData)) {
return <Redirect to={{ pathname: `${CONFIRM_DEPLOY_CONTRACT_ROUTE}/${id}` }} /> const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_DEPLOY_CONTRACT_PATH}`
return <Redirect to={{ pathname }} />
} }
if (data) { if (data) {
@ -41,29 +32,33 @@ export default class ConfirmTransactionSwitch extends Component {
const { name: tokenMethodName } = tokenData || {} const { name: tokenMethodName } = tokenData || {}
switch (tokenMethodName) { switch (tokenMethodName) {
case TOKEN_METHOD_TRANSFER: case TOKEN_METHOD_TRANSFER: {
return <Redirect to={{ pathname: `${CONFIRM_SEND_TOKEN_ROUTE}/${id}` }} /> const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_SEND_TOKEN_PATH}`
case TOKEN_METHOD_APPROVE: return <Redirect to={{ pathname }} />
return <Redirect to={{ pathname: `${CONFIRM_APPROVE_ROUTE}/${id}` }} /> }
default: case TOKEN_METHOD_APPROVE: {
return <Redirect to={{ pathname: `${CONFIRM_TOKEN_METHOD_ROUTE}/${id}` }} /> const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_APPROVE_PATH}`
return <Redirect to={{ pathname }} />
}
default: {
const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_TOKEN_METHOD_PATH}`
return <Redirect to={{ pathname }} />
}
} }
} }
return <Redirect to={{ pathname: `${CONFIRM_SEND_ETHER_ROUTE}/${id}` }} /> const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${id}${CONFIRM_SEND_ETHER_PATH}`
return <Redirect to={{ pathname }} />
} }
render () { render () {
const txData = this.getTransaction() const { confirmTransaction: { txData } } = this.props
if (!txData) {
return <Loading />
}
if (txData.txParams) { if (txData.txParams) {
return this.redirectToTransaction(txData) return this.redirectToTransaction(txData)
} else if (txData.msgParams) { } else if (txData.msgParams) {
return <Redirect to={{ pathname: SIGNATURE_REQUEST_ROUTE }} /> const pathname = `${CONFIRM_TRANSACTION_ROUTE}/${txData.id}${SIGNATURE_REQUEST_PATH}`
return <Redirect to={{ pathname }} />
} }
return <Loading /> return <Loading />

@ -1,10 +1,11 @@
import { connect } from 'react-redux' import { connect } from 'react-redux'
import ConfirmTransactionSwitch from './confirm-transaction-switch.component' import ConfirmTransactionSwitch from './confirm-transaction-switch.component'
import { unconfirmedTransactionsListSelector } from '../../../selectors/confirm-transaction'
const mapStateToProps = state => { const mapStateToProps = state => {
const { confirmTransaction } = state
return { return {
unconfirmedTransactions: unconfirmedTransactionsListSelector(state), confirmTransaction,
} }
} }

@ -1,6 +1,8 @@
import React, { Component } from 'react' import React, { Component } from 'react'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import { Switch, Route } from 'react-router-dom' import { Switch, Route } from 'react-router-dom'
import R from 'ramda'
import Loading from '../../loading-screen'
import ConfirmTransactionSwitch from '../confirm-transaction-switch' import ConfirmTransactionSwitch from '../confirm-transaction-switch'
import ConfirmTransactionBase from '../confirm-transaction-base' import ConfirmTransactionBase from '../confirm-transaction-base'
import ConfirmSendEther from '../confirm-send-ether' import ConfirmSendEther from '../confirm-send-ether'
@ -11,12 +13,12 @@ import ConfTx from '../../../conf-tx'
import { import {
DEFAULT_ROUTE, DEFAULT_ROUTE,
CONFIRM_TRANSACTION_ROUTE, CONFIRM_TRANSACTION_ROUTE,
CONFIRM_DEPLOY_CONTRACT_ROUTE, CONFIRM_DEPLOY_CONTRACT_PATH,
CONFIRM_SEND_ETHER_ROUTE, CONFIRM_SEND_ETHER_PATH,
CONFIRM_SEND_TOKEN_ROUTE, CONFIRM_SEND_TOKEN_PATH,
CONFIRM_APPROVE_ROUTE, CONFIRM_APPROVE_PATH,
CONFIRM_TOKEN_METHOD_ROUTE, CONFIRM_TOKEN_METHOD_PATH,
SIGNATURE_REQUEST_ROUTE, SIGNATURE_REQUEST_PATH,
} from '../../../routes' } from '../../../routes'
export default class ConfirmTransaction extends Component { export default class ConfirmTransaction extends Component {
@ -25,35 +27,107 @@ export default class ConfirmTransaction extends Component {
totalUnapprovedCount: PropTypes.number.isRequired, totalUnapprovedCount: PropTypes.number.isRequired,
match: PropTypes.object, match: PropTypes.object,
send: PropTypes.object, send: PropTypes.object,
unconfirmedTransactions: PropTypes.array,
setTransactionToConfirm: PropTypes.func,
confirmTransaction: PropTypes.object,
} }
componentDidMount () { componentDidMount () {
const { totalUnapprovedCount = 0, send = {}, history } = this.props const {
totalUnapprovedCount = 0,
send = {},
history,
confirmTransaction: { txData: { id: transactionId } = {} },
} = this.props
if (!totalUnapprovedCount && !send.to) { if (!totalUnapprovedCount && !send.to) {
history.replace(DEFAULT_ROUTE) history.replace(DEFAULT_ROUTE)
return
}
if (!transactionId) {
this.setTransactionToConfirm()
}
}
componentDidUpdate () {
const {
match: { params: { id: paramsTransactionId } = {} },
setTransactionToConfirm,
confirmTransaction: { txData: { id: transactionId } = {} },
} = this.props
if (paramsTransactionId && transactionId && paramsTransactionId !== transactionId + '') {
setTransactionToConfirm(paramsTransactionId)
}
if (!paramsTransactionId) {
this.setTransactionToConfirm()
}
}
setTransactionToConfirm () {
const {
history,
unconfirmedTransactions,
match: { params: { id: paramsTransactionId } = {} },
setTransactionToConfirm,
} = this.props
if (paramsTransactionId) {
// Check to make sure params ID is valid
const tx = R.find(({ id }) => id + '' === paramsTransactionId)(unconfirmedTransactions)
if (!tx) {
history.replace(DEFAULT_ROUTE)
} else {
setTransactionToConfirm(paramsTransactionId)
}
} else if (unconfirmedTransactions.length) {
const transactionId = unconfirmedTransactions[0].id
setTransactionToConfirm(transactionId)
} }
} }
render () { render () {
return ( const { confirmTransaction: { txData: { id } } = {} } = this.props
<Switch>
<Route return id
exact ? (
path={`${CONFIRM_DEPLOY_CONTRACT_ROUTE}/:id?`} <Switch>
component={ConfirmDeployContract} <Route
/> exact
<Route path={`${CONFIRM_TRANSACTION_ROUTE}/:id?${CONFIRM_DEPLOY_CONTRACT_PATH}`}
exact component={ConfirmDeployContract}
path={`${CONFIRM_TOKEN_METHOD_ROUTE}/:id?`} />
component={ConfirmTransactionBase} <Route
/> exact
<Route exact path={`${CONFIRM_SEND_ETHER_ROUTE}/:id?`} component={ConfirmSendEther} /> path={`${CONFIRM_TRANSACTION_ROUTE}/:id?${CONFIRM_TOKEN_METHOD_PATH}`}
<Route exact path={`${CONFIRM_SEND_TOKEN_ROUTE}/:id?`} component={ConfirmSendToken} /> component={ConfirmTransactionBase}
<Route exact path={`${CONFIRM_APPROVE_ROUTE}/:id?`} component={ConfirmApprove} /> />
<Route exact path={SIGNATURE_REQUEST_ROUTE} component={ConfTx} /> <Route
<Route path={`${CONFIRM_TRANSACTION_ROUTE}/:id?`} component={ConfirmTransactionSwitch} /> exact
</Switch> 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}
/>
<Route
exact
path={`${CONFIRM_TRANSACTION_ROUTE}/:id?${SIGNATURE_REQUEST_PATH}`}
component={ConfTx}
/>
<Route path={`${CONFIRM_TRANSACTION_ROUTE}/:id?`} component={ConfirmTransactionSwitch} />
</Switch>
)
: <Loading />
} }
} }

@ -1,19 +1,30 @@
import { connect } from 'react-redux' import { connect } from 'react-redux'
import { compose } from 'recompose' import { compose } from 'recompose'
import { withRouter } from 'react-router-dom' import { withRouter } from 'react-router-dom'
import { setTransactionToConfirm } from '../../../ducks/confirm-transaction.duck'
import ConfirmTransaction from './confirm-transaction.component' import ConfirmTransaction from './confirm-transaction.component'
import { getTotalUnapprovedCount } from '../../../selectors' import { getTotalUnapprovedCount } from '../../../selectors'
import { unconfirmedTransactionsListSelector } from '../../../selectors/confirm-transaction'
const mapStateToProps = (state, props) => { const mapStateToProps = state => {
const { metamask: { send } } = state const { metamask: { send }, confirmTransaction } = state
return { return {
totalUnapprovedCount: getTotalUnapprovedCount(state), totalUnapprovedCount: getTotalUnapprovedCount(state),
send, send,
confirmTransaction,
unconfirmedTransactions: unconfirmedTransactionsListSelector(state),
}
}
const mapDispatchToProps = dispatch => {
return {
setTransactionToConfirm: transactionId => dispatch(setTransactionToConfirm(transactionId)),
} }
} }
export default compose( export default compose(
withRouter, withRouter,
connect(mapStateToProps), connect(mapStateToProps, mapDispatchToProps),
)(ConfirmTransaction) )(ConfirmTransaction)

@ -105,7 +105,7 @@ ConfirmTxScreen.prototype.componentDidUpdate = function (prevProps) {
const unconfTxList = txHelper(unapprovedTxs, {}, {}, {}, network) const unconfTxList = txHelper(unapprovedTxs, {}, {}, {}, network)
if (prevTx.status === 'dropped') { if (prevTx && prevTx.status === 'dropped') {
this.props.dispatch(actions.showModal({ this.props.dispatch(actions.showModal({
name: 'TRANSACTION_CONFIRMED', name: 'TRANSACTION_CONFIRMED',
onHide: () => history.push(DEFAULT_ROUTE), onHide: () => history.push(DEFAULT_ROUTE),
@ -174,7 +174,6 @@ ConfirmTxScreen.prototype.render = function () {
]), ]),
*/ */
return currentTxView({ return currentTxView({
// Properties // Properties
txData: txData, txData: txData,

@ -284,30 +284,34 @@ export function setTransactionToConfirm (transactionId) {
return return
} }
const { lastGasPrice } = transaction if (transaction.txParams) {
const txData = lastGasPrice ? increaseFromLastGasPrice(transaction) : transaction const { lastGasPrice } = transaction
dispatch(updateTxDataAndCalculate(txData)) const txData = lastGasPrice ? increaseFromLastGasPrice(transaction) : transaction
dispatch(updateTxDataAndCalculate(txData))
const { txParams } = transaction
const { txParams } = transaction
if (txParams.data) {
const { tokens: existingTokens } = state if (txParams.data) {
const { data, to: tokenAddress } = txParams const { tokens: existingTokens } = state
const tokenData = getTokenData(data) const { data, to: tokenAddress } = txParams
dispatch(updateTokenData(tokenData)) const tokenData = getTokenData(data)
dispatch(updateTokenData(tokenData))
const tokenSymbolData = await getSymbolAndDecimals(tokenAddress, existingTokens) || {}
const { symbol: tokenSymbol = '', decimals: tokenDecimals = '' } = tokenSymbolData const tokenSymbolData = await getSymbolAndDecimals(tokenAddress, existingTokens) || {}
dispatch(updateTokenProps({ tokenSymbol, tokenDecimals })) const { symbol: tokenSymbol = '', decimals: tokenDecimals = '' } = tokenSymbolData
} dispatch(updateTokenProps({ tokenSymbol, tokenDecimals }))
}
if (txParams.nonce) { if (txParams.nonce) {
const nonce = conversionUtil(txParams.nonce, { const nonce = conversionUtil(txParams.nonce, {
fromNumericBase: 'hex', fromNumericBase: 'hex',
toNumericBase: 'dec', toNumericBase: 'dec',
}) })
dispatch(updateNonce(nonce)) dispatch(updateNonce(nonce))
}
} else {
dispatch(updateTxData(transaction))
} }
} }
} }

@ -21,14 +21,13 @@ const INITIALIZE_NOTICE_ROUTE = '/initialize/notice'
const INITIALIZE_BACKUP_PHRASE_ROUTE = '/initialize/backup-phrase' const INITIALIZE_BACKUP_PHRASE_ROUTE = '/initialize/backup-phrase'
const INITIALIZE_CONFIRM_SEED_ROUTE = '/initialize/confirm-phrase' const INITIALIZE_CONFIRM_SEED_ROUTE = '/initialize/confirm-phrase'
const CONFIRM_TRANSACTION_BASE = '/confirm-transaction' const CONFIRM_TRANSACTION_ROUTE = '/confirm-transaction'
const CONFIRM_TRANSACTION_ROUTE = `${CONFIRM_TRANSACTION_BASE}` const CONFIRM_SEND_ETHER_PATH = '/send-ether'
const CONFIRM_SEND_ETHER_ROUTE = `${CONFIRM_TRANSACTION_BASE}/send-ether` const CONFIRM_SEND_TOKEN_PATH = '/send-token'
const CONFIRM_SEND_TOKEN_ROUTE = `${CONFIRM_TRANSACTION_BASE}/send-token` const CONFIRM_DEPLOY_CONTRACT_PATH = '/deploy-contract'
const CONFIRM_DEPLOY_CONTRACT_ROUTE = `${CONFIRM_TRANSACTION_BASE}/deploy-contract` const CONFIRM_APPROVE_PATH = '/approve'
const CONFIRM_APPROVE_ROUTE = `${CONFIRM_TRANSACTION_BASE}/approve` const CONFIRM_TOKEN_METHOD_PATH = '/token-method'
const CONFIRM_TOKEN_METHOD_ROUTE = `${CONFIRM_TRANSACTION_BASE}/token-method` const SIGNATURE_REQUEST_PATH = '/signature-request'
const SIGNATURE_REQUEST_ROUTE = `${CONFIRM_TRANSACTION_BASE}/signature-request`
module.exports = { module.exports = {
DEFAULT_ROUTE, DEFAULT_ROUTE,
@ -54,10 +53,10 @@ module.exports = {
INITIALIZE_BACKUP_PHRASE_ROUTE, INITIALIZE_BACKUP_PHRASE_ROUTE,
INITIALIZE_CONFIRM_SEED_ROUTE, INITIALIZE_CONFIRM_SEED_ROUTE,
CONFIRM_TRANSACTION_ROUTE, CONFIRM_TRANSACTION_ROUTE,
CONFIRM_SEND_ETHER_ROUTE, CONFIRM_SEND_ETHER_PATH,
CONFIRM_SEND_TOKEN_ROUTE, CONFIRM_SEND_TOKEN_PATH,
CONFIRM_DEPLOY_CONTRACT_ROUTE, CONFIRM_DEPLOY_CONTRACT_PATH,
CONFIRM_APPROVE_ROUTE, CONFIRM_APPROVE_PATH,
CONFIRM_TOKEN_METHOD_ROUTE, CONFIRM_TOKEN_METHOD_PATH,
SIGNATURE_REQUEST_ROUTE, SIGNATURE_REQUEST_PATH,
} }

Loading…
Cancel
Save