1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-01 00:28:06 +01:00
metamask-extension/ui/app/components/tx-list.js

118 lines
3.1 KiB
JavaScript
Raw Normal View History

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
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')
const { formatBalance, formatDate } = require('../util')
const { showConfTxPage } = require('../actions')
2017-08-09 12:10:51 +02:00
module.exports = connect(mapStateToProps, mapDispatchToProps)(TxList)
2017-08-09 12:10:51 +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
}
}
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 () {
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
]),
]),
this.renderTransaction(),
2017-08-09 12:10:51 +02:00
])
}
TxList.prototype.renderTransaction = function () {
const { txsToRender, conversionRate } = this.props
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' ])]
}
// TODO: Consider moving TxListItem into a separate component
TxList.prototype.renderTransactionListItem = function (transaction, conversionRate) {
2017-08-11 04:35:10 +02:00
const props = {
dateString: formatDate(transaction.time),
address: transaction.txParams.to,
transactionStatus: transaction.status,
transactionAmount: transaction.txParams.value,
transActionId: transaction.id,
transactionHash: transaction.hash,
transactionNetworkId: transaction.metamaskNetworkId,
2017-08-11 04:35:10 +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,
transActionId,
transactionHash,
transactionNetworkId,
2017-09-05 10:48:52 +02:00
} = props
const { showConfTxPage } = this.props
2017-09-05 10:48:52 +02:00
2017-08-30 12:33:00 +02:00
const opts = {
2017-09-14 10:09:57 +02:00
key: transActionId,
txParams: transaction.txParams,
2017-08-30 12:33:00 +02:00
transactionStatus,
transActionId,
dateString,
address,
transactionAmount,
transactionHash,
2017-09-07 20:25:31 +02:00
className: '.tx-list-item.tx-list-clickable',
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})
opts.className += '.tx-list-pending-item-container'
2017-09-07 20:38:21 +02:00
opts.transactionStatus = 'Not Started'
} else if (transactionHash) {
opts.onClick = () => this.view(transactionHash, transactionNetworkId)
2017-08-30 12:33:00 +02:00
}
2017-08-30 12:33:00 +02:00
return h(TxListItem, opts)
2017-08-09 12:10:51 +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}`
}