nifty-wallet/ui/app/components/pending-tx-details.js

175 lines
4.4 KiB
JavaScript
Raw Normal View History

2016-06-24 12:48:52 -07:00
const Component = require('react').Component
const h = require('react-hyperscript')
const inherits = require('util').inherits
2016-07-06 17:58:46 -07:00
const MiniAccountPanel = require('./mini-account-panel')
2016-06-24 12:48:52 -07:00
const addressSummary = require('../util').addressSummary
const formatBalance = require('../util').formatBalance
2016-07-06 17:58:46 -07:00
const nameForAddress = require('../../lib/contract-namer')
2016-07-06 22:48:02 -07:00
const ethUtil = require('ethereumjs-util')
const BN = ethUtil.BN
const baseGasFee = new BN('21000', 10)
2016-07-06 23:16:04 -07:00
const gasCost = new BN('4a817c800', 16)
2016-07-06 22:48:02 -07:00
const baseFeeHex = baseGasFee.mul(gasCost).toString(16)
2016-06-24 12:48:52 -07:00
module.exports = PendingTxDetails
inherits(PendingTxDetails, Component)
function PendingTxDetails () {
Component.call(this)
}
2016-07-06 17:58:46 -07:00
const PTXP = PendingTxDetails.prototype
2016-06-24 12:48:52 -07:00
2016-07-06 17:58:46 -07:00
PTXP.render = function () {
2016-07-06 21:32:36 -07:00
var props = this.props
var txData = props.txData
2016-06-24 12:48:52 -07:00
var txParams = txData.txParams || {}
2016-07-06 21:32:36 -07:00
var address = txParams.from || props.selectedAddress
var identity = props.identities[address] || { address: address }
var balance = props.accounts[address].balance
2016-06-24 12:48:52 -07:00
2016-07-06 22:48:02 -07: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)
2016-07-06 23:35:59 -07:00
var dataLength = txParams.data ? (txParams.data.length - 2) / 2 : 0
2016-07-06 21:32:36 -07:00
console.dir(identity)
console.dir({props})
2016-07-06 17:58:46 -07:00
return (
2016-06-24 12:48:52 -07:00
h('div', [
2016-07-06 17:58:46 -07:00
h('.flex-row.flex-center', {
style: {
maxWidth: '100%',
},
}, [
h(MiniAccountPanel, {
attrs: [
identity.name,
addressSummary(address, 6, 4, false),
formatBalance(balance),
2016-07-06 17:58:46 -07:00
],
imageSeed: address,
2016-07-06 21:32:36 -07:00
imageifyIdenticons: props.imageifyIdenticons,
2016-07-06 17:58:46 -07:00
picOrder: 'right',
}),
h('img', {
src: 'images/forward-carrat.svg',
style: {
padding: '5px 6px 0px 10px',
height: '48px',
},
}),
this.miniAccountPanelForRecipient(),
]),
2016-06-24 12:48:52 -07:00
2016-07-06 21:32:36 -07: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)),
2016-06-24 12:48:52 -07:00
]),
2016-07-06 21:32:36 -07:00
h('.cell.row', [
h('.cell.label', 'Max Transaction Fee'),
h('.cell.value', formatBalance(gasCost)),
2016-06-24 12:48:52 -07:00
]),
2016-07-06 21:32:36 -07:00
h('.cell.row', {
style: {
fontFamily: 'Montserrat Regular',
background: 'rgb(216,216,216)',
},
}, [
h('.cell.label', 'Max Total'),
h('.cell.value', formatBalance(maxCost)),
2016-06-24 12:48:52 -07:00
]),
2016-07-06 21:32:36 -07:00
h('.cell.row', {
style: {
background: '#f7f7f7',
paddingBottom: '0px',
2016-07-06 22:48:02 -07:00
},
2016-07-06 21:32:36 -07:00
}, [
h('.cell.label'),
2016-07-06 22:48:02 -07:00
h('.cell.value', `Data included: ${dataLength} bytes`),
]),
2016-07-06 21:32:36 -07:00
]), // End of Table
this.warnIfNeeded(),
2016-06-24 12:48:52 -07:00
])
)
2016-07-06 17:58:46 -07:00
}
2016-06-24 12:48:52 -07:00
2016-07-06 22:48:02 -07:00
PTXP.miniAccountPanelForRecipient = function () {
2016-07-06 21:32:36 -07:00
var props = this.props
var txData = props.txData
2016-07-06 17:58:46 -07: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-06 22:48:02 -07:00
imageSeed: txParams.to,
2016-07-06 21:32:36 -07:00
imageifyIdenticons: props.imageifyIdenticons,
2016-07-06 17:58:46 -07:00
picOrder: 'left',
})
} else {
2016-07-06 22:48:02 -07:00
return h(MiniAccountPanel, {
2016-07-06 17:58:46 -07:00
attrs: [
2016-07-06 22:48:02 -07:00
'New Contract',
2016-07-06 17:58:46 -07:00
],
2016-07-06 21:32:36 -07:00
imageifyIdenticons: props.imageifyIdenticons,
2016-07-06 17:58:46 -07:00
picOrder: 'left',
})
}
2016-06-24 12:48:52 -07:00
}
2016-07-06 17:58:46 -07:00
2016-07-06 21:32:36 -07:00
// Should analyze if there is a DELEGATECALL opcode
// in the recipient contract, and show a warning if so.
2016-07-06 22:48:02 -07:00
PTXP.warnIfNeeded = function () {
const containsDelegateCall = !!this.props.txData.containsDelegateCall
if (!containsDelegateCall) {
return null
}
2016-07-06 21:32:36 -07:00
return h('span.error', {
style: {
fontFamily: 'Montserrat Light',
fontSize: '13px',
display: 'flex',
justifyContent: 'center',
2016-07-06 22:48:02 -07:00
},
2016-07-06 21:32:36 -07:00
}, [
h('i.fa.fa-lg.fa-info-circle', { style: { margin: '5px' } }),
h('span', ' Your identity may be used in other contracts!'),
])
}