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

150 lines
3.2 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)
}
TxList.prototype.render = function () {
// 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', {
2017-09-05 10:48:52 +02:00
style: {},
}, 'transactions'),
2017-08-09 12:10:51 +02:00
]),
2017-08-09 12:10:51 +02:00
]),
this.renderTranstions(),
2017-08-09 12:10:51 +02:00
])
}
TxList.prototype.getAddressText = function (transaction) {
const {
txParams: { to },
} = transaction
return to
? `${to.slice(0, 10)}...${to.slice(-4)}`
: 'Contract Published'
}
TxList.prototype.renderTranstions = function () {
const { txsToRender } = this.props
return txsToRender.length
? txsToRender.map((transaction) => {
return this.renderTransactionListItem(transaction)
})
: h('div.tx-list-item.tx-list-item--empty', [ 'No Transactions' ])
}
// 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
}
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,
} = props
return h('div.tx-list-item', {
2017-09-05 10:48:52 +02:00
key: transaction.id,
}, [
h('div.flex-column.tx-list-item__wrapper', {
2017-09-05 10:48:52 +02:00
style: {},
2017-08-09 12:10:51 +02:00
}, [
h('div.tx-list-date-wrapper', {
2017-09-05 10:48:52 +02:00
style: {},
2017-08-11 04:35:10 +02:00
}, [
h('span.tx-list-date', {}, [
dateString,
2017-09-05 10:48:52 +02:00
]),
2017-08-11 04:35:10 +02:00
]),
2017-08-09 12:10:51 +02:00
h('div.flex-row.tx-list-content-wrapper', {
2017-09-05 10:48:52 +02:00
style: {},
}, [
h('div.tx-list-identicon-wrapper', {
2017-09-05 10:48:52 +02:00
style: {},
}, [
h(Identicon, {
address,
diameter: 28,
2017-09-05 10:48:52 +02:00
}),
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', {
2017-09-05 10:48:52 +02:00
style: {},
}, [
h('span.tx-list-account', {}, [
this.getAddressText(transaction),
]),
]),
h('div.tx-list-status-wrapper', {
2017-09-05 10:48:52 +02:00
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', {
2017-09-05 10:48:52 +02:00
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
]),
2017-08-09 12:10:51 +02:00
])
}