2016-04-20 00:07:15 +02:00
|
|
|
const h = require('react-hyperscript')
|
2016-05-14 02:02:33 +02:00
|
|
|
const vreme = new (require('vreme'))
|
2016-04-20 02:31:34 +02:00
|
|
|
const formatBalance = require('../util').formatBalance
|
2016-04-20 03:21:28 +02:00
|
|
|
const addressSummary = require('../util').addressSummary
|
|
|
|
const explorerLink = require('../../lib/explorer-link')
|
2016-05-06 23:42:08 +02:00
|
|
|
const Panel = require('./panel')
|
2016-05-19 02:48:50 +02:00
|
|
|
const Identicon = require('./identicon')
|
|
|
|
const EtherBalance = require('./eth-balance')
|
|
|
|
|
2016-04-20 00:07:15 +02:00
|
|
|
|
2016-04-20 03:21:28 +02:00
|
|
|
module.exports = function(transactions, network) {
|
2016-05-14 01:28:46 +02:00
|
|
|
return (
|
2016-05-06 23:42:08 +02:00
|
|
|
|
2016-05-14 01:28:46 +02:00
|
|
|
h('section.transaction-list', [
|
2016-05-06 23:42:08 +02:00
|
|
|
|
2016-05-19 02:48:50 +02:00
|
|
|
h('style', `
|
|
|
|
.transaction-list .transaction-list-item:not(:last-of-type) {
|
|
|
|
border-bottom: 1px solid #D4D4D4;
|
|
|
|
}
|
|
|
|
.transaction-list .transaction-list-item .ether-balance-label {
|
|
|
|
display: block !important;
|
|
|
|
font-size: small;
|
|
|
|
}
|
|
|
|
`),
|
|
|
|
|
2016-05-14 01:28:46 +02:00
|
|
|
h('h3.flex-center.text-transform-uppercase', {
|
|
|
|
style: {
|
|
|
|
background: '#EBEBEB',
|
2016-05-14 02:02:33 +02:00
|
|
|
color: '#AEAEAE',
|
2016-05-14 01:28:46 +02:00
|
|
|
},
|
|
|
|
}, [
|
|
|
|
'Transactions',
|
|
|
|
]),
|
|
|
|
|
|
|
|
h('.tx-list', {
|
2016-05-06 23:42:08 +02:00
|
|
|
style: {
|
|
|
|
overflowY: 'auto',
|
2016-05-14 01:28:46 +02:00
|
|
|
height: '204px',
|
2016-05-14 01:36:04 +02:00
|
|
|
padding: '0 20px',
|
2016-05-06 23:42:08 +02:00
|
|
|
textAlign: 'center',
|
|
|
|
},
|
2016-05-14 01:28:46 +02:00
|
|
|
}, (
|
2016-05-06 23:42:08 +02:00
|
|
|
|
2016-05-14 01:28:46 +02:00
|
|
|
transactions.length ?
|
|
|
|
transactions.map(renderTransaction)
|
|
|
|
:
|
|
|
|
[h('.flex-center', {
|
2016-05-06 23:42:08 +02:00
|
|
|
style: {
|
2016-05-14 01:28:46 +02:00
|
|
|
height: '100%',
|
2016-05-06 23:42:08 +02:00
|
|
|
},
|
2016-05-14 01:28:46 +02:00
|
|
|
}, 'No transaction history...')]
|
|
|
|
|
|
|
|
))
|
|
|
|
|
|
|
|
])
|
|
|
|
|
|
|
|
)
|
|
|
|
|
2016-05-19 02:48:50 +02:00
|
|
|
|
2016-05-20 04:00:14 +02:00
|
|
|
function renderTransaction(transaction, i){
|
2016-05-19 02:48:50 +02:00
|
|
|
|
|
|
|
var txParams = transaction.txParams
|
|
|
|
var date = formatDate(transaction.time)
|
|
|
|
|
2016-05-20 02:45:58 +02:00
|
|
|
return (
|
2016-05-19 02:48:50 +02:00
|
|
|
|
2016-05-20 04:11:53 +02:00
|
|
|
h(`.transaction-list-item.flex-row.flex-space-between${transaction.hash ? '.pointer' : ''}`, {
|
2016-05-20 04:00:14 +02:00
|
|
|
key: `tx-${transaction.id + i}`,
|
2016-05-19 02:48:50 +02:00
|
|
|
onClick: (event) => {
|
2016-05-20 04:11:53 +02:00
|
|
|
if (!transaction.hash) return
|
2016-05-19 02:48:50 +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-20 02:45:58 +02:00
|
|
|
identicon(txParams, transaction),
|
2016-05-19 02:48:50 +02:00
|
|
|
]),
|
|
|
|
|
|
|
|
h('.flex-column', [
|
|
|
|
|
|
|
|
h('div', date),
|
|
|
|
|
2016-05-20 04:00:14 +02:00
|
|
|
recipientField(txParams, transaction),
|
2016-05-19 02:48:50 +02:00
|
|
|
|
|
|
|
]),
|
|
|
|
|
|
|
|
h(EtherBalance, {
|
|
|
|
value: txParams.value,
|
|
|
|
}),
|
|
|
|
])
|
|
|
|
|
|
|
|
)
|
2016-05-14 01:28:46 +02:00
|
|
|
}
|
2016-05-20 02:45:58 +02:00
|
|
|
}
|
|
|
|
|
2016-05-20 04:00:14 +02:00
|
|
|
function recipientField(txParams, transaction) {
|
2016-05-20 02:45:58 +02:00
|
|
|
if (txParams.to) {
|
|
|
|
return h('div', {
|
|
|
|
style: {
|
|
|
|
fontSize: 'small',
|
|
|
|
color: '#ABA9AA',
|
|
|
|
},
|
2016-05-20 04:00:14 +02:00
|
|
|
}, [
|
|
|
|
addressSummary(txParams.to),
|
|
|
|
failIfFailed(transaction),
|
|
|
|
])
|
2016-05-14 01:28:46 +02:00
|
|
|
|
2016-05-20 02:45:58 +02:00
|
|
|
} else {
|
|
|
|
|
|
|
|
return h('div', {
|
|
|
|
style: {
|
|
|
|
fontSize: 'small',
|
|
|
|
color: '#ABA9AA',
|
|
|
|
},
|
2016-05-20 04:00:14 +02:00
|
|
|
},[
|
|
|
|
'Contract Published',
|
|
|
|
failIfFailed(transaction),
|
|
|
|
])
|
|
|
|
|
2016-05-20 02:45:58 +02:00
|
|
|
}
|
|
|
|
}
|
2016-05-14 02:02:33 +02:00
|
|
|
|
|
|
|
function formatDate(date){
|
|
|
|
return vreme.format(new Date(date), 'March 16 2014 14:30')
|
2016-05-20 02:45:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function identicon(txParams, transaction) {
|
2016-05-20 04:00:14 +02:00
|
|
|
if (transaction.status === 'rejected') {
|
|
|
|
return h('i.fa.fa-exclamation-triangle.fa-lg.error', {
|
|
|
|
style: {
|
|
|
|
width: '24px',
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-05-20 02:45:58 +02:00
|
|
|
if (txParams.to) {
|
|
|
|
return h(Identicon, {
|
|
|
|
diameter: 24,
|
|
|
|
address: txParams.to || transaction.hash,
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
return h('i.fa.fa-file-text-o.fa-lg', {
|
|
|
|
style: {
|
|
|
|
width: '24px',
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2016-05-20 04:00:14 +02:00
|
|
|
|
|
|
|
function failIfFailed(transaction) {
|
|
|
|
if (transaction.status === 'rejected') {
|
|
|
|
return h('span.error', ' (Failed)')
|
|
|
|
}
|
|
|
|
}
|