2016-05-26 02:57:08 +02:00
|
|
|
const Component = require('react').Component
|
|
|
|
const h = require('react-hyperscript')
|
|
|
|
const inherits = require('util').inherits
|
|
|
|
|
2016-07-12 02:44:00 +02:00
|
|
|
const EtherBalance = require('./eth-balance')
|
2016-05-26 02:57:08 +02:00
|
|
|
const addressSummary = require('../util').addressSummary
|
|
|
|
const explorerLink = require('../../lib/explorer-link')
|
2016-06-29 23:12:58 +02:00
|
|
|
const CopyButton = require('./copyButton')
|
2016-05-26 02:57:08 +02:00
|
|
|
const vreme = new (require('vreme'))
|
2016-07-21 19:45:32 +02:00
|
|
|
const extension = require('../../../app/scripts/lib/extension')
|
2017-01-10 20:52:25 +01:00
|
|
|
const Tooltip = require('./tooltip')
|
2016-05-26 02:57:08 +02:00
|
|
|
|
2016-05-26 23:12:41 +02:00
|
|
|
const TransactionIcon = require('./transaction-list-item-icon')
|
2016-08-18 19:40:35 +02:00
|
|
|
const ShiftListItem = require('./shift-list-item')
|
2016-05-26 02:57:08 +02:00
|
|
|
module.exports = TransactionListItem
|
|
|
|
|
|
|
|
inherits(TransactionListItem, Component)
|
2016-06-21 22:18:32 +02:00
|
|
|
function TransactionListItem () {
|
2016-05-26 02:57:08 +02:00
|
|
|
Component.call(this)
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
TransactionListItem.prototype.render = function () {
|
2016-08-23 02:21:54 +02:00
|
|
|
const { transaction, network } = this.props
|
2016-08-18 19:40:35 +02:00
|
|
|
if (transaction.key === 'shapeshift') {
|
|
|
|
if (network === '1') return h(ShiftListItem, transaction)
|
|
|
|
}
|
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)
|
2017-03-23 16:26:39 +01:00
|
|
|
isLinkable = numericNet === 1 || numericNet === 3 || numericNet === 42
|
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-12-16 19:33:36 +01:00
|
|
|
var isPending = transaction.status === 'unapproved'
|
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 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-09-16 04:35:04 +02:00
|
|
|
onClick: (event) => {
|
|
|
|
if (isPending) {
|
|
|
|
this.props.showTx(transaction.id)
|
|
|
|
}
|
|
|
|
event.stopPropagation()
|
|
|
|
if (!transaction.hash || !isLinkable) return
|
|
|
|
var url = explorerLink(transaction.hash, parseInt(network))
|
|
|
|
extension.tabs.create({ url })
|
|
|
|
},
|
2016-05-26 02:57:08 +02:00
|
|
|
style: {
|
|
|
|
padding: '20px 0',
|
|
|
|
},
|
|
|
|
}, [
|
|
|
|
|
|
|
|
h('.identicon-wrapper.flex-column.flex-center.select-none', [
|
2017-01-10 20:52:25 +01:00
|
|
|
h('.pop-hover', {
|
2016-09-16 04:35:04 +02:00
|
|
|
onClick: (event) => {
|
|
|
|
event.stopPropagation()
|
2016-09-16 03:25:05 +02:00
|
|
|
if (!isTx || isPending) return
|
|
|
|
var url = `https://metamask.github.io/eth-tx-viz/?tx=${transaction.hash}`
|
|
|
|
extension.tabs.create({ url })
|
|
|
|
},
|
|
|
|
}, [
|
2016-09-16 03:13:13 +02:00
|
|
|
h(TransactionIcon, { txParams, transaction, isTx, isMsg }),
|
|
|
|
]),
|
2016-05-26 02:57:08 +02:00
|
|
|
]),
|
|
|
|
|
2016-09-16 04:35:04 +02:00
|
|
|
h('.flex-column', {style: {width: '200px', overflow: 'hidden'}}, [
|
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-07-07 22:48:52 +02:00
|
|
|
// Places a copy button if tx is successful, else places a placeholder empty div.
|
|
|
|
transaction.hash ? h(CopyButton, { value: transaction.hash }) : h('div', {style: { display: 'flex', alignItems: 'center', width: '26px' }}),
|
2016-06-29 23:12:58 +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-07-12 01:31:12 +02:00
|
|
|
width: '55px',
|
2016-07-09 02:27:13 +02:00
|
|
|
shorten: true,
|
2016-09-07 01:45:06 +02:00
|
|
|
showFiat: false,
|
2016-07-14 00:46:36 +02:00
|
|
|
style: {fontSize: '15px'},
|
2016-05-26 23:12:41 +02:00
|
|
|
}) : h('.flex-column'),
|
2016-05-26 02:57:08 +02:00
|
|
|
])
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function domainField (txParams) {
|
2016-05-26 23:12:41 +02:00
|
|
|
return h('div', {
|
|
|
|
style: {
|
2016-06-23 00:31:02 +02:00
|
|
|
fontSize: 'x-small',
|
2016-05-26 23:12:41 +02:00
|
|
|
color: '#ABA9AA',
|
2016-07-08 00:39:19 +02:00
|
|
|
overflow: 'hidden',
|
|
|
|
textOverflow: 'ellipsis',
|
|
|
|
width: '100%',
|
2016-05-26 23:12:41 +02:00
|
|
|
},
|
2016-06-21 22:18:32 +02:00
|
|
|
}, [
|
2016-05-26 23:12:41 +02:00
|
|
|
txParams.origin,
|
|
|
|
])
|
|
|
|
}
|
2016-05-26 02:57:08 +02:00
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function recipientField (txParams, transaction, isTx, isMsg) {
|
2016-05-26 23:12:41 +02:00
|
|
|
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) {
|
2016-06-21 22:18:32 +02:00
|
|
|
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: {
|
2016-06-23 00:31:02 +02:00
|
|
|
fontSize: 'x-small',
|
2016-05-26 23:12:41 +02:00
|
|
|
color: '#ABA9AA',
|
|
|
|
},
|
2016-06-21 22:18:32 +02:00
|
|
|
}, [
|
2016-05-26 23:12:41 +02:00
|
|
|
message,
|
|
|
|
failIfFailed(transaction),
|
|
|
|
])
|
2016-05-26 02:57:08 +02:00
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function formatDate (date) {
|
2016-05-26 02:57:08 +02:00
|
|
|
return vreme.format(new Date(date), 'March 16 2014 14:30')
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function failIfFailed (transaction) {
|
2016-05-26 02:57:08 +02:00
|
|
|
if (transaction.status === 'rejected') {
|
2016-05-26 23:12:41 +02:00
|
|
|
return h('span.error', ' (Rejected)')
|
|
|
|
}
|
2017-01-10 20:52:25 +01:00
|
|
|
if (transaction.err) {
|
|
|
|
|
|
|
|
return h(Tooltip, {
|
|
|
|
title: transaction.err.message,
|
|
|
|
position: 'bottom',
|
|
|
|
}, [
|
|
|
|
h('span.error', ' (Failed)'),
|
|
|
|
])
|
2016-05-26 02:57:08 +02:00
|
|
|
}
|
2017-01-10 20:52:25 +01:00
|
|
|
|
2016-05-26 02:57:08 +02:00
|
|
|
}
|