2016-06-24 21:48:52 +02:00
|
|
|
const Component = require('react').Component
|
|
|
|
const h = require('react-hyperscript')
|
|
|
|
const inherits = require('util').inherits
|
2017-02-28 01:06:28 +01:00
|
|
|
const extend = require('xtend')
|
2017-02-28 03:18:39 +01:00
|
|
|
const ethUtil = require('ethereumjs-util')
|
|
|
|
const BN = ethUtil.BN
|
2016-06-24 21:48:52 +02:00
|
|
|
|
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')
|
2016-09-15 19:24:05 +02:00
|
|
|
const util = require('../util')
|
|
|
|
const addressSummary = util.addressSummary
|
2016-07-07 02:58:46 +02:00
|
|
|
const nameForAddress = require('../../lib/contract-namer')
|
2017-02-27 22:53:43 +01:00
|
|
|
const HexInput = require('./hex-as-decimal-input')
|
|
|
|
|
2016-07-07 07:48:02 +02:00
|
|
|
|
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
|
2017-02-27 22:53:43 +01:00
|
|
|
var state = this.state || {}
|
2017-02-28 01:06:28 +01:00
|
|
|
var txData = state.txMeta || props.txData
|
2016-06-24 21:48:52 +02:00
|
|
|
|
|
|
|
var txParams = txData.txParams || {}
|
2017-01-31 00:08:31 +01:00
|
|
|
var address = txParams.from || props.selectedAddress
|
2016-07-07 06:32:36 +02:00
|
|
|
var identity = props.identities[address] || { address: address }
|
2016-07-16 02:47:58 +02:00
|
|
|
var account = props.accounts[address]
|
|
|
|
var balance = account ? account.balance : '0x0'
|
2016-06-24 21:48:52 +02:00
|
|
|
|
2017-02-27 22:53:43 +01:00
|
|
|
const gas = state.gas || txParams.gas
|
|
|
|
const gasPrice = state.gasPrice || txData.gasPrice
|
|
|
|
|
2017-02-28 01:06:28 +01:00
|
|
|
var txFee = state.txFee || txData.txFee || ''
|
|
|
|
var maxCost = state.maxCost || txData.maxCost || ''
|
2016-07-07 08:35:59 +02:00
|
|
|
var dataLength = txParams.data ? (txParams.data.length - 2) / 2 : 0
|
2016-07-08 01:54:35 +02:00
|
|
|
var imageify = props.imageifyIdenticons === undefined ? true : props.imageifyIdenticons
|
|
|
|
|
2017-02-28 01:06:28 +01:00
|
|
|
log.debug(`rendering gas: ${gas}, gasPrice: ${gasPrice}, txFee: ${txFee}, maxCost: ${maxCost}`)
|
|
|
|
|
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',
|
2016-07-07 20:50:01 +02:00
|
|
|
}, [
|
|
|
|
h('span.font-small', {
|
|
|
|
style: {
|
2016-07-07 21:27:34 +02:00
|
|
|
fontFamily: 'Montserrat Bold, Montserrat, sans-serif',
|
2016-07-07 20:50:01 +02:00
|
|
|
},
|
|
|
|
}, 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 20:50:01 +02:00
|
|
|
|
|
|
|
]),
|
2016-07-07 02:58:46 +02:00
|
|
|
|
2016-09-13 19:18:57 +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 {
|
2016-07-07 21:27:34 +02:00
|
|
|
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;
|
2016-07-07 21:27:34 +02:00
|
|
|
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',
|
2016-07-07 21:27:34 +02:00
|
|
|
background: 'white',
|
|
|
|
padding: '10px 25px',
|
2016-07-07 06:32:36 +02:00
|
|
|
},
|
|
|
|
}, [
|
|
|
|
h('.cell.label', 'Max Total'),
|
2016-07-07 21:27:34 +02:00
|
|
|
h('.cell.value', {
|
|
|
|
style: {
|
|
|
|
display: 'flex',
|
|
|
|
alignItems: 'center',
|
|
|
|
},
|
|
|
|
}, [
|
2016-09-07 02:28:25 +02:00
|
|
|
h(EthBalance, {
|
2016-07-14 08:39:44 +02:00
|
|
|
value: maxCost.toString(16),
|
2016-07-07 21:27:34 +02:00
|
|
|
inline: true,
|
|
|
|
labelColor: 'black',
|
|
|
|
fontSize: '16px',
|
|
|
|
}),
|
|
|
|
]),
|
2016-06-24 21:48:52 +02:00
|
|
|
]),
|
2017-02-27 22:53:43 +01:00
|
|
|
h('.cell.row', {
|
2016-07-07 06:32:36 +02:00
|
|
|
|
2017-02-27 22:53:43 +01:00
|
|
|
}, [
|
2017-02-28 01:33:58 +01:00
|
|
|
h('.cell.label', 'Gas Limit'),
|
2017-02-27 22:53:43 +01:00
|
|
|
h('.cell.value', {
|
|
|
|
|
|
|
|
}, [
|
|
|
|
h(HexInput, {
|
|
|
|
value: gas,
|
2017-02-28 01:33:58 +01:00
|
|
|
suffix: 'UNITS',
|
|
|
|
style: {
|
|
|
|
position: 'relative',
|
|
|
|
top: '5px',
|
|
|
|
},
|
2017-02-27 22:53:43 +01:00
|
|
|
onChange: (newHex) => {
|
2017-02-28 01:06:28 +01:00
|
|
|
log.info(`Gas limit changed to ${newHex}`)
|
2017-02-27 22:53:43 +01:00
|
|
|
this.setState({ gas: newHex })
|
|
|
|
},
|
|
|
|
}),
|
2017-02-28 01:09:05 +01:00
|
|
|
]),
|
2017-02-27 22:53:43 +01:00
|
|
|
]),
|
|
|
|
h('.cell.row', {
|
|
|
|
|
|
|
|
}, [
|
|
|
|
h('.cell.label', 'Gas Price'),
|
|
|
|
h('.cell.value', {
|
|
|
|
}, [
|
|
|
|
h(HexInput, {
|
|
|
|
value: gasPrice,
|
2017-02-28 01:33:58 +01:00
|
|
|
suffix: 'WEI',
|
|
|
|
style: {
|
|
|
|
position: 'relative',
|
|
|
|
top: '5px',
|
|
|
|
},
|
2017-02-27 22:53:43 +01:00
|
|
|
onChange: (newHex) => {
|
2017-02-28 01:06:28 +01:00
|
|
|
log.info(`Gas price changed to: ${newHex}`)
|
2017-02-28 01:33:58 +01:00
|
|
|
this.setState({ gasPrice: newHex })
|
2017-02-27 22:53:43 +01:00
|
|
|
},
|
|
|
|
}),
|
2017-02-28 01:09:05 +01:00
|
|
|
]),
|
2017-02-27 22:53:43 +01: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 21:27:34 +02:00
|
|
|
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
|
|
|
|
|
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',
|
2016-07-07 20:50:01 +02:00
|
|
|
}, [
|
|
|
|
h('span.font-small', {
|
|
|
|
style: {
|
2016-07-07 21:27:34 +02:00
|
|
|
fontFamily: 'Montserrat Bold, Montserrat, sans-serif',
|
2016-07-07 20:50:01 +02:00
|
|
|
},
|
2016-07-07 22:21:45 +02:00
|
|
|
}, nameForAddress(txParams.to, props.identities)),
|
2016-07-07 20:50:01 +02:00
|
|
|
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',
|
2016-07-07 20:50:01 +02:00
|
|
|
}, [
|
|
|
|
|
|
|
|
h('span.font-small', {
|
|
|
|
style: {
|
2016-07-07 21:27:34 +02:00
|
|
|
fontFamily: 'Montserrat Bold, Montserrat, sans-serif',
|
2016-07-07 20:50:01 +02:00
|
|
|
},
|
|
|
|
}, '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
|
|
|
|
2017-02-28 01:06:28 +01:00
|
|
|
PTXP.componentDidUpdate = function (prevProps, prevState) {
|
|
|
|
const state = this.state || {}
|
|
|
|
log.debug(`pending-tx-details componentDidUpdate`)
|
|
|
|
console.log(arguments)
|
|
|
|
|
|
|
|
// Only if gas or gasPrice changed:
|
|
|
|
if (prevState &&
|
|
|
|
(state.gas !== prevState.gas ||
|
2017-02-28 03:18:39 +01:00
|
|
|
state.gasPrice !== prevState.gasPrice)) {
|
2017-02-28 01:06:28 +01:00
|
|
|
log.debug(`recalculating gas since prev state change: ${JSON.stringify({ prevState, state })}`)
|
2017-02-28 03:18:39 +01:00
|
|
|
this.calculateGas()
|
2017-02-28 03:33:33 +01:00
|
|
|
|
|
|
|
// Otherwise this was a recalculation,
|
|
|
|
// so we should inform the parent:
|
|
|
|
} else {
|
|
|
|
if (this.props.onTxChange) {
|
|
|
|
this.props.onTxChange(this.gatherParams)
|
|
|
|
}
|
2017-02-28 01:06:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PTXP.gatherParams = function () {
|
|
|
|
log.debug(`pending-tx-details#gatherParams`)
|
|
|
|
const props = this.props
|
|
|
|
const state = this.state || {}
|
|
|
|
const txData = state.txData || props.txData
|
|
|
|
const txParams = txData.txParams
|
|
|
|
|
|
|
|
const gas = state.gas || txParams.gas
|
|
|
|
const gasPrice = state.gasPrice || txParams.gasPrice
|
|
|
|
const resultTx = extend(txParams, {
|
|
|
|
gas,
|
|
|
|
gasPrice,
|
|
|
|
})
|
|
|
|
const resultTxMeta = extend(txData, {
|
|
|
|
txParams: resultTx,
|
|
|
|
})
|
|
|
|
log.debug(`gathered params: ${JSON.stringify(resultTxMeta)}`)
|
|
|
|
return resultTxMeta
|
|
|
|
}
|
|
|
|
|
|
|
|
PTXP.calculateGas = function () {
|
|
|
|
const txMeta = this.gatherParams()
|
2017-02-28 01:09:05 +01:00
|
|
|
log.debug(`pending-tx-details calculating gas for ${JSON.stringify(txMeta)}`)
|
2017-02-28 03:18:39 +01:00
|
|
|
|
|
|
|
var txParams = txMeta.txParams
|
|
|
|
var gasMultiplier = txMeta.gasMultiplier
|
|
|
|
var gasCost = new BN(ethUtil.stripHexPrefix(txParams.gas || txMeta.estimatedGas), 16)
|
|
|
|
var gasPrice = new BN(ethUtil.stripHexPrefix(txParams.gasPrice || '0x4a817c800'), 16)
|
|
|
|
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)
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
txFee: '0x' + txFee.toString('hex'),
|
|
|
|
maxCost: '0x' + maxCost.toString('hex'),
|
2017-02-28 01:06:28 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-09-13 19:18:57 +02:00
|
|
|
function forwardCarrat () {
|
|
|
|
return (
|
2016-07-08 01:54:35 +02:00
|
|
|
|
2016-09-13 19:18:57 +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-09-13 19:18:57 +02:00
|
|
|
)
|
2016-07-12 00:49:13 +02:00
|
|
|
}
|