aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/transaction-list-item.js
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2016-05-26 08:57:08 +0800
committerDan Finlay <dan@danfinlay.com>2016-05-26 08:57:08 +0800
commit21af266fde3a9147f43ee1186daae275dc2a5eed (patch)
tree79dd2d111f5d6d8c25b839fa3b3b3710dd7a78c7 /ui/app/components/transaction-list-item.js
parent45ae2a0be374d862b6910c8344ec9f888fef9c46 (diff)
downloadtangerine-wallet-browser-21af266fde3a9147f43ee1186daae275dc2a5eed.tar.gz
tangerine-wallet-browser-21af266fde3a9147f43ee1186daae275dc2a5eed.tar.zst
tangerine-wallet-browser-21af266fde3a9147f43ee1186daae275dc2a5eed.zip
Move transaction list item into its own component
Diffstat (limited to 'ui/app/components/transaction-list-item.js')
-rw-r--r--ui/app/components/transaction-list-item.js126
1 files changed, 126 insertions, 0 deletions
diff --git a/ui/app/components/transaction-list-item.js b/ui/app/components/transaction-list-item.js
new file mode 100644
index 000000000..a0715db0b
--- /dev/null
+++ b/ui/app/components/transaction-list-item.js
@@ -0,0 +1,126 @@
+const Component = require('react').Component
+const h = require('react-hyperscript')
+const inherits = require('util').inherits
+
+const Identicon = require('./identicon')
+const EtherBalance = require('./eth-balance')
+const addressSummary = require('../util').addressSummary
+const explorerLink = require('../../lib/explorer-link')
+const formatBalance = require('../util').formatBalance
+const vreme = new (require('vreme'))
+
+module.exports = TransactionListItem
+
+
+inherits(TransactionListItem, Component)
+function TransactionListItem() {
+ Component.call(this)
+}
+
+TransactionListItem.prototype.render = function() {
+ const { transaction, i } = this.props
+
+ var date = formatDate(transaction.time)
+
+ var isMsg = ('msgParams' in transaction)
+ var isTx = ('txParams' in transaction)
+
+ var txParams = transaction.txParams
+
+ return (
+ h(`.transaction-list-item.flex-row.flex-space-between${transaction.hash ? '.pointer' : ''}`, {
+ key: `tx-${transaction.id + i}`,
+ onClick: (event) => {
+ if (!transaction.hash) return
+ var url = explorerLink(transaction.hash, parseInt(network))
+ chrome.tabs.create({ url })
+ },
+ style: {
+ padding: '20px 0',
+ },
+ }, [
+
+ // large identicon
+ h('.identicon-wrapper.flex-column.flex-center.select-none', [
+ identicon(txParams, transaction),
+ ]),
+
+ h('.flex-column', [
+
+ h('div', date),
+
+ recipientField(txParams, transaction),
+
+ ]),
+
+ h(EtherBalance, {
+ value: txParams.value,
+ }),
+ ])
+ )
+}
+
+
+function recipientField(txParams, transaction) {
+ if (txParams.to) {
+ return h('div', {
+ style: {
+ fontSize: 'small',
+ color: '#ABA9AA',
+ },
+ }, [
+ addressSummary(txParams.to),
+ failIfFailed(transaction),
+ ])
+
+ } else {
+
+ return h('div', {
+ style: {
+ fontSize: 'small',
+ color: '#ABA9AA',
+ },
+ },[
+ 'Contract Published',
+ failIfFailed(transaction),
+ ])
+ }
+}
+
+TransactionListItem.prototype.renderMessage = function() {
+ const { transaction, i } = this.props
+ return h('div', 'wowie, thats a message')
+}
+
+function formatDate(date){
+ return vreme.format(new Date(date), 'March 16 2014 14:30')
+}
+
+function identicon(txParams, transaction) {
+ if (transaction.status === 'rejected') {
+ return h('i.fa.fa-exclamation-triangle.fa-lg.error', {
+ style: {
+ width: '24px',
+ }
+ })
+ }
+
+ if (txParams.to) {
+ return h(Identicon, {
+ diameter: 24,
+ address: txParams.to || transaction.hash,
+ })
+ } else {
+ return h('i.fa.fa-file-text-o.fa-lg', {
+ style: {
+ width: '24px',
+ }
+ })
+ }
+}
+
+function failIfFailed(transaction) {
+ if (transaction.status === 'rejected') {
+ return h('span.error', ' (Failed)')
+ }
+}