aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/modals/transaction-details/transaction-details.component.js
blob: f2fec3409bcc819828f92d9ec3c0280f74b49ee2 (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
import React, { PureComponent } from 'react'
import PropTypes from 'prop-types'
import Modal from '../../modal'
import TransactionListItemDetails from '../../transaction-list-item-details'
import { hexToDecimal } from '../../../helpers/conversions.util'

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

  static propTypes = {
    hideModal: PropTypes.func,
    transaction: PropTypes.object,
    onRetry: PropTypes.func,
    showRetry: PropTypes.bool,
    onCancel: PropTypes.func,
    showCancel: PropTypes.bool,
  }

  handleSubmit = () => {
    this.props.hideModal()
  }

  handleRetry = () => {
    const { onRetry, hideModal } = this.props

    Promise.resolve(onRetry()).then(() => hideModal())
  }

  render () {
    const { t } = this.context
    const { transaction, showRetry, onCancel, showCancel } = this.props
    const { txParams: { nonce } = {} } = transaction
    const decimalNonce = nonce && hexToDecimal(nonce)

    return (
      <Modal
        onSubmit={this.handleSubmit}
        onClose={this.handleSubmit}
        submitText={t('ok')}
        headerText={t('transactionWithNonce', [`#${decimalNonce}`])}
      >
        <TransactionListItemDetails
          transaction={transaction}
          onRetry={this.handleRetry}
          showRetry={showRetry}
          onCancel={() => onCancel()}
          showCancel={showCancel}
        />
      </Modal>
    )
  }
}