2017-08-09 12:10:51 +02:00
|
|
|
const Component = require('react').Component
|
|
|
|
const connect = require('react-redux').connect
|
|
|
|
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-08-23 01:16:56 +02:00
|
|
|
const { formatBalance, formatDate } = require('../util')
|
2017-08-30 05:16:30 +02:00
|
|
|
const { showConfTxPage } = require('../actions')
|
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 {
|
|
|
|
showConfTxPage: ({ id }) => dispatch(showConfTxPage({ id }))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-09 12:10:51 +02:00
|
|
|
inherits(TxList, Component)
|
|
|
|
function TxList () {
|
|
|
|
Component.call(this)
|
|
|
|
}
|
|
|
|
|
|
|
|
TxList.prototype.render = function () {
|
|
|
|
|
2017-08-30 05:16:30 +02:00
|
|
|
const { txsToRender, showConfTxPage } = this.props
|
2017-08-09 12:10:51 +02:00
|
|
|
|
|
|
|
return h('div.flex-column.tx-list-container', {}, [
|
|
|
|
|
2017-09-07 20:38:21 +02:00
|
|
|
h('div.flex-row.tx-list-header-wrapper', [
|
|
|
|
h('div.flex-row.tx-list-header', [
|
|
|
|
h('div', 'transactions'),
|
2017-08-09 12:10:51 +02:00
|
|
|
]),
|
|
|
|
]),
|
|
|
|
|
2017-09-12 22:40:28 +02:00
|
|
|
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
|
2017-09-07 12:14:53 +02:00
|
|
|
|
|
|
|
return txsToRender.length
|
2017-09-14 10:09:57 +02:00
|
|
|
? txsToRender.map((transaction, i) => this.renderTransactionListItem(transaction, conversionRate))
|
2017-09-07 20:38:21 +02:00
|
|
|
: [h('div.tx-list-item.tx-list-item--empty', [ 'No Transactions' ])]
|
2017-09-07 12:14:53 +02:00
|
|
|
}
|
|
|
|
|
2017-08-23 01:16:56 +02:00
|
|
|
// TODO: Consider moving TxListItem into a separate component
|
2017-09-12 22:40:28 +02:00
|
|
|
TxList.prototype.renderTransactionListItem = function (transaction, conversionRate) {
|
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,
|
2017-08-30 05:16:30 +02:00
|
|
|
transActionId: transaction.id,
|
2017-09-07 18:18:13 +02:00
|
|
|
transactionHash: transaction.hash,
|
|
|
|
transactionNetworkId: transaction.metamaskNetworkId,
|
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,
|
2017-08-30 05:16:30 +02:00
|
|
|
transActionId,
|
2017-09-07 18:18:13 +02:00
|
|
|
transactionHash,
|
|
|
|
transactionNetworkId,
|
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 = {
|
2017-09-22 03:44:52 +02:00
|
|
|
key: transActionId || transactionHash,
|
2017-09-14 10:09:57 +02:00
|
|
|
txParams: transaction.txParams,
|
2017-08-30 12:33:00 +02:00
|
|
|
transactionStatus,
|
|
|
|
transActionId,
|
|
|
|
dateString,
|
|
|
|
address,
|
|
|
|
transactionAmount,
|
2017-09-07 18:18:13 +02:00
|
|
|
transactionHash,
|
2017-09-07 20:25:31 +02:00
|
|
|
className: '.tx-list-item.tx-list-clickable',
|
2017-09-12 22:40:28 +02:00
|
|
|
conversionRate,
|
2017-08-30 12:33:00 +02:00
|
|
|
}
|
2017-08-09 12:10:51 +02:00
|
|
|
|
2017-08-30 12:33:00 +02:00
|
|
|
if (transactionStatus === 'unapproved') {
|
|
|
|
opts.onClick = () => showConfTxPage({id: transActionId})
|
2017-09-07 18:18:13 +02:00
|
|
|
opts.className += '.tx-list-pending-item-container'
|
2017-09-07 20:38:21 +02:00
|
|
|
opts.transactionStatus = 'Not Started'
|
|
|
|
} 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-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}`
|
|
|
|
}
|