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-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-03-01 23:37:51 +01:00
|
|
|
const gas = (state.gas === undefined) ? txParams.gas : state.gas
|
|
|
|
const gasPrice = (state.gasPrice === undefined) ? txData.gasPrice : state.gasPrice
|
2017-02-27 22:53:43 +01:00
|
|
|
|
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', [
|
|
|
|
|
2017-02-28 03:36:43 +01:00
|
|
|
// Ether Value
|
|
|
|
// Currently not customizable, but easily modified
|
|
|
|
// in the way that gas and gasLimit currently are.
|
2016-07-07 06:32:36 +02:00
|
|
|
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
|
|
|
]),
|
|
|
|
|
2017-02-28 03:36:43 +01:00
|
|
|
// Gas Limit (customizable)
|
2017-02-28 23:19:32 +01:00
|
|
|
h('.cell.row', [
|
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-03-01 23:37:51 +01:00
|
|
|
this.setState({ gas: newHex })
|
2017-02-27 22:53:43 +01:00
|
|
|
},
|
|
|
|
}),
|
2017-02-28 01:09:05 +01:00
|
|
|
]),
|
2017-02-28 23:19:32 +01:00
|
|
|
]),
|
2017-02-27 22:53:43 +01:00
|
|
|
|
2017-02-28 03:36:43 +01:00
|
|
|
// Gas Price (customizable)
|
2017-02-28 23:19:32 +01:00
|
|
|
h('.cell.row', [
|
2017-02-27 22:53:43 +01:00
|
|
|
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-03-01 23:37:51 +01:00
|
|
|
this.setState({ gasPrice: newHex })
|
2017-02-27 22:53:43 +01:00
|
|
|
},
|
|
|
|
}),
|
2017-02-28 01:09:05 +01:00
|
|
|
]),
|
2017-02-28 23:19:32 +01:00
|
|
|
]),
|
2017-02-28 03:36:43 +01:00
|
|
|
|
|
|
|
// Max Transaction Fee (calculated)
|
|
|
|
h('.cell.row', [
|
|
|
|
h('.cell.label', 'Max Transaction Fee'),
|
|
|
|
h(EthBalance, { value: txFee.toString(16) }),
|
|
|
|
]),
|
|
|
|
|
|
|
|
h('.cell.row', {
|
|
|
|
style: {
|
|
|
|
fontFamily: 'Montserrat Regular',
|
|
|
|
background: 'white',
|
|
|
|
padding: '10px 25px',
|
|
|
|
},
|
|
|
|
}, [
|
|
|
|
h('.cell.label', 'Max Total'),
|
|
|
|
h('.cell.value', {
|
|
|
|
style: {
|
|
|
|
display: 'flex',
|
|
|
|
alignItems: 'center',
|
|
|
|
},
|
|
|
|
}, [
|
|
|
|
h(EthBalance, {
|
|
|
|
value: maxCost.toString(16),
|
|
|
|
inline: true,
|
|
|
|
labelColor: 'black',
|
|
|
|
fontSize: '16px',
|
|
|
|
}),
|
|
|
|
]),
|
|
|
|
]),
|
|
|
|
|
|
|
|
// Data size row:
|
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 20:35:04 +01:00
|
|
|
PTXP.componentDidUpdate = function (prevProps, previousState) {
|
2017-02-28 23:08:00 +01:00
|
|
|
log.debug(`pending-tx-details componentDidUpdate`)
|
2017-02-28 01:06:28 +01:00
|
|
|
const state = this.state || {}
|
2017-02-28 20:35:04 +01:00
|
|
|
const prevState = previousState || {}
|
|
|
|
const { gas, gasPrice } = state
|
|
|
|
|
2017-02-28 01:06:28 +01:00
|
|
|
// Only if gas or gasPrice changed:
|
2017-02-28 20:35:04 +01:00
|
|
|
if (!prevState ||
|
|
|
|
(gas !== prevState.gas ||
|
|
|
|
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 20:35:04 +01:00
|
|
|
}
|
|
|
|
}
|
2017-02-28 03:33:33 +01:00
|
|
|
|
2017-02-28 20:35:04 +01:00
|
|
|
PTXP.calculateGas = function () {
|
|
|
|
const txMeta = this.gatherParams()
|
|
|
|
log.debug(`pending-tx-details calculating gas for ${JSON.stringify(txMeta)}`)
|
|
|
|
|
|
|
|
var txParams = txMeta.txParams
|
|
|
|
var gasCost = new BN(ethUtil.stripHexPrefix(txParams.gas || txMeta.estimatedGas), 16)
|
|
|
|
var gasPrice = new BN(ethUtil.stripHexPrefix(txParams.gasPrice || '0x4a817c800'), 16)
|
|
|
|
var txFee = gasCost.mul(gasPrice)
|
|
|
|
var txValue = new BN(ethUtil.stripHexPrefix(txParams.value || '0x0'), 16)
|
|
|
|
var maxCost = txValue.add(txFee)
|
|
|
|
|
|
|
|
const txFeeHex = '0x' + txFee.toString('hex')
|
|
|
|
const maxCostHex = '0x' + maxCost.toString('hex')
|
|
|
|
const gasPriceHex = '0x' + gasPrice.toString('hex')
|
|
|
|
|
|
|
|
txMeta.txFee = txFeeHex
|
|
|
|
txMeta.maxCost = maxCostHex
|
|
|
|
txMeta.txParams.gasPrice = gasPriceHex
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
txFee: '0x' + txFee.toString('hex'),
|
|
|
|
maxCost: '0x' + maxCost.toString('hex'),
|
|
|
|
})
|
|
|
|
|
|
|
|
if (this.props.onTxChange) {
|
|
|
|
this.props.onTxChange(txMeta)
|
2017-02-28 01:06:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-01 01:36:05 +01:00
|
|
|
PTXP.resetGasFields = function () {
|
|
|
|
log.debug(`pending-tx-details#resetGasFields`)
|
|
|
|
const txData = this.props.txData
|
|
|
|
this.setState({
|
|
|
|
gas: txData.txParams.gas,
|
|
|
|
gasPrice: txData.gasPrice,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-02-28 20:35:04 +01:00
|
|
|
// After a customizable state value has been updated,
|
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,
|
|
|
|
})
|
2017-03-01 00:41:17 +01:00
|
|
|
log.debug(`UI has computed tx params ${JSON.stringify(resultTx)}`)
|
2017-02-28 01:06:28 +01:00
|
|
|
return resultTxMeta
|
|
|
|
}
|
|
|
|
|
2017-03-02 02:03:55 +01:00
|
|
|
PTXP.verifyGasParams = function () {
|
|
|
|
// We call this in case the gas has not been modified at all
|
|
|
|
if (!this.state) { return true }
|
|
|
|
return this._notZeroOrEmptyString(this.state.gas) && this._notZeroOrEmptyString(this.state.gasPrice)
|
|
|
|
}
|
|
|
|
|
|
|
|
PTXP._notZeroOrEmptyString = function (obj) {
|
|
|
|
return obj !== '' && obj !== '0x0'
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|