2016-05-26 02:57:08 +02:00
|
|
|
const Component = require('react').Component
|
|
|
|
const h = require('react-hyperscript')
|
|
|
|
const inherits = require('util').inherits
|
2017-12-07 04:48:26 +01:00
|
|
|
const connect = require('react-redux').connect
|
2016-05-26 02:57:08 +02:00
|
|
|
|
2017-05-16 20:34:53 +02:00
|
|
|
const EthBalance = require('./eth-balance')
|
2016-05-26 02:57:08 +02:00
|
|
|
const addressSummary = require('../util').addressSummary
|
2017-10-14 17:23:44 +02:00
|
|
|
const explorerLink = require('etherscan-link').createExplorerLink
|
2016-06-29 23:12:58 +02:00
|
|
|
const CopyButton = require('./copyButton')
|
2017-08-03 23:48:19 +02:00
|
|
|
const vreme = new (require('vreme'))()
|
2017-01-10 20:52:25 +01:00
|
|
|
const Tooltip = require('./tooltip')
|
2017-05-23 00:43:20 +02:00
|
|
|
const numberToBN = require('number-to-bn')
|
2017-12-07 04:20:11 +01:00
|
|
|
const actions = require('../actions')
|
2018-01-25 06:41:29 +01:00
|
|
|
const t = require('../../i18n')
|
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')
|
2017-12-07 04:48:26 +01:00
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => {
|
|
|
|
return {
|
|
|
|
retryTransaction: transactionId => dispatch(actions.retryTransaction(transactionId)),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = connect(null, mapDispatchToProps)(TransactionListItem)
|
2016-05-26 02:57:08 +02:00
|
|
|
|
|
|
|
inherits(TransactionListItem, Component)
|
2016-06-21 22:18:32 +02:00
|
|
|
function TransactionListItem () {
|
2016-05-26 02:57:08 +02:00
|
|
|
Component.call(this)
|
|
|
|
}
|
|
|
|
|
2017-12-07 06:01:11 +01:00
|
|
|
TransactionListItem.prototype.showRetryButton = function () {
|
|
|
|
const { transaction = {} } = this.props
|
|
|
|
const { status, time } = transaction
|
|
|
|
return status === 'submitted' && Date.now() - time > 30000
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
TransactionListItem.prototype.render = function () {
|
2017-05-16 20:34:53 +02:00
|
|
|
const { transaction, network, conversionRate, currentCurrency } = this.props
|
2017-12-07 04:20:11 +01:00
|
|
|
const { status } = transaction
|
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-04-25 23:39:01 +02:00
|
|
|
isLinkable = numericNet === 1 || numericNet === 3 || numericNet === 4 || 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)
|
2017-12-07 04:20:11 +01:00
|
|
|
var isPending = 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
|
|
|
|
2017-05-23 00:43:20 +02:00
|
|
|
const nonce = txParams.nonce ? numberToBN(txParams.nonce).toString(10) : ''
|
2017-05-21 23:09:44 +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 (
|
2017-12-07 04:22:40 +01:00
|
|
|
h('.transaction-list-item.flex-column', {
|
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))
|
2017-04-05 07:43:55 +02:00
|
|
|
global.platform.openWindow({ url })
|
2016-09-16 04:35:04 +02:00
|
|
|
},
|
2016-05-26 02:57:08 +02:00
|
|
|
style: {
|
|
|
|
padding: '20px 0',
|
2017-12-07 04:22:40 +01:00
|
|
|
alignItems: 'center',
|
2016-05-26 02:57:08 +02:00
|
|
|
},
|
|
|
|
}, [
|
2017-12-07 04:22:40 +01:00
|
|
|
h(`.flex-row.flex-space-between${isClickable ? '.pointer' : ''}`, {
|
|
|
|
style: {
|
|
|
|
width: '100%',
|
|
|
|
},
|
|
|
|
}, [
|
|
|
|
h('.identicon-wrapper.flex-column.flex-center.select-none', [
|
|
|
|
h(TransactionIcon, { txParams, transaction, isTx, isMsg }),
|
|
|
|
]),
|
|
|
|
|
|
|
|
h(Tooltip, {
|
2018-01-23 10:48:03 +01:00
|
|
|
title: t('transactionNumber'),
|
2017-12-07 04:22:40 +01:00
|
|
|
position: 'right',
|
|
|
|
}, [
|
|
|
|
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' }}),
|
|
|
|
|
|
|
|
isTx ? h(EthBalance, {
|
|
|
|
value: txParams.value,
|
|
|
|
conversionRate,
|
|
|
|
currentCurrency,
|
|
|
|
width: '55px',
|
|
|
|
shorten: true,
|
|
|
|
showFiat: false,
|
|
|
|
style: {fontSize: '15px'},
|
|
|
|
}) : h('.flex-column'),
|
2016-05-26 02:57:08 +02:00
|
|
|
]),
|
|
|
|
|
2017-12-07 06:01:11 +01:00
|
|
|
this.showRetryButton() && h('.transition-list-item__retry.grow-on-hover', {
|
2017-12-07 04:22:40 +01:00
|
|
|
onClick: event => {
|
|
|
|
event.stopPropagation()
|
|
|
|
this.resubmit()
|
|
|
|
},
|
|
|
|
style: {
|
2017-12-07 05:27:43 +01:00
|
|
|
height: '22px',
|
|
|
|
borderRadius: '22px',
|
2017-12-07 04:22:40 +01:00
|
|
|
color: '#F9881B',
|
2017-12-07 05:27:43 +01:00
|
|
|
padding: '0 20px',
|
2017-12-07 04:22:40 +01:00
|
|
|
backgroundColor: '#FFE3C9',
|
|
|
|
display: 'flex',
|
|
|
|
justifyContent: 'center',
|
|
|
|
alignItems: 'center',
|
2017-12-07 05:27:43 +01:00
|
|
|
fontSize: '8px',
|
2017-12-07 04:22:40 +01:00
|
|
|
cursor: 'pointer',
|
|
|
|
},
|
2017-05-21 23:18:23 +02:00
|
|
|
}, [
|
2017-12-07 04:22:40 +01:00
|
|
|
h('div', {
|
2017-05-21 23:09:44 +02:00
|
|
|
style: {
|
2017-12-07 04:22:40 +01:00
|
|
|
paddingRight: '2px',
|
2017-05-21 23:09:44 +02:00
|
|
|
},
|
2018-01-23 10:48:03 +01:00
|
|
|
}, t('takesTooLong')),
|
2017-12-07 04:22:40 +01:00
|
|
|
h('div', {
|
|
|
|
style: {
|
|
|
|
textDecoration: 'underline',
|
|
|
|
},
|
2018-01-23 10:48:03 +01:00
|
|
|
}, t('retryWithMoreGas')),
|
2016-05-26 02:57:08 +02:00
|
|
|
]),
|
|
|
|
])
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2017-12-07 04:20:11 +01:00
|
|
|
TransactionListItem.prototype.resubmit = function () {
|
|
|
|
const { transaction } = this.props
|
2017-12-07 04:48:26 +01:00
|
|
|
this.props.retryTransaction(transaction.id)
|
2017-12-07 04:20:11 +01: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) {
|
2018-01-23 10:48:03 +01:00
|
|
|
message = t('sigRequested')
|
2016-05-26 23:12:41 +02:00
|
|
|
} 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 {
|
2018-01-23 10:48:03 +01:00
|
|
|
message = t('contractPublished')
|
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,
|
2017-10-03 00:39:44 +02:00
|
|
|
renderErrorOrWarning(transaction),
|
2016-05-26 23:12:41 +02:00
|
|
|
])
|
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')
|
|
|
|
}
|
|
|
|
|
2017-10-03 00:39:44 +02:00
|
|
|
function renderErrorOrWarning (transaction) {
|
2017-11-02 03:30:33 +01:00
|
|
|
const { status } = transaction
|
2017-10-03 00:39:44 +02:00
|
|
|
|
|
|
|
// show rejected
|
|
|
|
if (status === 'rejected') {
|
2018-01-23 10:48:03 +01:00
|
|
|
return h('span.error', ' (' + t('rejected') + ')')
|
2016-05-26 23:12:41 +02:00
|
|
|
}
|
2017-08-04 20:43:08 +02:00
|
|
|
if (transaction.err || transaction.warning) {
|
|
|
|
const { err, warning = {} } = transaction
|
2017-08-29 16:50:48 +02:00
|
|
|
const errFirst = !!((err && warning) || err)
|
2017-08-04 20:43:08 +02:00
|
|
|
|
|
|
|
errFirst ? err.message : warning.message
|
|
|
|
|
2017-11-02 03:30:33 +01:00
|
|
|
// show error
|
|
|
|
if (err) {
|
|
|
|
const message = err.message || ''
|
|
|
|
return (
|
|
|
|
h(Tooltip, {
|
|
|
|
title: message,
|
|
|
|
position: 'bottom',
|
|
|
|
}, [
|
2018-01-23 10:48:03 +01:00
|
|
|
h(`span.error`, ` (` + t('failed') + `)`),
|
2017-11-02 03:30:33 +01:00
|
|
|
])
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// show warning
|
|
|
|
if (warning) {
|
|
|
|
const message = warning.message
|
|
|
|
return h(Tooltip, {
|
|
|
|
title: message,
|
|
|
|
position: 'bottom',
|
|
|
|
}, [
|
2018-01-23 10:48:03 +01:00
|
|
|
h(`span.warning`, ` (` + t('warning') + `)`),
|
2017-11-02 03:30:33 +01:00
|
|
|
])
|
|
|
|
}
|
2016-05-26 02:57:08 +02:00
|
|
|
}
|
|
|
|
}
|