2017-08-30 12:33:00 +02:00
|
|
|
const Component = require('react').Component
|
|
|
|
const h = require('react-hyperscript')
|
2017-09-14 10:09:57 +02:00
|
|
|
const connect = require('react-redux').connect
|
2017-08-30 12:33:00 +02:00
|
|
|
const inherits = require('util').inherits
|
2017-09-12 23:59:33 +02:00
|
|
|
const classnames = require('classnames')
|
2017-09-14 10:09:57 +02:00
|
|
|
const abi = require('human-standard-token-abi')
|
|
|
|
const abiDecoder = require('abi-decoder')
|
|
|
|
abiDecoder.addABI(abi)
|
2017-09-07 18:18:13 +02:00
|
|
|
const prefixForNetwork = require('../../lib/etherscan-prefix-for-network')
|
2017-08-30 12:33:00 +02:00
|
|
|
const Identicon = require('./identicon')
|
|
|
|
|
2017-09-12 22:40:28 +02:00
|
|
|
const { conversionUtil } = require('../conversion-util')
|
|
|
|
|
2017-09-14 10:09:57 +02:00
|
|
|
module.exports = connect(mapStateToProps)(TxListItem)
|
|
|
|
|
|
|
|
function mapStateToProps (state) {
|
|
|
|
return {
|
|
|
|
tokens: state.metamask.tokens,
|
|
|
|
}
|
|
|
|
}
|
2017-08-30 12:33:00 +02:00
|
|
|
|
|
|
|
inherits(TxListItem, Component)
|
|
|
|
function TxListItem () {
|
|
|
|
Component.call(this)
|
|
|
|
}
|
|
|
|
|
2017-09-14 10:09:57 +02:00
|
|
|
TxListItem.prototype.getAddressText = function () {
|
|
|
|
const {
|
|
|
|
address,
|
|
|
|
txParams = {},
|
|
|
|
} = this.props
|
|
|
|
|
|
|
|
const decodedData = txParams.data && abiDecoder.decodeMethod(txParams.data)
|
|
|
|
const { name: txDataName, params = [] } = decodedData || {}
|
|
|
|
const { value } = params[0] || {}
|
|
|
|
|
|
|
|
switch (txDataName) {
|
|
|
|
case 'transfer':
|
|
|
|
return `${value.slice(0, 10)}...${value.slice(-4)}`
|
|
|
|
default:
|
|
|
|
return address
|
|
|
|
? `${address.slice(0, 10)}...${address.slice(-4)}`
|
|
|
|
: 'Contract Published'
|
|
|
|
}
|
2017-08-30 12:33:00 +02:00
|
|
|
}
|
|
|
|
|
2017-09-14 10:09:57 +02:00
|
|
|
TxListItem.prototype.getSendEtherTotal = function () {
|
2017-08-30 12:33:00 +02:00
|
|
|
const {
|
|
|
|
transactionAmount,
|
2017-09-12 22:40:28 +02:00
|
|
|
conversionRate,
|
2017-09-14 10:09:57 +02:00
|
|
|
address,
|
2017-08-30 12:33:00 +02:00
|
|
|
} = this.props
|
|
|
|
|
2017-09-14 10:09:57 +02:00
|
|
|
if (!address) {
|
|
|
|
return {}
|
|
|
|
}
|
|
|
|
|
2017-09-12 22:40:28 +02:00
|
|
|
const totalInUSD = conversionUtil(transactionAmount, {
|
|
|
|
fromNumericBase: 'hex',
|
|
|
|
toNumericBase: 'dec',
|
|
|
|
fromCurrency: 'ETH',
|
|
|
|
toCurrency: 'USD',
|
2017-09-14 04:20:13 +02:00
|
|
|
fromDenomination: 'WEI',
|
2017-09-12 22:40:28 +02:00
|
|
|
numberOfDecimals: 2,
|
|
|
|
conversionRate,
|
|
|
|
})
|
|
|
|
const totalInETH = conversionUtil(transactionAmount, {
|
|
|
|
fromNumericBase: 'hex',
|
|
|
|
toNumericBase: 'dec',
|
|
|
|
fromCurrency: 'ETH',
|
|
|
|
toCurrency: 'ETH',
|
2017-09-14 04:20:13 +02:00
|
|
|
fromDenomination: 'WEI',
|
2017-09-12 22:40:28 +02:00
|
|
|
conversionRate,
|
|
|
|
numberOfDecimals: 6,
|
|
|
|
})
|
|
|
|
|
2017-09-14 10:09:57 +02:00
|
|
|
return {
|
|
|
|
total: `${totalInETH} ETH`,
|
2017-09-15 13:23:12 +02:00
|
|
|
fiatTotal: `$${totalInUSD} USD`,
|
2017-09-14 10:09:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TxListItem.prototype.getSendTokenTotal = function () {
|
|
|
|
const {
|
|
|
|
txParams = {},
|
|
|
|
tokens,
|
|
|
|
} = this.props
|
|
|
|
|
|
|
|
const toAddress = txParams.to
|
|
|
|
const decodedData = txParams.data && abiDecoder.decodeMethod(txParams.data)
|
|
|
|
const { params = [] } = decodedData || {}
|
|
|
|
const { value } = params[1] || {}
|
|
|
|
const { decimals, symbol } = tokens.filter(({ address }) => address === toAddress)[0] || {}
|
|
|
|
|
|
|
|
const multiplier = Math.pow(10, Number(decimals || 0))
|
|
|
|
const total = Number(value / multiplier)
|
|
|
|
|
|
|
|
return {
|
|
|
|
total: `${total} ${symbol}`,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TxListItem.prototype.render = function () {
|
|
|
|
const {
|
|
|
|
transactionStatus,
|
|
|
|
onClick,
|
|
|
|
transActionId,
|
|
|
|
dateString,
|
|
|
|
address,
|
|
|
|
className,
|
|
|
|
txParams = {},
|
|
|
|
} = this.props
|
|
|
|
|
|
|
|
const decodedData = txParams.data && abiDecoder.decodeMethod(txParams.data)
|
|
|
|
const { name: txDataName } = decodedData || {}
|
|
|
|
|
|
|
|
const { total, fiatTotal } = txDataName === 'transfer'
|
|
|
|
? this.getSendTokenTotal()
|
|
|
|
: this.getSendEtherTotal()
|
|
|
|
|
2017-08-30 12:33:00 +02:00
|
|
|
return h(`div${className || ''}`, {
|
|
|
|
key: transActionId,
|
|
|
|
onClick: () => onClick && onClick(transActionId),
|
|
|
|
}, [
|
|
|
|
h(`div.flex-column.tx-list-item-wrapper`, {}, [
|
|
|
|
|
|
|
|
h('div.tx-list-date-wrapper', {
|
|
|
|
style: {},
|
|
|
|
}, [
|
|
|
|
h('span.tx-list-date', {}, [
|
|
|
|
dateString,
|
|
|
|
]),
|
|
|
|
]),
|
|
|
|
|
|
|
|
h('div.flex-row.tx-list-content-wrapper', {
|
|
|
|
style: {},
|
|
|
|
}, [
|
|
|
|
|
|
|
|
h('div.tx-list-identicon-wrapper', {
|
|
|
|
style: {},
|
|
|
|
}, [
|
|
|
|
h(Identicon, {
|
|
|
|
address,
|
|
|
|
diameter: 28,
|
|
|
|
}),
|
|
|
|
]),
|
|
|
|
|
|
|
|
h('div.tx-list-account-and-status-wrapper', {}, [
|
|
|
|
h('div.tx-list-account-wrapper', {
|
|
|
|
style: {},
|
|
|
|
}, [
|
|
|
|
h('span.tx-list-account', {}, [
|
|
|
|
this.getAddressText(address),
|
|
|
|
]),
|
|
|
|
]),
|
|
|
|
|
|
|
|
h('div.tx-list-status-wrapper', {
|
|
|
|
style: {},
|
|
|
|
}, [
|
2017-09-12 23:59:33 +02:00
|
|
|
h('span', {
|
|
|
|
className: classnames('tx-list-status', {
|
2017-09-14 10:09:57 +02:00
|
|
|
'tx-list-status--rejected': transactionStatus === 'rejected',
|
|
|
|
'tx-list-status--failed': transactionStatus === 'failed',
|
|
|
|
}),
|
|
|
|
},
|
2017-08-30 12:33:00 +02:00
|
|
|
transactionStatus,
|
2017-09-12 23:59:33 +02:00
|
|
|
),
|
2017-08-30 12:33:00 +02:00
|
|
|
]),
|
|
|
|
]),
|
|
|
|
|
|
|
|
h('div.flex-column.tx-list-details-wrapper', {
|
|
|
|
style: {},
|
|
|
|
}, [
|
|
|
|
|
2017-09-12 23:59:33 +02:00
|
|
|
h('span', {
|
|
|
|
className: classnames('tx-list-value', {
|
2017-09-14 10:09:57 +02:00
|
|
|
'tx-list-value--confirmed': transactionStatus === 'confirmed',
|
|
|
|
}),
|
|
|
|
}, total),
|
|
|
|
|
|
|
|
h('span.tx-list-fiat-value', fiatTotal),
|
2017-08-30 12:33:00 +02:00
|
|
|
|
|
|
|
]),
|
|
|
|
]),
|
|
|
|
]) // holding on icon from design
|
|
|
|
])
|
|
|
|
}
|