1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-30 08:09:15 +01:00
metamask-extension/ui/app/components/pending-tx-details.js

172 lines
4.4 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-06-24 21:48:52 +02:00
const addressSummary = require('../util').addressSummary
const formatBalance = require('../util').formatBalance
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
const baseGasFee = new BN('21000', 10)
const gasCost = new BN('10000000000', 10)
const baseFeeHex = baseGasFee.mul(gasCost).toString(16)
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 || {}
2016-07-07 06:32:36 +02:00
var address = txParams.from || props.selectedAddress
var identity = props.identities[address] || { address: address }
2016-06-24 21:48:52 +02:00
2016-07-07 07:48:02 +02:00
var gasCost = ethUtil.stripHexPrefix(txParams.gas || baseFeeHex)
var txValue = ethUtil.stripHexPrefix(txParams.value || '0x0')
var maxCost = ((new BN(txValue, 16)).add(new BN(gasCost, 16))).toString(16)
var dataLength = txParams.data ? txParams.data.length - 2 : 0
2016-07-07 06:32:36 +02:00
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, {
attrs: [
identity.name,
addressSummary(address, 6, 4, false),
2016-07-07 06:32:36 +02:00
formatBalance(identity.balance).formatted,
2016-07-07 02:58:46 +02:00
],
imageSeed: address,
2016-07-07 06:32:36 +02:00
imageifyIdenticons: props.imageifyIdenticons,
2016-07-07 02:58:46 +02:00
picOrder: 'right',
}),
h('img', {
src: 'images/forward-carrat.svg',
style: {
padding: '5px 6px 0px 10px',
height: '48px',
},
}),
this.miniAccountPanelForRecipient(),
]),
2016-06-24 21:48:52 +02:00
2016-07-07 06:32:36 +02:00
h('style', `
.table-box {
margin: 7px 6px 0px 6px;
}
.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 15px;
}
`),
h('.table-box', [
h('.row', [
h('.cell.label', 'Amount'),
h('.cell.value', formatBalance(txParams.value).formatted),
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-07-07 07:48:02 +02:00
h('.cell.value', formatBalance(gasCost).formatted),
2016-06-24 21:48:52 +02:00
]),
2016-07-07 06:32:36 +02:00
h('.cell.row', {
style: {
fontFamily: 'Montserrat Regular',
background: 'rgb(216,216,216)',
},
}, [
h('.cell.label', 'Max Total'),
h('.cell.value', formatBalance(maxCost).formatted),
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'),
2016-07-07 07:48:02 +02:00
h('.cell.value', `Data included: ${dataLength} bytes`),
]),
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)
// If it's not a contract deploy, send to the account
if (!isContractDeploy) {
return h(MiniAccountPanel, {
attrs: [
nameForAddress(txParams.to),
addressSummary(txParams.to, 6, 4, false),
],
2016-07-07 07:48:02 +02:00
imageSeed: txParams.to,
2016-07-07 06:32:36 +02:00
imageifyIdenticons: props.imageifyIdenticons,
2016-07-07 02:58:46 +02:00
picOrder: 'left',
})
} else {
2016-07-07 07:48:02 +02:00
return h(MiniAccountPanel, {
2016-07-07 02:58:46 +02:00
attrs: [
2016-07-07 07:48:02 +02:00
'New Contract',
2016-07-07 02:58:46 +02:00
],
2016-07-07 06:32:36 +02:00
imageifyIdenticons: props.imageifyIdenticons,
2016-07-07 02:58:46 +02:00
picOrder: 'left',
})
}
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!'),
])
}