2016-05-26 02:57:08 +02:00
|
|
|
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'))
|
|
|
|
|
2016-05-26 23:12:41 +02:00
|
|
|
const TransactionIcon = require('./transaction-list-item-icon')
|
|
|
|
|
2016-05-26 02:57:08 +02:00
|
|
|
module.exports = TransactionListItem
|
|
|
|
|
|
|
|
|
|
|
|
inherits(TransactionListItem, Component)
|
|
|
|
function TransactionListItem() {
|
|
|
|
Component.call(this)
|
|
|
|
}
|
|
|
|
|
|
|
|
TransactionListItem.prototype.render = function() {
|
2016-05-26 23:50:01 +02:00
|
|
|
const { transaction, i, network } = this.props
|
2016-05-26 02:57:08 +02:00
|
|
|
|
|
|
|
var date = formatDate(transaction.time)
|
|
|
|
|
2016-05-26 23:59:05 +02:00
|
|
|
let isLinkable = false
|
2016-05-27 00:00:37 +02:00
|
|
|
const numericNet = parseInt(network)
|
|
|
|
isLinkable = numericNet === 1 || numericNet === 2
|
2016-05-26 23:59:05 +02:00
|
|
|
|
2016-05-26 02:57:08 +02:00
|
|
|
var isMsg = ('msgParams' in transaction)
|
|
|
|
var isTx = ('txParams' in transaction)
|
2016-05-26 23:32:45 +02:00
|
|
|
var isPending = transaction.status === 'unconfirmed'
|
2016-05-26 02:57:08 +02:00
|
|
|
|
2016-05-26 23:12:41 +02:00
|
|
|
let txParams
|
|
|
|
if (isTx) {
|
|
|
|
txParams = transaction.txParams
|
|
|
|
} else if (isMsg) {
|
|
|
|
txParams = transaction.msgParams
|
|
|
|
}
|
2016-05-26 02:57:08 +02:00
|
|
|
|
2016-05-26 23:59:05 +02:00
|
|
|
const isClickable = ('hash' in transaction && isLinkable) || isPending
|
2016-05-26 23:32:45 +02:00
|
|
|
|
2016-05-26 02:57:08 +02:00
|
|
|
return (
|
2016-05-26 23:32:45 +02:00
|
|
|
h(`.transaction-list-item.flex-row.flex-space-between${isClickable ? '.pointer' : ''}`, {
|
2016-05-26 02:57:08 +02:00
|
|
|
key: `tx-${transaction.id + i}`,
|
|
|
|
onClick: (event) => {
|
2016-05-26 23:32:45 +02:00
|
|
|
if (isPending) {
|
|
|
|
this.props.showTx(transaction.id)
|
|
|
|
}
|
|
|
|
|
2016-05-26 23:59:05 +02:00
|
|
|
if (!transaction.hash || !isLinkable) return
|
2016-05-26 02:57:08 +02:00
|
|
|
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', [
|
2016-05-26 23:12:41 +02:00
|
|
|
transaction.status === 'unconfirmed' ? h('.red-dot', ' ') :
|
|
|
|
h(TransactionIcon, { txParams, transaction, isTx, isMsg }),
|
2016-05-26 02:57:08 +02:00
|
|
|
]),
|
|
|
|
|
|
|
|
h('.flex-column', [
|
2016-05-26 23:12:41 +02:00
|
|
|
domainField(txParams),
|
2016-05-26 02:57:08 +02:00
|
|
|
h('div', date),
|
2016-05-26 23:12:41 +02:00
|
|
|
recipientField(txParams, transaction, isTx, isMsg),
|
2016-05-26 02:57:08 +02:00
|
|
|
]),
|
|
|
|
|
2016-05-26 23:12:41 +02:00
|
|
|
isTx ? h(EtherBalance, {
|
2016-05-26 02:57:08 +02:00
|
|
|
value: txParams.value,
|
2016-05-26 23:12:41 +02:00
|
|
|
}) : h('.flex-column'),
|
2016-05-26 02:57:08 +02:00
|
|
|
])
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2016-05-26 23:12:41 +02:00
|
|
|
function domainField(txParams) {
|
|
|
|
return h('div', {
|
|
|
|
style: {
|
|
|
|
fontSize: 'small',
|
|
|
|
color: '#ABA9AA',
|
|
|
|
},
|
|
|
|
},[
|
|
|
|
txParams.origin,
|
|
|
|
])
|
|
|
|
}
|
2016-05-26 02:57:08 +02:00
|
|
|
|
2016-05-26 23:12:41 +02:00
|
|
|
function recipientField(txParams, transaction, isTx, isMsg) {
|
|
|
|
let message
|
2016-05-26 02:57:08 +02:00
|
|
|
|
2016-05-26 23:12:41 +02:00
|
|
|
if (isMsg) {
|
|
|
|
message = 'Signature Requested'
|
|
|
|
} else if (txParams.to) {
|
|
|
|
message = addressSummary(txParams.to)
|
2016-05-26 02:57:08 +02:00
|
|
|
} else {
|
2016-05-26 23:12:41 +02:00
|
|
|
message = 'Contract Published'
|
2016-05-26 02:57:08 +02:00
|
|
|
}
|
2016-05-26 23:12:41 +02:00
|
|
|
|
|
|
|
return h('div', {
|
|
|
|
style: {
|
|
|
|
fontSize: 'small',
|
|
|
|
color: '#ABA9AA',
|
|
|
|
},
|
|
|
|
},[
|
|
|
|
message,
|
|
|
|
failIfFailed(transaction),
|
|
|
|
])
|
|
|
|
|
2016-05-26 02:57:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TransactionListItem.prototype.renderMessage = function() {
|
2016-05-26 23:41:11 +02:00
|
|
|
const { transaction, i, network } = this.props
|
2016-05-26 02:57:08 +02:00
|
|
|
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') {
|
2016-05-26 23:12:41 +02:00
|
|
|
return h('span.error', ' (Rejected)')
|
|
|
|
}
|
|
|
|
if (transaction.status === 'failed') {
|
2016-05-26 02:57:08 +02:00
|
|
|
return h('span.error', ' (Failed)')
|
|
|
|
}
|
|
|
|
}
|