aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components
diff options
context:
space:
mode:
Diffstat (limited to 'ui/app/components')
-rw-r--r--ui/app/components/app/transaction-action/tests/transaction-action.component.test.js63
-rw-r--r--ui/app/components/app/transaction-action/transaction-action.component.js36
-rw-r--r--ui/app/components/app/transaction-list-item/transaction-list-item.component.js10
-rw-r--r--ui/app/components/app/transaction-list-item/transaction-list-item.container.js14
4 files changed, 32 insertions, 91 deletions
diff --git a/ui/app/components/app/transaction-action/tests/transaction-action.component.test.js b/ui/app/components/app/transaction-action/tests/transaction-action.component.test.js
index b22a9db39..16f2e256f 100644
--- a/ui/app/components/app/transaction-action/tests/transaction-action.component.test.js
+++ b/ui/app/components/app/transaction-action/tests/transaction-action.component.test.js
@@ -18,33 +18,6 @@ describe('TransactionAction Component', () => {
}
})
- it('should render -- when methodData is still fetching', () => {
- const methodData = { data: {}, done: false, error: null }
- const transaction = {
- id: 1,
- status: 'confirmed',
- submittedTime: 1534045442919,
- time: 1534045440641,
- txParams: {
- from: '0xc5ae6383e126f901dcb06131d97a88745bfa88d6',
- gas: '0x5208',
- gasPrice: '0x3b9aca00',
- nonce: '0x96',
- to: '0x50a9d56c2b8ba9a5c7f2c08c3d26e0499f23a706',
- value: '0x2386f26fc10000',
- },
- }
-
- const wrapper = shallow(<TransactionAction
- methodData={methodData}
- transaction={transaction}
- className="transaction-action"
- />, { context: { t }})
-
- assert.equal(wrapper.find('.transaction-action').length, 1)
- assert.equal(wrapper.text(), '--')
- })
-
it('should render Sent Ether', () => {
const methodData = { data: {}, done: true, error: null }
const transaction = {
@@ -75,15 +48,7 @@ describe('TransactionAction Component', () => {
it('should render Approved', async () => {
const methodData = {
- data: {
- name: 'Approve',
- params: [
- { type: 'address' },
- { type: 'uint256' },
- ],
- },
- done: true,
- error: null,
+ name: 'Approve',
}
const transaction = {
id: 1,
@@ -99,6 +64,7 @@ describe('TransactionAction Component', () => {
value: '0x2386f26fc10000',
data: '0x095ea7b300000000000000000000000050a9d56c2b8ba9a5c7f2c08c3d26e0499f23a7060000000000000000000000000000000000000000000000000000000000000003',
},
+ transactionCategory: 'contractInteraction',
}
const wrapper = shallow(
@@ -111,23 +77,12 @@ describe('TransactionAction Component', () => {
)
assert.ok(wrapper)
- assert.equal(wrapper.find('.test-class').length, 1)
- await wrapper.instance().getTransactionAction()
- assert.equal(wrapper.state('transactionAction'), 'approve')
+ assert.equal(wrapper.find('.transaction-action').length, 1)
+ assert.equal(wrapper.find('.transaction-action').text().trim(), 'Approve')
})
- it('should render Accept Fulfillment', async () => {
- const methodData = {
- data: {
- name: 'AcceptFulfillment',
- params: [
- { type: 'address' },
- { type: 'uint256' },
- ],
- },
- done: true,
- error: null,
- }
+ it('should render contractInteraction', async () => {
+ const methodData = {}
const transaction = {
id: 1,
status: 'confirmed',
@@ -142,6 +97,7 @@ describe('TransactionAction Component', () => {
value: '0x2386f26fc10000',
data: '0x095ea7b300000000000000000000000050a9d56c2b8ba9a5c7f2c08c3d26e0499f23a7060000000000000000000000000000000000000000000000000000000000000003',
},
+ transactionCategory: 'contractInteraction',
}
const wrapper = shallow(
@@ -154,9 +110,8 @@ describe('TransactionAction Component', () => {
)
assert.ok(wrapper)
- assert.equal(wrapper.find('.test-class').length, 1)
- await wrapper.instance().getTransactionAction()
- assert.equal(wrapper.state('transactionAction'), ' Accept Fulfillment')
+ assert.equal(wrapper.find('.transaction-action').length, 1)
+ assert.equal(wrapper.find('.transaction-action').text().trim(), 'contractInteraction')
})
})
})
diff --git a/ui/app/components/app/transaction-action/transaction-action.component.js b/ui/app/components/app/transaction-action/transaction-action.component.js
index 4a5efdaae..26012ff7f 100644
--- a/ui/app/components/app/transaction-action/transaction-action.component.js
+++ b/ui/app/components/app/transaction-action/transaction-action.component.js
@@ -15,43 +15,23 @@ export default class TransactionAction extends PureComponent {
methodData: PropTypes.object,
}
- state = {
- transactionAction: '',
- }
-
- componentDidMount () {
- this.getTransactionAction()
- }
-
- componentDidUpdate () {
- this.getTransactionAction()
- }
-
- async getTransactionAction () {
- const { transactionAction } = this.state
+ getTransactionAction () {
const { transaction, methodData } = this.props
- const { data, done } = methodData
- const { name = '' } = data
-
- if (!done || transactionAction) {
- return
- }
+ const { name } = methodData
- const actionKey = await getTransactionActionKey(transaction, data)
- const action = actionKey
- ? this.context.t(actionKey)
- : camelCaseToCapitalize(name)
+ const actionKey = getTransactionActionKey(transaction)
+ const action = actionKey && this.context.t(actionKey)
+ const methodName = name && camelCaseToCapitalize(name)
- this.setState({ transactionAction: action })
+ return methodName || action || ''
}
render () {
- const { className, methodData: { done } } = this.props
- const { transactionAction } = this.state
+ const { className } = this.props
return (
<div className={classnames('transaction-action', className)}>
- { (done && transactionAction) || '--' }
+ { this.getTransactionAction() }
</div>
)
}
diff --git a/ui/app/components/app/transaction-list-item/transaction-list-item.component.js b/ui/app/components/app/transaction-list-item/transaction-list-item.component.js
index 80b26469b..8bdb6a313 100644
--- a/ui/app/components/app/transaction-list-item/transaction-list-item.component.js
+++ b/ui/app/components/app/transaction-list-item/transaction-list-item.component.js
@@ -34,6 +34,8 @@ export default class TransactionListItem extends PureComponent {
fetchBasicGasAndTimeEstimates: PropTypes.func,
fetchGasEstimates: PropTypes.func,
rpcPrefs: PropTypes.object,
+ data: PropTypes.string,
+ getContractMethodData: PropTypes.func,
}
static defaultProps = {
@@ -150,6 +152,12 @@ export default class TransactionListItem extends PureComponent {
)
}
+ componentDidMount () {
+ if (this.props.data) {
+ this.props.getContractMethodData(this.props.data)
+ }
+ }
+
render () {
const {
assetImages,
@@ -214,7 +222,7 @@ export default class TransactionListItem extends PureComponent {
<TransactionListItemDetails
transactionGroup={transactionGroup}
onRetry={this.handleRetry}
- showRetry={showRetry && methodData.done}
+ showRetry={showRetry}
onCancel={this.handleCancel}
showCancel={showCancel}
cancelDisabled={!hasEnoughCancelGas}
diff --git a/ui/app/components/app/transaction-list-item/transaction-list-item.container.js b/ui/app/components/app/transaction-list-item/transaction-list-item.container.js
index 5e88a2937..1675958aa 100644
--- a/ui/app/components/app/transaction-list-item/transaction-list-item.container.js
+++ b/ui/app/components/app/transaction-list-item/transaction-list-item.container.js
@@ -1,9 +1,8 @@
import { connect } from 'react-redux'
import { withRouter } from 'react-router-dom'
import { compose } from 'recompose'
-import withMethodData from '../../../helpers/higher-order-components/with-method-data'
import TransactionListItem from './transaction-list-item.component'
-import { setSelectedToken, showModal, showSidebar, addKnownMethodData } from '../../../store/actions'
+import { setSelectedToken, showModal, showSidebar, getContractMethodData } from '../../../store/actions'
import { hexToDecimal } from '../../../helpers/utils/conversions.util'
import { getTokenData } from '../../../helpers/utils/transactions.util'
import { getHexGasTotal, increaseLastGasPrice } from '../../../helpers/utils/confirm-tx.util'
@@ -14,15 +13,15 @@ import {
setCustomGasPriceForRetry,
setCustomGasLimit,
} from '../../../ducks/gas/gas.duck'
-import { getIsMainnet, preferencesSelector, getSelectedAddress, conversionRateSelector } from '../../../selectors/selectors'
+import { getIsMainnet, preferencesSelector, getSelectedAddress, conversionRateSelector, getKnownMethodData } from '../../../selectors/selectors'
import { isBalanceSufficient } from '../../../pages/send/send.utils'
const mapStateToProps = (state, ownProps) => {
- const { metamask: { knownMethodData, accounts, provider, frequentRpcListDetail } } = state
+ const { metamask: { accounts, provider, frequentRpcListDetail } } = state
const { showFiatInTestnets } = preferencesSelector(state)
const isMainnet = getIsMainnet(state)
const { transactionGroup: { primaryTransaction } = {} } = ownProps
- const { txParams: { gas: gasLimit, gasPrice } = {} } = primaryTransaction
+ const { txParams: { gas: gasLimit, gasPrice, data } = {} } = primaryTransaction
const selectedAccountBalance = accounts[getSelectedAddress(state)].balance
const selectRpcInfo = frequentRpcListDetail.find(rpcInfo => rpcInfo.rpcUrl === provider.rpcTarget)
const { rpcPrefs } = selectRpcInfo || {}
@@ -38,7 +37,7 @@ const mapStateToProps = (state, ownProps) => {
})
return {
- knownMethodData,
+ methodData: getKnownMethodData(state, data) || {},
showFiat: (isMainnet || !!showFiatInTestnets),
selectedAccountBalance,
hasEnoughCancelGas,
@@ -51,7 +50,7 @@ const mapDispatchToProps = dispatch => {
fetchBasicGasAndTimeEstimates: () => dispatch(fetchBasicGasAndTimeEstimates()),
fetchGasEstimates: (blockTime) => dispatch(fetchGasEstimates(blockTime)),
setSelectedToken: tokenAddress => dispatch(setSelectedToken(tokenAddress)),
- addKnownMethodData: (fourBytePrefix, methodData) => dispatch(addKnownMethodData(fourBytePrefix, methodData)),
+ getContractMethodData: methodData => dispatch(getContractMethodData(methodData)),
retryTransaction: (transaction, gasPrice) => {
dispatch(setCustomGasPriceForRetry(gasPrice || transaction.txParams.gasPrice))
dispatch(setCustomGasLimit(transaction.txParams.gas))
@@ -97,5 +96,4 @@ const mergeProps = (stateProps, dispatchProps, ownProps) => {
export default compose(
withRouter,
connect(mapStateToProps, mapDispatchToProps, mergeProps),
- withMethodData,
)(TransactionListItem)