2018-08-26 03:00:38 +02:00
|
|
|
import React, { PureComponent } from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
2018-08-31 21:34:22 +02:00
|
|
|
import classnames from 'classnames'
|
2018-08-26 03:00:38 +02:00
|
|
|
import { getActivities } from './transaction-activity-log.util'
|
|
|
|
import Card from '../card'
|
2018-09-07 22:59:05 +02:00
|
|
|
import { getEthConversionFromWeiHex, getValueFromWeiHex } from '../../helpers/conversions.util'
|
|
|
|
import { formatDate } from '../../util'
|
2018-08-26 03:00:38 +02:00
|
|
|
|
|
|
|
export default class TransactionActivityLog extends PureComponent {
|
|
|
|
static contextTypes = {
|
|
|
|
t: PropTypes.func,
|
|
|
|
}
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
transaction: PropTypes.object,
|
2018-08-31 21:34:22 +02:00
|
|
|
className: PropTypes.string,
|
|
|
|
conversionRate: PropTypes.number,
|
2018-10-26 10:26:43 +02:00
|
|
|
nativeCurrency: PropTypes.string,
|
2018-08-26 03:00:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
state = {
|
|
|
|
activities: [],
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount () {
|
|
|
|
this.setActivites()
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate (prevProps) {
|
2018-10-23 13:59:04 +02:00
|
|
|
const {
|
|
|
|
transaction: { history: prevHistory = [], txReceipt: { status: prevStatus } = {} } = {},
|
|
|
|
} = prevProps
|
|
|
|
const {
|
|
|
|
transaction: { history = [], txReceipt: { status } = {} } = {},
|
|
|
|
} = this.props
|
|
|
|
|
|
|
|
if (prevHistory.length !== history.length || prevStatus !== status) {
|
2018-08-26 03:00:38 +02:00
|
|
|
this.setActivites()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setActivites () {
|
|
|
|
const activities = getActivities(this.props.transaction)
|
|
|
|
this.setState({ activities })
|
|
|
|
}
|
|
|
|
|
|
|
|
renderActivity (activity, index) {
|
2018-10-26 10:26:43 +02:00
|
|
|
const { conversionRate, nativeCurrency } = this.props
|
2018-09-07 22:59:05 +02:00
|
|
|
const { eventKey, value, timestamp } = activity
|
|
|
|
const ethValue = index === 0
|
|
|
|
? `${getValueFromWeiHex({
|
|
|
|
value,
|
2018-10-26 10:26:43 +02:00
|
|
|
fromCurrency: nativeCurrency,
|
|
|
|
toCurrency: nativeCurrency,
|
2018-09-07 22:59:05 +02:00
|
|
|
conversionRate,
|
|
|
|
numberOfDecimals: 6,
|
2018-10-26 10:26:43 +02:00
|
|
|
})} ${nativeCurrency}`
|
|
|
|
: getEthConversionFromWeiHex({ value, fromCurrency: nativeCurrency, conversionRate })
|
2018-09-07 22:59:05 +02:00
|
|
|
const formattedTimestamp = formatDate(timestamp)
|
|
|
|
const activityText = this.context.t(eventKey, [ethValue, formattedTimestamp])
|
2018-08-31 21:34:22 +02:00
|
|
|
|
2018-08-26 03:00:38 +02:00
|
|
|
return (
|
|
|
|
<div
|
|
|
|
key={index}
|
|
|
|
className="transaction-activity-log__activity"
|
|
|
|
>
|
|
|
|
<div className="transaction-activity-log__activity-icon" />
|
2018-09-07 22:59:05 +02:00
|
|
|
<div
|
|
|
|
className="transaction-activity-log__activity-text"
|
|
|
|
title={activityText}
|
|
|
|
>
|
|
|
|
{ activityText }
|
2018-08-31 21:34:22 +02:00
|
|
|
</div>
|
2018-08-26 03:00:38 +02:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
const { t } = this.context
|
2018-08-31 21:34:22 +02:00
|
|
|
const { className } = this.props
|
2018-08-26 03:00:38 +02:00
|
|
|
const { activities } = this.state
|
|
|
|
|
|
|
|
return (
|
2018-08-31 21:34:22 +02:00
|
|
|
<div className={classnames('transaction-activity-log', className)}>
|
2018-08-26 03:00:38 +02:00
|
|
|
<Card
|
|
|
|
title={t('activityLog')}
|
|
|
|
className="transaction-activity-log__card"
|
|
|
|
>
|
|
|
|
<div className="transaction-activity-log__activities-container">
|
2018-08-31 21:34:22 +02:00
|
|
|
{ activities.map((activity, index) => this.renderActivity(activity, index)) }
|
2018-08-26 03:00:38 +02:00
|
|
|
</div>
|
|
|
|
</Card>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|