1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00
metamask-extension/ui/app/components/transaction-list-item.js

166 lines
4.5 KiB
JavaScript
Raw Normal View History

const Component = require('react').Component
const h = require('react-hyperscript')
const inherits = require('util').inherits
const EthBalance = require('./eth-balance')
const addressSummary = require('../util').addressSummary
const explorerLink = require('../../lib/explorer-link')
2016-06-29 23:12:58 +02:00
const CopyButton = require('./copyButton')
const vreme = new (require('vreme'))
const Tooltip = require('./tooltip')
2017-05-23 00:43:20 +02:00
const numberToBN = require('number-to-bn')
const TransactionIcon = require('./transaction-list-item-icon')
2016-08-18 19:40:35 +02:00
const ShiftListItem = require('./shift-list-item')
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 () {
const { transaction, network, conversionRate, currentCurrency } = this.props
2016-08-18 19:40:35 +02:00
if (transaction.key === 'shapeshift') {
if (network === '1') return h(ShiftListItem, transaction)
}
var date = formatDate(transaction.time)
let isLinkable = false
2016-05-27 00:00:37 +02:00
const numericNet = parseInt(network)
isLinkable = numericNet === 1 || numericNet === 3 || numericNet === 4 || numericNet === 42
var isMsg = ('msgParams' in transaction)
var isTx = ('txParams' in transaction)
2016-12-16 19:33:36 +01:00
var isPending = transaction.status === 'unapproved'
let txParams
if (isTx) {
txParams = transaction.txParams
} else if (isMsg) {
txParams = transaction.msgParams
}
2017-05-23 00:43:20 +02:00
const nonce = txParams.nonce ? numberToBN(txParams.nonce).toString(10) : ''
const isClickable = ('hash' in transaction && isLinkable) || isPending
return (
h(`.transaction-list-item.flex-row.flex-space-between${isClickable ? '.pointer' : ''}`, {
onClick: (event) => {
if (isPending) {
this.props.showTx(transaction.id)
}
event.stopPropagation()
if (!transaction.hash || !isLinkable) return
var url = explorerLink(transaction.hash, parseInt(network))
2017-04-05 07:43:55 +02:00
global.platform.openWindow({ url })
},
style: {
padding: '20px 0',
},
}, [
h('.identicon-wrapper.flex-column.flex-center.select-none', [
h('.pop-hover', {
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}`
2017-04-05 07:43:55 +02:00
global.platform.openWindow({ url })
2016-09-16 03:25:05 +02:00
},
}, [
2016-09-16 03:13:13 +02:00
h(TransactionIcon, { txParams, transaction, isTx, isMsg }),
]),
]),
h(Tooltip, {
title: 'Transaction Number',
position: 'bottom',
2017-05-21 23:18:23 +02:00
}, [
h('span', {
style: {
display: 'flex',
cursor: 'normal',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
padding: '10px',
},
}, nonce),
]),
h('.flex-column', {style: {width: '200px', overflow: 'hidden'}}, [
domainField(txParams),
h('div', date),
recipientField(txParams, transaction, isTx, isMsg),
]),
// 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
isTx ? h(EthBalance, {
value: txParams.value,
conversionRate,
currentCurrency,
width: '55px',
2016-07-09 02:27:13 +02:00
shorten: true,
showFiat: false,
style: {fontSize: '15px'},
}) : 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',
overflow: 'hidden',
textOverflow: 'ellipsis',
width: '100%',
},
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.err) {
return h(Tooltip, {
title: transaction.err.message,
position: 'bottom',
}, [
h('span.error', ' (Failed)'),
])
}
}