1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-30 16:18:07 +01:00
metamask-extension/ui/app/components/transaction-list-item.js

122 lines
2.9 KiB
JavaScript
Raw Normal View History

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 vreme = new (require('vreme'))
const TransactionIcon = require('./transaction-list-item-icon')
module.exports = TransactionListItem
inherits(TransactionListItem, Component)
2016-06-21 22:18:32 +02:00
function TransactionListItem () {
Component.call(this)
}
2016-06-21 22:18:32 +02:00
TransactionListItem.prototype.render = function () {
2016-05-26 23:50:01 +02:00
const { transaction, i, network } = this.props
var date = formatDate(transaction.time)
let isLinkable = false
2016-05-27 00:00:37 +02:00
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', [
2016-06-21 22:56:04 +02:00
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'),
])
)
}
2016-06-21 22:18:32 +02:00
function domainField (txParams) {
return h('div', {
style: {
2016-06-23 00:31:02 +02:00
fontSize: 'x-small',
color: '#ABA9AA',
},
2016-06-21 22:18:32 +02:00
}, [
txParams.origin,
])
}
2016-06-21 22:18:32 +02:00
function recipientField (txParams, transaction, isTx, isMsg) {
let message
if (isMsg) {
message = 'Signature Requested'
} else if (txParams.to) {
2016-06-21 22:18:32 +02:00
message = addressSummary(txParams.to)
} else {
message = 'Contract Published'
}
return h('div', {
style: {
2016-06-23 00:31:02 +02:00
fontSize: 'x-small',
color: '#ABA9AA',
},
2016-06-21 22:18:32 +02:00
}, [
message,
failIfFailed(transaction),
])
}
2016-06-21 22:18:32 +02:00
function formatDate (date) {
return vreme.format(new Date(date), 'March 16 2014 14:30')
}
2016-06-21 22:18:32 +02:00
function failIfFailed (transaction) {
if (transaction.status === 'rejected') {
return h('span.error', ' (Rejected)')
}
if (transaction.status === 'failed') {
return h('span.error', ' (Failed)')
}
}