aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/transaction-activity-log/transaction-activity-log.component.js
blob: c0cf099d0961fd02edb9cc9895cd0f750edc95db (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import React, { PureComponent } from 'react'
import PropTypes from 'prop-types'
import classnames from 'classnames'
import { getActivities } from './transaction-activity-log.util'
import Card from '../card'
import { getEthConversionFromWeiHex } from '../../helpers/conversions.util'
import { ETH } from '../../constants/common'

export default class TransactionActivityLog extends PureComponent {
  static contextTypes = {
    t: PropTypes.func,
  }

  static propTypes = {
    transaction: PropTypes.object,
    className: PropTypes.string,
    conversionRate: PropTypes.number,
  }

  state = {
    activities: [],
  }

  componentDidMount () {
    this.setActivites()
  }

  componentDidUpdate (prevProps) {
    const { transaction: { history: prevHistory = [] } = {} } = prevProps
    const { transaction: { history = [] } = {} } = this.props

    if (prevHistory.length !== history.length) {
      this.setActivites()
    }
  }

  setActivites () {
    const activities = getActivities(this.props.transaction)
    this.setState({ activities })
  }

  renderActivity (activity, index) {
    const { conversionRate } = this.props
    const { eventKey, value } = activity
    const ethValue = getEthConversionFromWeiHex({ value, toCurrency: ETH, conversionRate })

    return (
      <div
        key={index}
        className="transaction-activity-log__activity"
      >
        <div className="transaction-activity-log__activity-icon" />
        <div className="transaction-activity-log__activity-text">
          { this.context.t(eventKey, [ethValue]) }
        </div>
      </div>
    )
  }

  render () {
    const { t } = this.context
    const { className } = this.props
    const { activities } = this.state

    return (
      <div className={classnames('transaction-activity-log', className)}>
        <Card
          title={t('activityLog')}
          className="transaction-activity-log__card"
        >
          <div className="transaction-activity-log__activities-container">
            { activities.map((activity, index) => this.renderActivity(activity, index)) }
          </div>
        </Card>
      </div>
    )
  }
}