1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-13 21:27:12 +01:00
metamask-extension/ui/app/components/transaction-action/transaction-action.component.js

59 lines
1.4 KiB
JavaScript
Raw Normal View History

import React, { PureComponent } from 'react'
import PropTypes from 'prop-types'
import classnames from 'classnames'
import { getTransactionActionKey } from '../../helpers/transactions.util'
import { camelCaseToCapitalize } from '../../helpers/common.util'
export default class TransactionAction extends PureComponent {
static contextTypes = {
2018-09-17 19:09:48 +02:00
t: PropTypes.func,
}
static propTypes = {
className: PropTypes.string,
transaction: PropTypes.object,
methodData: PropTypes.object,
}
state = {
transactionAction: '',
}
componentDidMount () {
this.getTransactionAction()
}
componentDidUpdate () {
this.getTransactionAction()
}
async getTransactionAction () {
const { transactionAction } = this.state
const { transaction, methodData } = this.props
2018-08-07 10:57:46 +02:00
const { data, done } = methodData
2018-10-05 22:02:55 +02:00
const { name = '' } = data
2018-08-07 10:57:46 +02:00
if (!done || transactionAction) {
return
}
const actionKey = await getTransactionActionKey(transaction, data)
const action = actionKey
? this.context.t(actionKey)
: camelCaseToCapitalize(name)
this.setState({ transactionAction: action })
}
render () {
const { className, methodData: { done } } = this.props
const { transactionAction } = this.state
return (
<div className={classnames('transaction-action', className)}>
{ (done && transactionAction) || '--' }
</div>
)
}
}