1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-27 21:00:13 +01:00
metamask-extension/ui/app/components/transaction-list.js

135 lines
3.0 KiB
JavaScript
Raw Normal View History

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
const addressSummary = require('../util').addressSummary
const explorerLink = require('../../lib/explorer-link')
const Panel = require('./panel')
2016-05-19 02:48:50 +02:00
const Identicon = require('./identicon')
const EtherBalance = require('./eth-balance')
module.exports = function(transactions, network) {
return (
h('section.transaction-list', [
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;
}
`),
h('h3.flex-center.text-transform-uppercase', {
style: {
background: '#EBEBEB',
2016-05-14 02:02:33 +02:00
color: '#AEAEAE',
},
}, [
'Transactions',
]),
h('.tx-list', {
style: {
overflowY: 'auto',
height: '204px',
padding: '0 20px',
textAlign: 'center',
},
}, (
transactions.length ?
transactions.map(renderTransaction)
:
[h('.flex-center', {
style: {
height: '100%',
},
}, 'No transaction history...')]
))
])
)
2016-05-19 02:48:50 +02:00
function renderTransaction(transaction){
var panelOpts = {
key: `tx-${transaction.hash}`,
identiconKey: transaction.txParams.to,
onClick: (event) => {
var url = explorerLink(transaction.hash, parseInt(network))
chrome.tabs.create({ url })
},
2016-05-19 02:48:50 +02:00
attributes: [
{
key: 'TIME',
value: formatDate(transaction.time),
},
{
key: 'TO',
value: addressSummary(transaction.txParams.to),
},
{
key: 'VALUE',
value: formatBalance(transaction.txParams.value),
},
]
}
var txParams = transaction.txParams
var date = formatDate(transaction.time)
return (
h('.transaction-list-item.flex-row.flex-space-between.cursor-pointer', {
key: `tx-${transaction.hash}`,
onClick: (event) => {
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', [
h(Identicon, {
diameter: 24,
address: txParams.to,
}),
]),
h('.flex-column', [
h('div', date),
h('div', {
style: {
fontSize: 'small',
color: '#ABA9AA',
},
}, addressSummary(txParams.to)),
]),
h(EtherBalance, {
value: txParams.value,
}),
])
)
}
2016-05-19 02:48:50 +02:00
}
2016-05-14 02:02:33 +02:00
function formatDate(date){
return vreme.format(new Date(date), 'March 16 2014 14:30')
}