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