1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00
metamask-extension/ui/app/components/pending-tx-details.js

240 lines
6.1 KiB
JavaScript
Raw Normal View History

2016-06-24 21:48:52 +02:00
const Component = require('react').Component
const h = require('react-hyperscript')
const inherits = require('util').inherits
2016-07-07 02:58:46 +02:00
const MiniAccountPanel = require('./mini-account-panel')
2016-09-07 02:28:25 +02:00
const EthBalance = require('./eth-balance')
const util = require('../util')
const addressSummary = util.addressSummary
2016-07-07 02:58:46 +02:00
const nameForAddress = require('../../lib/contract-namer')
2016-07-07 07:48:02 +02:00
const ethUtil = require('ethereumjs-util')
const BN = ethUtil.BN
2016-06-24 21:48:52 +02:00
module.exports = PendingTxDetails
inherits(PendingTxDetails, Component)
function PendingTxDetails () {
Component.call(this)
}
2016-07-07 02:58:46 +02:00
const PTXP = PendingTxDetails.prototype
2016-06-24 21:48:52 +02:00
2016-07-07 02:58:46 +02:00
PTXP.render = function () {
2016-07-07 06:32:36 +02:00
var props = this.props
var txData = props.txData
2016-06-24 21:48:52 +02:00
var txParams = txData.txParams || {}
var address = txParams.from || props.selectedAccount
2016-07-07 06:32:36 +02:00
var identity = props.identities[address] || { address: address }
var account = props.accounts[address]
var balance = account ? account.balance : '0x0'
2016-06-24 21:48:52 +02:00
2016-10-13 04:35:09 +02:00
var gasMultiplier = txData.gasMultiplier
var gasCost = new BN(ethUtil.stripHexPrefix(txParams.gas || txData.estimatedGas), 16)
var gasPrice = new BN(ethUtil.stripHexPrefix(txParams.gasPrice || '0x4a817c800'), 16)
2016-10-14 01:04:23 +02:00
gasPrice = gasPrice.mul(new BN(gasMultiplier * 100), 10).div(new BN(100, 10))
var txFee = gasCost.mul(gasPrice)
var txValue = new BN(ethUtil.stripHexPrefix(txParams.value || '0x0'), 16)
var maxCost = txValue.add(txFee)
2016-07-07 08:35:59 +02:00
var dataLength = txParams.data ? (txParams.data.length - 2) / 2 : 0
2016-07-07 06:32:36 +02:00
2016-07-08 01:54:35 +02:00
var imageify = props.imageifyIdenticons === undefined ? true : props.imageifyIdenticons
2016-07-07 02:58:46 +02:00
return (
2016-06-24 21:48:52 +02:00
h('div', [
2016-07-07 02:58:46 +02:00
h('.flex-row.flex-center', {
style: {
maxWidth: '100%',
},
}, [
h(MiniAccountPanel, {
imageSeed: address,
2016-07-08 01:54:35 +02:00
imageifyIdenticons: imageify,
2016-07-07 02:58:46 +02:00
picOrder: 'right',
}, [
h('span.font-small', {
style: {
fontFamily: 'Montserrat Bold, Montserrat, sans-serif',
},
}, identity.name),
h('span.font-small', {
style: {
fontFamily: 'Montserrat Light, Montserrat, sans-serif',
},
}, addressSummary(address, 6, 4, false)),
h('span.font-small', {
style: {
fontFamily: 'Montserrat Light, Montserrat, sans-serif',
},
2016-07-08 01:54:35 +02:00
}, [
2016-09-07 02:28:25 +02:00
h(EthBalance, {
2016-07-08 01:54:35 +02:00
value: balance,
inline: true,
labelColor: '#F7861C',
2016-07-08 02:00:24 +02:00
}),
2016-07-08 01:54:35 +02:00
]),
]),
2016-07-07 02:58:46 +02:00
forwardCarrat(),
2016-07-07 02:58:46 +02:00
this.miniAccountPanelForRecipient(),
]),
2016-06-24 21:48:52 +02:00
2016-07-07 06:32:36 +02:00
h('style', `
.table-box {
margin: 7px 0px 0px 0px;
width: 100%;
2016-07-07 06:32:36 +02:00
}
.table-box .row {
margin: 0px;
background: rgb(236,236,236);
display: flex;
justify-content: space-between;
font-family: Montserrat Light, sans-serif;
font-size: 13px;
padding: 5px 25px;
}
.table-box .row .value {
font-family: Montserrat Regular;
2016-07-07 06:32:36 +02:00
}
`),
h('.table-box', [
h('.row', [
h('.cell.label', 'Amount'),
2016-09-07 02:28:25 +02:00
h(EthBalance, { value: txParams.value }),
2016-06-24 21:48:52 +02:00
]),
2016-07-07 06:32:36 +02:00
h('.cell.row', [
h('.cell.label', 'Max Transaction Fee'),
2016-09-07 02:28:25 +02:00
h(EthBalance, { value: txFee.toString(16) }),
2016-06-24 21:48:52 +02:00
]),
2016-07-07 06:32:36 +02:00
h('.cell.row', {
style: {
fontFamily: 'Montserrat Regular',
background: 'white',
padding: '10px 25px',
2016-07-07 06:32:36 +02:00
},
}, [
h('.cell.label', 'Max Total'),
h('.cell.value', {
style: {
display: 'flex',
alignItems: 'center',
},
}, [
2016-09-07 02:28:25 +02:00
h(EthBalance, {
value: maxCost.toString(16),
inline: true,
labelColor: 'black',
fontSize: '16px',
}),
]),
2016-06-24 21:48:52 +02:00
]),
2016-07-07 06:32:36 +02:00
h('.cell.row', {
style: {
background: '#f7f7f7',
paddingBottom: '0px',
2016-07-07 07:48:02 +02:00
},
2016-07-07 06:32:36 +02:00
}, [
h('.cell.label'),
h('.cell.value', {
style: {
fontFamily: 'Montserrat Light',
fontSize: '11px',
},
}, `Data included: ${dataLength} bytes`),
2016-07-07 07:48:02 +02:00
]),
2016-07-07 06:32:36 +02:00
]), // End of Table
this.warnIfNeeded(),
2016-06-24 21:48:52 +02:00
])
)
2016-07-07 02:58:46 +02:00
}
2016-06-24 21:48:52 +02:00
2016-07-07 07:48:02 +02:00
PTXP.miniAccountPanelForRecipient = function () {
2016-07-07 06:32:36 +02:00
var props = this.props
var txData = props.txData
2016-07-07 02:58:46 +02:00
var txParams = txData.txParams || {}
var isContractDeploy = !('to' in txParams)
2016-07-12 00:49:13 +02:00
var imageify = props.imageifyIdenticons === undefined ? true : props.imageifyIdenticons
2016-07-07 02:58:46 +02:00
// If it's not a contract deploy, send to the account
if (!isContractDeploy) {
return h(MiniAccountPanel, {
2016-07-07 07:48:02 +02:00
imageSeed: txParams.to,
2016-07-12 00:49:13 +02:00
imageifyIdenticons: imageify,
2016-07-07 02:58:46 +02:00
picOrder: 'left',
}, [
h('span.font-small', {
style: {
fontFamily: 'Montserrat Bold, Montserrat, sans-serif',
},
}, nameForAddress(txParams.to, props.identities)),
h('span.font-small', {
style: {
fontFamily: 'Montserrat Light, Montserrat, sans-serif',
},
}, addressSummary(txParams.to, 6, 4, false)),
])
2016-07-07 02:58:46 +02:00
} else {
2016-07-07 07:48:02 +02:00
return h(MiniAccountPanel, {
2016-07-12 00:49:13 +02:00
imageifyIdenticons: imageify,
2016-07-07 02:58:46 +02:00
picOrder: 'left',
}, [
h('span.font-small', {
style: {
fontFamily: 'Montserrat Bold, Montserrat, sans-serif',
},
}, 'New Contract'),
])
2016-07-07 02:58:46 +02:00
}
2016-06-24 21:48:52 +02:00
}
2016-07-07 02:58:46 +02:00
2016-07-07 06:32:36 +02:00
// Should analyze if there is a DELEGATECALL opcode
// in the recipient contract, and show a warning if so.
2016-07-07 07:48:02 +02:00
PTXP.warnIfNeeded = function () {
const containsDelegateCall = !!this.props.txData.containsDelegateCall
if (!containsDelegateCall) {
return null
}
2016-07-07 06:32:36 +02:00
return h('span.error', {
style: {
fontFamily: 'Montserrat Light',
fontSize: '13px',
display: 'flex',
justifyContent: 'center',
2016-07-07 07:48:02 +02:00
},
2016-07-07 06:32:36 +02:00
}, [
h('i.fa.fa-lg.fa-info-circle', { style: { margin: '5px' } }),
h('span', ' Your identity may be used in other contracts!'),
])
}
2016-07-08 01:54:35 +02:00
function forwardCarrat () {
return (
2016-07-08 01:54:35 +02:00
h('img', {
src: 'images/forward-carrat.svg',
style: {
padding: '5px 6px 0px 10px',
height: '37px',
},
})
2016-07-08 01:54:35 +02:00
)
2016-07-12 00:49:13 +02:00
}