1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-23 11:46:13 +02:00
metamask-extension/ui/app/components/tx-list.js

134 lines
2.9 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
2017-08-11 04:35:10 +02:00
const selectors = require('../selectors')
const Identicon = require('./identicon')
const { formatBalance, formatDate } = require('../util')
2017-08-09 12:10:51 +02:00
module.exports = connect(mapStateToProps)(TxList)
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
}
}
inherits(TxList, Component)
function TxList () {
Component.call(this)
}
const contentDivider = h('div.tx-list-content-divider', {
style: {},
2017-08-09 12:10:51 +02:00
})
TxList.prototype.render = function () {
2017-08-29 16:50:48 +02:00
const { txsToRender } = this.props
2017-08-09 12:10:51 +02:00
console.log('transactions to render', txsToRender)
2017-08-09 12:10:51 +02:00
return h('div.flex-column.tx-list-container', {}, [
h('div.flex-row.tx-list-header-wrapper', {
style: {},
2017-08-09 12:10:51 +02:00
}, [
h('div.flex-row.tx-list-header', {
2017-08-09 12:10:51 +02:00
}, [
h('div', {
style: {}
}, 'transactions'),
2017-08-09 12:10:51 +02:00
]),
2017-08-09 12:10:51 +02:00
]),
contentDivider,
txsToRender.map((transaction) => {
return this.renderTransactionListItem(transaction)
}),
2017-08-09 12:10:51 +02:00
])
}
// TODO: Consider moving TxListItem into a separate component
TxList.prototype.renderTransactionListItem = function (transaction) {
2017-08-11 04:35:10 +02:00
const props = {
dateString: formatDate(transaction.time),
address: transaction.txParams.to,
transactionStatus: transaction.status,
transactionAmount: formatBalance(transaction.txParams.value, 6),
2017-08-11 04:35:10 +02:00
}
const { address, transactionStatus, transactionAmount, dateString } = props
return h('div', {}, [
h('div.flex-column.tx-list-item-wrapper', {
style: {}
2017-08-09 12:10:51 +02:00
}, [
h('div.tx-list-date-wrapper', {
style: {}
2017-08-11 04:35:10 +02:00
}, [
h('span.tx-list-date', {}, [
dateString,
])
2017-08-11 04:35:10 +02:00
]),
2017-08-09 12:10:51 +02:00
h('div.flex-row.tx-list-content-wrapper', {
style: {}
}, [
h('div.tx-list-identicon-wrapper', {
style: {}
}, [
h(Identicon, {
address,
diameter: 28,
})
2017-08-11 04:35:10 +02:00
]),
2017-08-09 12:10:51 +02:00
h('div.tx-list-account-and-status-wrapper', {}, [
h('div.tx-list-account-wrapper', {
style: {}
}, [
h('span.tx-list-account', {}, [
`${address.slice(0, 10)}...${address.slice(-4)}`
]),
]),
h('div.tx-list-status-wrapper', {
style: {}
}, [
h('span.tx-list-status', {}, [
transactionStatus,
]),
]),
2017-08-11 04:35:10 +02:00
]),
2017-08-09 12:10:51 +02:00
h('div.flex-column.tx-list-details-wrapper', {
style: {}
}, [
2017-08-09 12:10:51 +02:00
h('span.tx-list-value', {}, [
transactionAmount,
]),
h('span.tx-list-fiat-value', {}, [
'+ $300 USD',
]),
2017-08-11 04:35:10 +02:00
]),
2017-08-09 12:10:51 +02:00
2017-08-11 04:35:10 +02:00
]),
2017-08-29 16:50:48 +02:00
]),
contentDivider
2017-08-09 12:10:51 +02:00
])
}