mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Show token tx properly
This commit is contained in:
parent
d722c1045f
commit
93a1089e08
@ -141,6 +141,7 @@ SendTokenScreen.prototype.submit = function () {
|
|||||||
hideWarning,
|
hideWarning,
|
||||||
addToAddressBook,
|
addToAddressBook,
|
||||||
signTokenTx,
|
signTokenTx,
|
||||||
|
selectedToken,
|
||||||
} = this.props
|
} = this.props
|
||||||
|
|
||||||
const { nickname = ' ' } = identities[to] || {}
|
const { nickname = ' ' } = identities[to] || {}
|
||||||
@ -161,7 +162,11 @@ SendTokenScreen.prototype.submit = function () {
|
|||||||
gasPrice: gasPrice,
|
gasPrice: gasPrice,
|
||||||
}
|
}
|
||||||
|
|
||||||
signTokenTx(selectedTokenAddress, to, Number(amount).toString(16), txParams)
|
const { decimals } = selectedToken || {}
|
||||||
|
const multiplier = Math.pow(10, Number(decimals || 0))
|
||||||
|
const sendAmount = Number(amount * multiplier).toString(16)
|
||||||
|
|
||||||
|
signTokenTx(selectedTokenAddress, to, sendAmount, txParams)
|
||||||
}
|
}
|
||||||
|
|
||||||
SendTokenScreen.prototype.renderToAddressInput = function () {
|
SendTokenScreen.prototype.renderToAddressInput = function () {
|
||||||
|
@ -1,37 +1,60 @@
|
|||||||
const Component = require('react').Component
|
const Component = require('react').Component
|
||||||
const h = require('react-hyperscript')
|
const h = require('react-hyperscript')
|
||||||
|
const connect = require('react-redux').connect
|
||||||
const inherits = require('util').inherits
|
const inherits = require('util').inherits
|
||||||
const classnames = require('classnames')
|
const classnames = require('classnames')
|
||||||
|
const abi = require('human-standard-token-abi')
|
||||||
|
const abiDecoder = require('abi-decoder')
|
||||||
|
abiDecoder.addABI(abi)
|
||||||
const prefixForNetwork = require('../../lib/etherscan-prefix-for-network')
|
const prefixForNetwork = require('../../lib/etherscan-prefix-for-network')
|
||||||
const Identicon = require('./identicon')
|
const Identicon = require('./identicon')
|
||||||
|
|
||||||
const { conversionUtil } = require('../conversion-util')
|
const { conversionUtil } = require('../conversion-util')
|
||||||
|
|
||||||
module.exports = TxListItem
|
module.exports = connect(mapStateToProps)(TxListItem)
|
||||||
|
|
||||||
|
function mapStateToProps (state) {
|
||||||
|
return {
|
||||||
|
tokens: state.metamask.tokens,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
inherits(TxListItem, Component)
|
inherits(TxListItem, Component)
|
||||||
function TxListItem () {
|
function TxListItem () {
|
||||||
Component.call(this)
|
Component.call(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
TxListItem.prototype.getAddressText = function (address) {
|
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
|
return address
|
||||||
? `${address.slice(0, 10)}...${address.slice(-4)}`
|
? `${address.slice(0, 10)}...${address.slice(-4)}`
|
||||||
: 'Contract Published'
|
: 'Contract Published'
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TxListItem.prototype.render = function () {
|
TxListItem.prototype.getSendEtherTotal = function () {
|
||||||
const {
|
const {
|
||||||
transactionStatus,
|
|
||||||
onClick,
|
|
||||||
transActionId,
|
|
||||||
dateString,
|
|
||||||
address,
|
|
||||||
transactionAmount,
|
transactionAmount,
|
||||||
className,
|
|
||||||
conversionRate,
|
conversionRate,
|
||||||
|
address,
|
||||||
} = this.props
|
} = this.props
|
||||||
|
|
||||||
|
if (!address) {
|
||||||
|
return {}
|
||||||
|
}
|
||||||
|
|
||||||
const totalInUSD = conversionUtil(transactionAmount, {
|
const totalInUSD = conversionUtil(transactionAmount, {
|
||||||
fromNumericBase: 'hex',
|
fromNumericBase: 'hex',
|
||||||
toNumericBase: 'dec',
|
toNumericBase: 'dec',
|
||||||
@ -49,6 +72,50 @@ TxListItem.prototype.render = function () {
|
|||||||
numberOfDecimals: 6,
|
numberOfDecimals: 6,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
total: `${totalInETH} ETH`,
|
||||||
|
fiatTotal: `${totalInUSD} USD`,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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()
|
||||||
|
|
||||||
return h(`div${className || ''}`, {
|
return h(`div${className || ''}`, {
|
||||||
key: transActionId,
|
key: transActionId,
|
||||||
onClick: () => onClick && onClick(transActionId),
|
onClick: () => onClick && onClick(transActionId),
|
||||||
@ -90,8 +157,9 @@ TxListItem.prototype.render = function () {
|
|||||||
}, [
|
}, [
|
||||||
h('span', {
|
h('span', {
|
||||||
className: classnames('tx-list-status', {
|
className: classnames('tx-list-status', {
|
||||||
'tx-list-status--rejected': transactionStatus === 'rejected'
|
'tx-list-status--rejected': transactionStatus === 'rejected',
|
||||||
})
|
'tx-list-status--failed': transactionStatus === 'failed',
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
transactionStatus,
|
transactionStatus,
|
||||||
),
|
),
|
||||||
@ -104,15 +172,11 @@ TxListItem.prototype.render = function () {
|
|||||||
|
|
||||||
h('span', {
|
h('span', {
|
||||||
className: classnames('tx-list-value', {
|
className: classnames('tx-list-value', {
|
||||||
'tx-list-value--confirmed': transactionStatus === 'confirmed'
|
'tx-list-value--confirmed': transactionStatus === 'confirmed',
|
||||||
})
|
}),
|
||||||
},
|
}, total),
|
||||||
`${totalInETH} ETH`,
|
|
||||||
),
|
|
||||||
|
|
||||||
h('span.tx-list-fiat-value', {}, [
|
h('span.tx-list-fiat-value', fiatTotal),
|
||||||
`${totalInUSD} USD`,
|
|
||||||
]),
|
|
||||||
|
|
||||||
]),
|
]),
|
||||||
]),
|
]),
|
||||||
|
@ -49,7 +49,7 @@ TxList.prototype.renderTransaction = function () {
|
|||||||
const { txsToRender, conversionRate } = this.props
|
const { txsToRender, conversionRate } = this.props
|
||||||
|
|
||||||
return txsToRender.length
|
return txsToRender.length
|
||||||
? txsToRender.map((transaction) => this.renderTransactionListItem(transaction, conversionRate))
|
? txsToRender.map((transaction, i) => this.renderTransactionListItem(transaction, conversionRate))
|
||||||
: [h('div.tx-list-item.tx-list-item--empty', [ 'No Transactions' ])]
|
: [h('div.tx-list-item.tx-list-item--empty', [ 'No Transactions' ])]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,7 +77,8 @@ TxList.prototype.renderTransactionListItem = function (transaction, conversionRa
|
|||||||
const { showConfTxPage } = this.props
|
const { showConfTxPage } = this.props
|
||||||
|
|
||||||
const opts = {
|
const opts = {
|
||||||
key: transactionHash,
|
key: transActionId,
|
||||||
|
txParams: transaction.txParams,
|
||||||
transactionStatus,
|
transactionStatus,
|
||||||
transActionId,
|
transActionId,
|
||||||
dateString,
|
dateString,
|
||||||
|
@ -66,11 +66,11 @@
|
|||||||
flex-flow: column nowrap;
|
flex-flow: column nowrap;
|
||||||
|
|
||||||
@media screen and (max-width: $break-small) {
|
@media screen and (max-width: $break-small) {
|
||||||
padding: 0 1.3em .95em;
|
padding: 0 1.3em;
|
||||||
}
|
}
|
||||||
|
|
||||||
@media screen and (min-width: $break-large) {
|
@media screen and (min-width: $break-large) {
|
||||||
// margin: 0 2.37em;
|
padding-bottom: 12px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,16 +79,12 @@
|
|||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
background: rgba($alto, .2);
|
background: rgba($alto, .2);
|
||||||
|
|
||||||
.tx-list-details-wrapper {
|
|
||||||
background: transparent;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.tx-list-pending-item-container {
|
.tx-list-pending-item-container {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
opacity: 0.5;
|
opacity: .5;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tx-list-date-wrapper {
|
.tx-list-date-wrapper {
|
||||||
@ -96,11 +92,10 @@
|
|||||||
|
|
||||||
@media screen and (max-width: $break-small) {
|
@media screen and (max-width: $break-small) {
|
||||||
margin-top: 6px;
|
margin-top: 6px;
|
||||||
margin-bottom: 20px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@media screen and (min-width: $break-large) {
|
@media screen and (min-width: $break-large) {
|
||||||
margin-top: 13px;
|
margin-top: 12px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,6 +144,7 @@
|
|||||||
.tx-list-account-and-status-wrapper {
|
.tx-list-account-and-status-wrapper {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex: 1 1 auto;
|
flex: 1 1 auto;
|
||||||
|
flex-flow: row wrap;
|
||||||
width: 0;
|
width: 0;
|
||||||
|
|
||||||
@media screen and (max-width: $break-small) {
|
@media screen and (max-width: $break-small) {
|
||||||
@ -184,7 +180,8 @@
|
|||||||
text-transform: capitalize;
|
text-transform: capitalize;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tx-list-status--rejected {
|
.tx-list-status--rejected,
|
||||||
|
.tx-list-status--failed {
|
||||||
color: $monzo;
|
color: $monzo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -238,7 +235,6 @@
|
|||||||
.tx-list-details-wrapper {
|
.tx-list-details-wrapper {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
flex: 0 0 35%;
|
flex: 0 0 35%;
|
||||||
background: rgba($white, .8);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.tx-list-value {
|
.tx-list-value {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user