2017-08-09 12:10:51 +02:00
|
|
|
const Component = require('react').Component
|
2018-03-16 01:29:45 +01:00
|
|
|
const connect = require('../metamask-connect')
|
2017-08-09 12:10:51 +02:00
|
|
|
const h = require('react-hyperscript')
|
|
|
|
const inherits = require('util').inherits
|
2017-09-07 18:18:13 +02:00
|
|
|
const prefixForNetwork = require('../../lib/etherscan-prefix-for-network')
|
2017-08-11 04:35:10 +02:00
|
|
|
const selectors = require('../selectors')
|
2017-08-30 12:33:00 +02:00
|
|
|
const TxListItem = require('./tx-list-item')
|
2017-09-29 16:50:09 +02:00
|
|
|
const ShiftListItem = require('./shift-list-item')
|
2017-11-02 03:30:33 +01:00
|
|
|
const { formatDate } = require('../util')
|
2017-08-30 05:16:30 +02:00
|
|
|
const { showConfTxPage } = require('../actions')
|
2017-10-13 23:14:26 +02:00
|
|
|
const classnames = require('classnames')
|
2017-10-27 19:39:40 +02:00
|
|
|
const { tokenInfoGetter } = require('../token-util')
|
2017-08-09 12:10:51 +02:00
|
|
|
|
2017-08-30 05:16:30 +02:00
|
|
|
module.exports = connect(mapStateToProps, mapDispatchToProps)(TxList)
|
2017-08-09 12:10:51 +02:00
|
|
|
|
2017-08-10 05:06:37 +02:00
|
|
|
function mapStateToProps (state) {
|
2017-08-09 12:10:51 +02:00
|
|
|
return {
|
2017-08-11 04:35:10 +02:00
|
|
|
txsToRender: selectors.transactionsSelector(state),
|
|
|
|
conversionRate: selectors.conversionRateSelector(state),
|
2017-08-09 12:10:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-30 05:16:30 +02:00
|
|
|
function mapDispatchToProps (dispatch) {
|
|
|
|
return {
|
2017-11-02 13:15:59 +01:00
|
|
|
showConfTxPage: ({ id }) => dispatch(showConfTxPage({ id })),
|
2017-08-30 05:16:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-09 12:10:51 +02:00
|
|
|
inherits(TxList, Component)
|
|
|
|
function TxList () {
|
|
|
|
Component.call(this)
|
|
|
|
}
|
|
|
|
|
2017-10-27 19:39:40 +02:00
|
|
|
TxList.prototype.componentWillMount = function () {
|
|
|
|
this.tokenInfoGetter = tokenInfoGetter()
|
|
|
|
}
|
|
|
|
|
2017-08-09 12:10:51 +02:00
|
|
|
TxList.prototype.render = function () {
|
2018-01-16 20:58:02 +01:00
|
|
|
return h('div.flex-column', [
|
2017-09-07 20:38:21 +02:00
|
|
|
h('div.flex-row.tx-list-header-wrapper', [
|
|
|
|
h('div.flex-row.tx-list-header', [
|
2018-03-22 01:41:47 +01:00
|
|
|
h('div', this.props.t('transactions')),
|
2017-08-09 12:10:51 +02:00
|
|
|
]),
|
|
|
|
]),
|
2018-01-16 20:58:02 +01:00
|
|
|
h('div.flex-column.tx-list-container', {}, [
|
|
|
|
this.renderTransaction(),
|
|
|
|
]),
|
2017-08-09 12:10:51 +02:00
|
|
|
])
|
|
|
|
}
|
|
|
|
|
2017-09-12 22:40:28 +02:00
|
|
|
TxList.prototype.renderTransaction = function () {
|
|
|
|
const { txsToRender, conversionRate } = this.props
|
2018-02-09 01:40:15 +01:00
|
|
|
|
2017-09-07 12:14:53 +02:00
|
|
|
return txsToRender.length
|
2018-01-12 20:48:18 +01:00
|
|
|
? txsToRender.map((transaction, i) => this.renderTransactionListItem(transaction, conversionRate, i))
|
2017-10-03 02:28:15 +02:00
|
|
|
: [h(
|
|
|
|
'div.tx-list-item.tx-list-item--empty',
|
|
|
|
{ key: 'tx-list-none' },
|
2018-03-22 01:41:47 +01:00
|
|
|
[ this.props.t('noTransactions') ],
|
2017-10-03 02:28:15 +02:00
|
|
|
)]
|
2017-09-07 12:14:53 +02:00
|
|
|
}
|
|
|
|
|
2017-08-23 01:16:56 +02:00
|
|
|
// TODO: Consider moving TxListItem into a separate component
|
2018-01-12 20:48:18 +01:00
|
|
|
TxList.prototype.renderTransactionListItem = function (transaction, conversionRate, index) {
|
2017-09-26 18:15:14 +02:00
|
|
|
// console.log({transaction})
|
|
|
|
// refer to transaction-list.js:line 58
|
2017-09-29 17:40:57 +02:00
|
|
|
|
2017-09-26 18:15:14 +02:00
|
|
|
if (transaction.key === 'shapeshift') {
|
2018-02-09 01:40:15 +01:00
|
|
|
return h(ShiftListItem, { ...transaction, key: `shapeshift${index}` })
|
2017-09-26 18:15:14 +02:00
|
|
|
}
|
|
|
|
|
2017-08-11 04:35:10 +02:00
|
|
|
const props = {
|
2017-08-23 01:16:56 +02:00
|
|
|
dateString: formatDate(transaction.time),
|
|
|
|
address: transaction.txParams.to,
|
|
|
|
transactionStatus: transaction.status,
|
2017-09-12 22:40:28 +02:00
|
|
|
transactionAmount: transaction.txParams.value,
|
2018-03-09 04:49:26 +01:00
|
|
|
transactionId: transaction.id,
|
2017-09-07 18:18:13 +02:00
|
|
|
transactionHash: transaction.hash,
|
|
|
|
transactionNetworkId: transaction.metamaskNetworkId,
|
2018-03-14 01:27:23 +01:00
|
|
|
transactionSubmittedTime: transaction.submittedTime,
|
2017-08-11 04:35:10 +02:00
|
|
|
}
|
2017-08-30 05:16:30 +02:00
|
|
|
|
2017-09-05 10:48:52 +02:00
|
|
|
const {
|
2017-09-06 09:33:39 +02:00
|
|
|
address,
|
2017-09-05 10:48:52 +02:00
|
|
|
transactionStatus,
|
|
|
|
transactionAmount,
|
|
|
|
dateString,
|
2018-03-09 04:49:26 +01:00
|
|
|
transactionId,
|
2017-09-07 18:18:13 +02:00
|
|
|
transactionHash,
|
|
|
|
transactionNetworkId,
|
2018-03-14 00:39:04 +01:00
|
|
|
transactionSubmittedTime,
|
2017-09-05 10:48:52 +02:00
|
|
|
} = props
|
2017-08-30 05:16:30 +02:00
|
|
|
const { showConfTxPage } = this.props
|
2017-09-05 10:48:52 +02:00
|
|
|
|
2017-08-30 12:33:00 +02:00
|
|
|
const opts = {
|
2018-03-09 04:49:26 +01:00
|
|
|
key: transactionId || transactionHash,
|
2017-09-14 10:09:57 +02:00
|
|
|
txParams: transaction.txParams,
|
2017-08-30 12:33:00 +02:00
|
|
|
transactionStatus,
|
2018-03-09 04:49:26 +01:00
|
|
|
transactionId,
|
2017-08-30 12:33:00 +02:00
|
|
|
dateString,
|
|
|
|
address,
|
|
|
|
transactionAmount,
|
2017-09-07 18:18:13 +02:00
|
|
|
transactionHash,
|
2017-09-12 22:40:28 +02:00
|
|
|
conversionRate,
|
2017-10-27 19:39:40 +02:00
|
|
|
tokenInfoGetter: this.tokenInfoGetter,
|
2018-03-14 00:39:04 +01:00
|
|
|
transactionSubmittedTime,
|
2017-08-30 12:33:00 +02:00
|
|
|
}
|
2017-08-09 12:10:51 +02:00
|
|
|
|
2017-11-02 13:15:59 +01:00
|
|
|
const isUnapproved = transactionStatus === 'unapproved'
|
2017-10-13 23:14:26 +02:00
|
|
|
|
|
|
|
if (isUnapproved) {
|
2018-03-20 21:01:08 +01:00
|
|
|
opts.onClick = () => showConfTxPage({ id: transactionId })
|
2018-03-22 04:24:44 +01:00
|
|
|
opts.transactionStatus = this.props.t('notStarted')
|
2017-09-07 20:38:21 +02:00
|
|
|
} else if (transactionHash) {
|
2017-09-07 18:18:13 +02:00
|
|
|
opts.onClick = () => this.view(transactionHash, transactionNetworkId)
|
2017-08-30 12:33:00 +02:00
|
|
|
}
|
2017-08-31 09:28:45 +02:00
|
|
|
|
2017-10-13 23:14:26 +02:00
|
|
|
opts.className = classnames('.tx-list-item', {
|
|
|
|
'.tx-list-pending-item-container': isUnapproved,
|
|
|
|
'.tx-list-clickable': Boolean(transactionHash) || isUnapproved,
|
|
|
|
})
|
|
|
|
|
2017-08-30 12:33:00 +02:00
|
|
|
return h(TxListItem, opts)
|
2017-08-09 12:10:51 +02:00
|
|
|
}
|
|
|
|
|
2017-09-07 18:18:13 +02:00
|
|
|
TxList.prototype.view = function (txHash, network) {
|
|
|
|
const url = etherscanLinkFor(txHash, network)
|
|
|
|
if (url) {
|
|
|
|
navigateTo(url)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function navigateTo (url) {
|
|
|
|
global.platform.openWindow({ url })
|
|
|
|
}
|
|
|
|
|
|
|
|
function etherscanLinkFor (txHash, network) {
|
|
|
|
const prefix = prefixForNetwork(network)
|
|
|
|
return `https://${prefix}etherscan.io/tx/${txHash}`
|
|
|
|
}
|