aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/transaction-list-item.js
blob: fc1c3c6307cfae37179aff76a33df9be22af8d85 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
const Component = require('react').Component
const h = require('react-hyperscript')
const inherits = require('util').inherits

const EtherBalance = require('./eth-balance')
const addressSummary = require('../util').addressSummary
const explorerLink = require('../../lib/explorer-link')
const formatBalance = require('../util').formatBalance
const vreme = new (require('vreme'))

const TransactionIcon = require('./transaction-list-item-icon')

module.exports = TransactionListItem


inherits(TransactionListItem, Component)
function TransactionListItem() {
  Component.call(this)
}

TransactionListItem.prototype.render = function() {
  const { transaction, i, network } = this.props

  var date = formatDate(transaction.time)

  let isLinkable = false
  const numericNet = parseInt(network)
  isLinkable = numericNet === 1 || numericNet === 2

  var isMsg = ('msgParams' in transaction)
  var isTx = ('txParams' in transaction)
  var isPending = transaction.status === 'unconfirmed'

  let txParams
  if (isTx) {
    txParams = transaction.txParams
  } else if (isMsg) {
    txParams = transaction.msgParams
  }

  const isClickable = ('hash' in transaction && isLinkable) || isPending

  return (
    h(`.transaction-list-item.flex-row.flex-space-between${isClickable ? '.pointer' : ''}`, {
      key: `tx-${transaction.id + i}`,
      onClick: (event) => {
        if (isPending) {
          this.props.showTx(transaction.id)
        }

        if (!transaction.hash || !isLinkable) return
        var url = explorerLink(transaction.hash, parseInt(network))
        chrome.tabs.create({ url })
      },
      style: {
        padding: '20px 0',
      },
    }, [

      // large identicon
      h('.identicon-wrapper.flex-column.flex-center.select-none', [
        transaction.status === 'unconfirmed' ? h('.red-dot', ' ') :
        h(TransactionIcon, { txParams, transaction, isTx, isMsg }),
      ]),

      h('.flex-column', [
        domainField(txParams),
        h('div', date),
        recipientField(txParams, transaction, isTx, isMsg),
      ]),

      isTx ? h(EtherBalance, {
        value: txParams.value,
      }) : h('.flex-column'),
    ])
  )
}

function domainField(txParams) {
  return h('div', {
    style: {
      fontSize: 'small',
      color: '#ABA9AA',
    },
  },[
    txParams.origin,
  ])
}

function recipientField(txParams, transaction, isTx, isMsg) {
  let message

  if (isMsg) {
    message = 'Signature Requested'
  } else if (txParams.to) {
    message =  addressSummary(txParams.to)
  } else {
    message = 'Contract Published'
  }

  return h('div', {
    style: {
      fontSize: 'small',
      color: '#ABA9AA',
    },
  },[
    message,
    failIfFailed(transaction),
  ])

}

TransactionListItem.prototype.renderMessage = function() {
  const { transaction, i, network } = this.props
  return h('div', 'wowie, thats a message')
}

function formatDate(date){
  return vreme.format(new Date(date), 'March 16 2014 14:30')
}

function failIfFailed(transaction) {
  if (transaction.status === 'rejected') {
    return h('span.error', ' (Rejected)')
  }
  if (transaction.status === 'failed') {
    return h('span.error', ' (Failed)')
  }
}