2016-05-03 23:32:22 +02:00
|
|
|
const Component = require('react').Component
|
2017-11-29 05:24:35 +01:00
|
|
|
const { withRouter } = require('react-router-dom')
|
|
|
|
const { compose } = require('recompose')
|
2018-03-29 17:00:44 +02:00
|
|
|
const PropTypes = require('prop-types')
|
|
|
|
const connect = require('react-redux').connect
|
2016-05-03 23:32:22 +02:00
|
|
|
const h = require('react-hyperscript')
|
|
|
|
const inherits = require('util').inherits
|
2017-09-22 07:25:16 +02:00
|
|
|
const actions = require('../../actions')
|
2017-05-17 23:18:01 +02:00
|
|
|
const clone = require('clone')
|
2017-03-23 21:44:09 +01:00
|
|
|
const ethUtil = require('ethereumjs-util')
|
|
|
|
const BN = ethUtil.BN
|
2017-09-22 07:25:16 +02:00
|
|
|
const hexToBn = require('../../../../app/scripts/lib/hex-to-bn')
|
2018-03-28 03:08:04 +02:00
|
|
|
const classnames = require('classnames')
|
2018-03-13 06:01:35 +01:00
|
|
|
const {
|
|
|
|
conversionUtil,
|
|
|
|
addCurrencies,
|
2018-03-14 00:39:04 +01:00
|
|
|
multiplyCurrencies,
|
2018-03-13 06:01:35 +01:00
|
|
|
} = require('../../conversion-util')
|
2018-03-28 03:08:04 +02:00
|
|
|
const {
|
2018-05-05 17:11:53 +02:00
|
|
|
calcGasTotal,
|
2018-03-28 03:08:04 +02:00
|
|
|
isBalanceSufficient,
|
2018-05-05 17:11:53 +02:00
|
|
|
} = require('../send_/send.utils')
|
2018-03-09 06:33:36 +01:00
|
|
|
const GasFeeDisplay = require('../send/gas-fee-display-v2')
|
2018-03-20 00:12:09 +01:00
|
|
|
const SenderToRecipient = require('../sender-to-recipient')
|
|
|
|
const NetworkDisplay = require('../network-display')
|
2018-04-09 21:15:23 +02:00
|
|
|
const currencyFormatter = require('currency-formatter')
|
|
|
|
const currencies = require('currency-formatter/currencies')
|
2017-03-23 21:44:09 +01:00
|
|
|
|
2018-05-05 17:11:53 +02:00
|
|
|
const { MIN_GAS_PRICE_HEX } = require('../send_/send.constants')
|
2017-11-29 05:24:35 +01:00
|
|
|
const { SEND_ROUTE, DEFAULT_ROUTE } = require('../../routes')
|
2018-05-14 23:34:10 +02:00
|
|
|
const {
|
|
|
|
ENVIRONMENT_TYPE_POPUP,
|
|
|
|
ENVIRONMENT_TYPE_NOTIFICATION,
|
|
|
|
} = require('../../../../app/scripts/lib/enums')
|
2017-03-23 21:44:09 +01:00
|
|
|
|
2018-04-27 21:03:00 +02:00
|
|
|
import {
|
|
|
|
updateSendErrors,
|
2018-05-14 14:19:09 +02:00
|
|
|
} from '../../ducks/send.duck'
|
2018-04-27 21:03:00 +02:00
|
|
|
|
2018-03-29 17:00:44 +02:00
|
|
|
ConfirmSendEther.contextTypes = {
|
|
|
|
t: PropTypes.func,
|
|
|
|
}
|
|
|
|
|
2017-11-29 05:24:35 +01:00
|
|
|
module.exports = compose(
|
|
|
|
withRouter,
|
|
|
|
connect(mapStateToProps, mapDispatchToProps)
|
|
|
|
)(ConfirmSendEther)
|
2017-09-12 07:19:05 +02:00
|
|
|
|
2018-03-29 17:00:44 +02:00
|
|
|
|
2017-09-12 07:19:05 +02:00
|
|
|
function mapStateToProps (state) {
|
|
|
|
const {
|
|
|
|
conversionRate,
|
|
|
|
identities,
|
2017-10-19 04:09:26 +02:00
|
|
|
currentCurrency,
|
2017-11-08 17:44:48 +01:00
|
|
|
send,
|
2017-09-12 07:19:05 +02:00
|
|
|
} = state.metamask
|
2017-09-13 08:02:51 +02:00
|
|
|
const accounts = state.metamask.accounts
|
|
|
|
const selectedAddress = state.metamask.selectedAddress || Object.keys(accounts)[0]
|
2018-03-28 03:08:04 +02:00
|
|
|
const { balance } = accounts[selectedAddress]
|
2017-09-12 07:19:05 +02:00
|
|
|
return {
|
|
|
|
conversionRate,
|
|
|
|
identities,
|
2017-09-13 08:02:51 +02:00
|
|
|
selectedAddress,
|
2017-10-19 04:09:26 +02:00
|
|
|
currentCurrency,
|
2017-11-08 17:44:48 +01:00
|
|
|
send,
|
2018-03-28 03:08:04 +02:00
|
|
|
balance,
|
2017-09-12 07:19:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function mapDispatchToProps (dispatch) {
|
|
|
|
return {
|
2017-11-08 17:44:48 +01:00
|
|
|
clearSend: () => dispatch(actions.clearSend()),
|
|
|
|
editTransaction: txMeta => {
|
2018-03-13 06:01:35 +01:00
|
|
|
const { id, txParams } = txMeta
|
2017-11-08 17:44:48 +01:00
|
|
|
const {
|
|
|
|
gas: gasLimit,
|
|
|
|
gasPrice,
|
|
|
|
to,
|
2017-11-08 20:18:27 +01:00
|
|
|
value: amount,
|
2017-11-08 17:44:48 +01:00
|
|
|
} = txParams
|
2018-03-09 04:49:26 +01:00
|
|
|
|
2017-11-10 04:49:16 +01:00
|
|
|
dispatch(actions.updateSend({
|
|
|
|
gasLimit,
|
|
|
|
gasPrice,
|
|
|
|
gasTotal: null,
|
|
|
|
to,
|
|
|
|
amount,
|
|
|
|
errors: { to: null, amount: null },
|
|
|
|
editingTransactionId: id,
|
|
|
|
}))
|
2017-11-08 17:44:48 +01:00
|
|
|
},
|
2017-09-14 04:57:33 +02:00
|
|
|
cancelTransaction: ({ id }) => dispatch(actions.cancelTx({ id })),
|
2018-03-09 06:33:36 +01:00
|
|
|
showCustomizeGasModal: (txMeta, sendGasLimit, sendGasPrice, sendGasTotal) => {
|
2018-03-13 06:01:35 +01:00
|
|
|
const { id, txParams, lastGasPrice } = txMeta
|
2018-03-09 06:33:36 +01:00
|
|
|
const { gas: txGasLimit, gasPrice: txGasPrice } = txParams
|
|
|
|
|
2018-03-13 06:01:35 +01:00
|
|
|
let forceGasMin
|
|
|
|
if (lastGasPrice) {
|
2018-03-14 22:20:18 +01:00
|
|
|
forceGasMin = ethUtil.addHexPrefix(multiplyCurrencies(lastGasPrice, 1.1, {
|
2018-03-13 06:01:35 +01:00
|
|
|
multiplicandBase: 16,
|
|
|
|
multiplierBase: 10,
|
|
|
|
toNumericBase: 'hex',
|
|
|
|
fromDenomination: 'WEI',
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
2018-03-09 06:33:36 +01:00
|
|
|
dispatch(actions.updateSend({
|
|
|
|
gasLimit: sendGasLimit || txGasLimit,
|
|
|
|
gasPrice: sendGasPrice || txGasPrice,
|
|
|
|
editingTransactionId: id,
|
|
|
|
gasTotal: sendGasTotal,
|
2018-03-13 06:01:35 +01:00
|
|
|
forceGasMin,
|
2018-03-09 06:33:36 +01:00
|
|
|
}))
|
|
|
|
dispatch(actions.showModal({ name: 'CUSTOMIZE_GAS' }))
|
|
|
|
},
|
2018-04-27 21:03:00 +02:00
|
|
|
updateSendErrors: error => dispatch(updateSendErrors(error)),
|
2017-09-12 07:19:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-22 07:25:16 +02:00
|
|
|
inherits(ConfirmSendEther, Component)
|
|
|
|
function ConfirmSendEther () {
|
2017-07-30 07:44:39 +02:00
|
|
|
Component.call(this)
|
2017-09-22 07:25:16 +02:00
|
|
|
this.state = {}
|
2017-09-13 08:02:51 +02:00
|
|
|
this.onSubmit = this.onSubmit.bind(this)
|
2017-07-30 07:44:39 +02:00
|
|
|
}
|
2017-07-30 07:18:26 +02:00
|
|
|
|
2018-04-02 20:56:19 +02:00
|
|
|
ConfirmSendEther.prototype.updateComponentSendErrors = function (prevProps) {
|
|
|
|
const {
|
|
|
|
balance: oldBalance,
|
|
|
|
conversionRate: oldConversionRate,
|
|
|
|
} = prevProps
|
|
|
|
const {
|
|
|
|
updateSendErrors,
|
|
|
|
balance,
|
|
|
|
conversionRate,
|
2018-04-02 20:59:35 +02:00
|
|
|
send: {
|
|
|
|
errors: {
|
|
|
|
simulationFails,
|
|
|
|
},
|
|
|
|
},
|
2018-04-02 20:56:19 +02:00
|
|
|
} = this.props
|
2018-03-29 20:00:03 +02:00
|
|
|
const txMeta = this.gatherTxMeta()
|
|
|
|
|
2018-04-02 20:56:19 +02:00
|
|
|
const shouldUpdateBalanceSendErrors = balance && [
|
|
|
|
balance !== oldBalance,
|
|
|
|
conversionRate !== oldConversionRate,
|
|
|
|
].some(x => Boolean(x))
|
|
|
|
|
|
|
|
if (shouldUpdateBalanceSendErrors) {
|
|
|
|
const balanceIsSufficient = this.isBalanceSufficient(txMeta)
|
|
|
|
updateSendErrors({
|
2018-04-27 12:41:18 +02:00
|
|
|
insufficientFunds: balanceIsSufficient ? false : 'insufficientFunds',
|
2018-04-02 20:56:19 +02:00
|
|
|
})
|
|
|
|
}
|
2018-04-02 20:59:35 +02:00
|
|
|
|
|
|
|
const shouldUpdateSimulationSendError = Boolean(txMeta.simulationFails) !== Boolean(simulationFails)
|
|
|
|
|
|
|
|
if (shouldUpdateSimulationSendError) {
|
|
|
|
updateSendErrors({
|
2018-04-27 12:41:18 +02:00
|
|
|
simulationFails: !txMeta.simulationFails ? false : 'transactionError',
|
2018-04-02 20:59:35 +02:00
|
|
|
})
|
|
|
|
}
|
2018-04-02 20:56:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ConfirmSendEther.prototype.componentWillMount = function () {
|
|
|
|
this.updateComponentSendErrors({})
|
|
|
|
}
|
|
|
|
|
|
|
|
ConfirmSendEther.prototype.componentDidUpdate = function (prevProps) {
|
|
|
|
this.updateComponentSendErrors(prevProps)
|
2018-03-29 20:00:03 +02:00
|
|
|
}
|
|
|
|
|
2017-09-22 07:25:16 +02:00
|
|
|
ConfirmSendEther.prototype.getAmount = function () {
|
2017-10-19 04:09:26 +02:00
|
|
|
const { conversionRate, currentCurrency } = this.props
|
2017-03-28 20:46:33 +02:00
|
|
|
const txMeta = this.gatherTxMeta()
|
|
|
|
const txParams = txMeta.txParams || {}
|
2017-10-22 22:14:03 +02:00
|
|
|
|
2017-10-19 04:09:26 +02:00
|
|
|
const FIAT = conversionUtil(txParams.value, {
|
2017-09-22 07:25:16 +02:00
|
|
|
fromNumericBase: 'hex',
|
|
|
|
toNumericBase: 'dec',
|
|
|
|
fromCurrency: 'ETH',
|
2017-10-19 04:09:26 +02:00
|
|
|
toCurrency: currentCurrency,
|
2017-09-22 07:25:16 +02:00
|
|
|
numberOfDecimals: 2,
|
|
|
|
fromDenomination: 'WEI',
|
|
|
|
conversionRate,
|
|
|
|
})
|
|
|
|
const ETH = conversionUtil(txParams.value, {
|
|
|
|
fromNumericBase: 'hex',
|
|
|
|
toNumericBase: 'dec',
|
|
|
|
fromCurrency: 'ETH',
|
|
|
|
toCurrency: 'ETH',
|
|
|
|
fromDenomination: 'WEI',
|
|
|
|
conversionRate,
|
|
|
|
numberOfDecimals: 6,
|
|
|
|
})
|
|
|
|
|
|
|
|
return {
|
2017-10-19 04:09:26 +02:00
|
|
|
FIAT,
|
2017-09-22 07:25:16 +02:00
|
|
|
ETH,
|
2017-09-13 08:02:51 +02:00
|
|
|
}
|
2017-09-14 04:57:33 +02:00
|
|
|
|
2017-09-13 08:02:51 +02:00
|
|
|
}
|
2017-03-23 21:44:09 +01:00
|
|
|
|
2017-09-22 07:25:16 +02:00
|
|
|
ConfirmSendEther.prototype.getGasFee = function () {
|
2017-10-19 04:09:26 +02:00
|
|
|
const { conversionRate, currentCurrency } = this.props
|
2017-09-13 08:02:51 +02:00
|
|
|
const txMeta = this.gatherTxMeta()
|
|
|
|
const txParams = txMeta.txParams || {}
|
2017-06-05 20:40:20 +02:00
|
|
|
|
2017-05-08 01:51:57 +02:00
|
|
|
// Gas
|
2017-03-28 20:46:33 +02:00
|
|
|
const gas = txParams.gas
|
|
|
|
const gasBn = hexToBn(gas)
|
2017-09-22 07:25:16 +02:00
|
|
|
|
2017-09-18 20:41:46 +02:00
|
|
|
// From latest master
|
|
|
|
// const gasLimit = new BN(parseInt(blockGasLimit))
|
|
|
|
// const safeGasLimitBN = this.bnMultiplyByFraction(gasLimit, 19, 20)
|
|
|
|
// const saferGasLimitBN = this.bnMultiplyByFraction(gasLimit, 18, 20)
|
|
|
|
// const safeGasLimit = safeGasLimitBN.toString(10)
|
2017-05-08 01:51:57 +02:00
|
|
|
|
|
|
|
// Gas Price
|
2017-10-26 18:06:34 +02:00
|
|
|
const gasPrice = txParams.gasPrice || MIN_GAS_PRICE_HEX
|
2017-03-28 20:46:33 +02:00
|
|
|
const gasPriceBn = hexToBn(gasPrice)
|
2017-03-23 21:44:09 +01:00
|
|
|
|
2017-03-24 00:36:33 +01:00
|
|
|
const txFeeBn = gasBn.mul(gasPriceBn)
|
2017-03-24 01:00:59 +01:00
|
|
|
|
2017-10-19 04:09:26 +02:00
|
|
|
const FIAT = conversionUtil(txFeeBn, {
|
2017-09-12 22:38:02 +02:00
|
|
|
fromNumericBase: 'BN',
|
|
|
|
toNumericBase: 'dec',
|
|
|
|
fromDenomination: 'WEI',
|
|
|
|
fromCurrency: 'ETH',
|
2017-10-19 04:09:26 +02:00
|
|
|
toCurrency: currentCurrency,
|
2017-09-12 22:38:02 +02:00
|
|
|
numberOfDecimals: 2,
|
2017-09-12 07:19:05 +02:00
|
|
|
conversionRate,
|
|
|
|
})
|
2017-09-13 08:02:51 +02:00
|
|
|
const ETH = conversionUtil(txFeeBn, {
|
2017-09-12 22:38:02 +02:00
|
|
|
fromNumericBase: 'BN',
|
|
|
|
toNumericBase: 'dec',
|
|
|
|
fromDenomination: 'WEI',
|
|
|
|
fromCurrency: 'ETH',
|
2017-09-12 07:19:05 +02:00
|
|
|
toCurrency: 'ETH',
|
2017-09-12 22:38:02 +02:00
|
|
|
numberOfDecimals: 6,
|
2017-09-12 07:19:05 +02:00
|
|
|
conversionRate,
|
|
|
|
})
|
|
|
|
|
2017-09-13 08:02:51 +02:00
|
|
|
return {
|
2017-10-19 04:09:26 +02:00
|
|
|
FIAT,
|
2017-09-13 08:02:51 +02:00
|
|
|
ETH,
|
2018-03-09 06:33:36 +01:00
|
|
|
gasFeeInHex: txFeeBn.toString(16),
|
2017-09-13 08:02:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-22 07:25:16 +02:00
|
|
|
ConfirmSendEther.prototype.getData = function () {
|
2017-09-13 08:02:51 +02:00
|
|
|
const { identities } = this.props
|
|
|
|
const txMeta = this.gatherTxMeta()
|
|
|
|
const txParams = txMeta.txParams || {}
|
2018-04-04 22:56:39 +02:00
|
|
|
const account = identities ? identities[txParams.from] || {} : {}
|
2018-03-09 06:33:36 +01:00
|
|
|
const { FIAT: gasFeeInFIAT, ETH: gasFeeInETH, gasFeeInHex } = this.getGasFee()
|
2017-10-19 04:09:26 +02:00
|
|
|
const { FIAT: amountInFIAT, ETH: amountInETH } = this.getAmount()
|
2017-09-20 15:56:20 +02:00
|
|
|
|
2017-10-19 04:09:26 +02:00
|
|
|
const totalInFIAT = addCurrencies(gasFeeInFIAT, amountInFIAT, {
|
2017-09-20 15:56:20 +02:00
|
|
|
toNumericBase: 'dec',
|
|
|
|
numberOfDecimals: 2,
|
|
|
|
})
|
|
|
|
const totalInETH = addCurrencies(gasFeeInETH, amountInETH, {
|
|
|
|
toNumericBase: 'dec',
|
|
|
|
numberOfDecimals: 6,
|
|
|
|
})
|
2017-09-13 08:02:51 +02:00
|
|
|
|
2017-09-22 07:25:16 +02:00
|
|
|
return {
|
|
|
|
from: {
|
|
|
|
address: txParams.from,
|
2018-04-04 22:56:39 +02:00
|
|
|
name: account.name,
|
2017-09-22 07:25:16 +02:00
|
|
|
},
|
|
|
|
to: {
|
|
|
|
address: txParams.to,
|
2018-03-29 17:00:44 +02:00
|
|
|
name: identities[txParams.to] ? identities[txParams.to].name : this.context.t('newRecipient'),
|
2017-09-22 07:25:16 +02:00
|
|
|
},
|
|
|
|
memo: txParams.memo || '',
|
2017-10-19 04:09:26 +02:00
|
|
|
gasFeeInFIAT,
|
2017-09-22 07:25:16 +02:00
|
|
|
gasFeeInETH,
|
2017-10-19 04:09:26 +02:00
|
|
|
amountInFIAT,
|
2017-09-22 07:25:16 +02:00
|
|
|
amountInETH,
|
2017-10-19 04:09:26 +02:00
|
|
|
totalInFIAT,
|
2017-09-22 07:25:16 +02:00
|
|
|
totalInETH,
|
2018-03-09 06:33:36 +01:00
|
|
|
gasFeeInHex,
|
2017-09-13 08:02:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-09 21:15:23 +02:00
|
|
|
ConfirmSendEther.prototype.convertToRenderableCurrency = function (value, currencyCode) {
|
|
|
|
const upperCaseCurrencyCode = currencyCode.toUpperCase()
|
|
|
|
|
|
|
|
return currencies.find(currency => currency.code === upperCaseCurrencyCode)
|
|
|
|
? currencyFormatter.format(Number(value), {
|
|
|
|
code: upperCaseCurrencyCode,
|
|
|
|
})
|
|
|
|
: value
|
|
|
|
}
|
|
|
|
|
2018-05-29 19:23:06 +02:00
|
|
|
ConfirmSendEther.prototype.editTransaction = function () {
|
2017-11-29 05:24:35 +01:00
|
|
|
const { editTransaction, history } = this.props
|
2018-05-29 19:23:06 +02:00
|
|
|
const txMeta = this.gatherTxMeta()
|
2017-11-29 05:24:35 +01:00
|
|
|
editTransaction(txMeta)
|
|
|
|
history.push(SEND_ROUTE)
|
|
|
|
}
|
|
|
|
|
2018-05-29 19:23:06 +02:00
|
|
|
ConfirmSendEther.prototype.renderHeaderRow = function (isTxReprice) {
|
2018-05-14 23:34:10 +02:00
|
|
|
const windowType = window.METAMASK_UI_TYPE
|
2018-05-29 19:23:06 +02:00
|
|
|
const isFullScreen = windowType !== ENVIRONMENT_TYPE_NOTIFICATION &&
|
|
|
|
windowType !== ENVIRONMENT_TYPE_POPUP
|
|
|
|
|
|
|
|
if (isTxReprice && isFullScreen) {
|
|
|
|
return null
|
|
|
|
}
|
2018-05-14 23:34:10 +02:00
|
|
|
|
2018-05-29 19:23:06 +02:00
|
|
|
return (
|
|
|
|
h('.page-container__header-row', [
|
|
|
|
h('span.page-container__back-button', {
|
|
|
|
onClick: () => this.editTransaction(),
|
|
|
|
style: {
|
|
|
|
visibility: isTxReprice ? 'hidden' : 'initial',
|
|
|
|
},
|
|
|
|
}, 'Edit'),
|
|
|
|
!isFullScreen && h(NetworkDisplay),
|
|
|
|
])
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
ConfirmSendEther.prototype.renderHeader = function (isTxReprice) {
|
|
|
|
const title = isTxReprice ? this.context.t('speedUpTitle') : this.context.t('confirm')
|
|
|
|
const subtitle = isTxReprice
|
|
|
|
? this.context.t('speedUpSubtitle')
|
|
|
|
: this.context.t('pleaseReviewTransaction')
|
|
|
|
|
|
|
|
return (
|
|
|
|
h('.page-container__header', [
|
|
|
|
this.renderHeaderRow(isTxReprice),
|
|
|
|
h('.page-container__title', title),
|
|
|
|
h('.page-container__subtitle', subtitle),
|
|
|
|
])
|
|
|
|
)
|
2018-05-14 23:34:10 +02:00
|
|
|
}
|
|
|
|
|
2017-09-22 07:25:16 +02:00
|
|
|
ConfirmSendEther.prototype.render = function () {
|
2018-03-09 06:33:36 +01:00
|
|
|
const {
|
|
|
|
currentCurrency,
|
|
|
|
clearSend,
|
|
|
|
conversionRate,
|
|
|
|
currentCurrency: convertedCurrency,
|
|
|
|
showCustomizeGasModal,
|
2018-03-28 03:08:04 +02:00
|
|
|
send: {
|
|
|
|
gasTotal,
|
|
|
|
gasLimit: sendGasLimit,
|
|
|
|
gasPrice: sendGasPrice,
|
|
|
|
errors,
|
|
|
|
},
|
2018-03-09 06:33:36 +01:00
|
|
|
} = this.props
|
2017-09-13 08:02:51 +02:00
|
|
|
const txMeta = this.gatherTxMeta()
|
2018-05-29 19:23:06 +02:00
|
|
|
const isTxReprice = Boolean(txMeta.lastGasPrice)
|
2017-09-13 08:02:51 +02:00
|
|
|
const txParams = txMeta.txParams || {}
|
|
|
|
|
|
|
|
const {
|
|
|
|
from: {
|
|
|
|
address: fromAddress,
|
|
|
|
name: fromName,
|
|
|
|
},
|
|
|
|
to: {
|
|
|
|
address: toAddress,
|
|
|
|
name: toName,
|
|
|
|
},
|
|
|
|
memo,
|
2018-03-09 06:33:36 +01:00
|
|
|
gasFeeInHex,
|
2017-10-19 04:09:26 +02:00
|
|
|
amountInFIAT,
|
|
|
|
totalInFIAT,
|
2017-09-13 08:02:51 +02:00
|
|
|
totalInETH,
|
|
|
|
} = this.getData()
|
2017-03-28 20:46:33 +02:00
|
|
|
|
2018-04-09 21:15:23 +02:00
|
|
|
const convertedAmountInFiat = this.convertToRenderableCurrency(amountInFIAT, currentCurrency)
|
|
|
|
const convertedTotalInFiat = this.convertToRenderableCurrency(totalInFIAT, currentCurrency)
|
|
|
|
|
2017-09-18 20:28:10 +02:00
|
|
|
// This is from the latest master
|
|
|
|
// It handles some of the errors that we are not currently handling
|
|
|
|
// Leaving as comments fo reference
|
|
|
|
|
|
|
|
// const balanceBn = hexToBn(balance)
|
|
|
|
// const insufficientBalance = balanceBn.lt(maxCost)
|
|
|
|
// const buyDisabled = insufficientBalance || !this.state.valid || !isValidAddress || this.state.submitting
|
|
|
|
// const showRejectAll = props.unconfTxListLength > 1
|
2017-09-18 20:41:46 +02:00
|
|
|
// const dangerousGasLimit = gasBn.gte(saferGasLimitBN)
|
|
|
|
// const gasLimitSpecified = txMeta.gasLimitSpecified
|
2017-03-28 20:46:33 +02:00
|
|
|
|
2017-03-24 00:02:40 +01:00
|
|
|
this.inputs = []
|
2017-03-23 21:44:09 +01:00
|
|
|
|
2016-05-03 23:32:22 +02:00
|
|
|
return (
|
2018-03-20 00:12:09 +01:00
|
|
|
// Main Send token Card
|
|
|
|
h('.page-container', [
|
2018-05-29 19:23:06 +02:00
|
|
|
this.renderHeader(isTxReprice),
|
2018-03-20 00:12:09 +01:00
|
|
|
h('.page-container__content', [
|
|
|
|
h(SenderToRecipient, {
|
|
|
|
senderName: fromName,
|
|
|
|
senderAddress: fromAddress,
|
|
|
|
recipientName: toName,
|
|
|
|
recipientAddress: txParams.to,
|
|
|
|
}),
|
|
|
|
|
|
|
|
// h('h3.flex-center.confirm-screen-sending-to-message', {
|
|
|
|
// style: {
|
|
|
|
// textAlign: 'center',
|
|
|
|
// fontSize: '16px',
|
|
|
|
// },
|
|
|
|
// }, [
|
|
|
|
// `You're sending to Recipient ...${toAddress.slice(toAddress.length - 4)}`,
|
|
|
|
// ]),
|
|
|
|
|
2018-04-09 21:15:23 +02:00
|
|
|
h('h3.flex-center.confirm-screen-send-amount', [`${convertedAmountInFiat}`]),
|
2018-03-20 00:12:09 +01:00
|
|
|
h('h3.flex-center.confirm-screen-send-amount-currency', [ currentCurrency.toUpperCase() ]),
|
|
|
|
h('div.flex-center.confirm-memo-wrapper', [
|
|
|
|
h('h3.confirm-screen-send-memo', [ memo ? `"${memo}"` : '' ]),
|
2017-07-30 07:18:26 +02:00
|
|
|
]),
|
2017-07-30 05:55:55 +02:00
|
|
|
|
2018-03-20 00:12:09 +01:00
|
|
|
h('div.confirm-screen-rows', [
|
|
|
|
h('section.flex-row.flex-center.confirm-screen-row', [
|
2018-03-29 17:00:44 +02:00
|
|
|
h('span.confirm-screen-label.confirm-screen-section-column', [ this.context.t('from') ]),
|
2018-03-20 00:12:09 +01:00
|
|
|
h('div.confirm-screen-section-column', [
|
|
|
|
h('div.confirm-screen-row-info', fromName),
|
|
|
|
h('div.confirm-screen-row-detail', `...${fromAddress.slice(fromAddress.length - 4)}`),
|
|
|
|
]),
|
2017-07-30 07:44:39 +02:00
|
|
|
]),
|
|
|
|
|
2018-03-20 00:12:09 +01:00
|
|
|
h('section.flex-row.flex-center.confirm-screen-row', [
|
2018-03-29 17:00:44 +02:00
|
|
|
h('span.confirm-screen-label.confirm-screen-section-column', [ this.context.t('to') ]),
|
2018-03-20 00:12:09 +01:00
|
|
|
h('div.confirm-screen-section-column', [
|
|
|
|
h('div.confirm-screen-row-info', toName),
|
|
|
|
h('div.confirm-screen-row-detail', `...${toAddress.slice(toAddress.length - 4)}`),
|
2017-08-29 16:50:48 +02:00
|
|
|
]),
|
2018-03-20 00:12:09 +01:00
|
|
|
]),
|
2017-07-30 07:44:39 +02:00
|
|
|
|
2018-03-20 00:12:09 +01:00
|
|
|
h('section.flex-row.flex-center.confirm-screen-row', [
|
2018-03-29 17:00:44 +02:00
|
|
|
h('span.confirm-screen-label.confirm-screen-section-column', [ this.context.t('gasFee') ]),
|
2018-03-20 00:12:09 +01:00
|
|
|
h('div.confirm-screen-section-column', [
|
|
|
|
h(GasFeeDisplay, {
|
|
|
|
gasTotal: gasTotal || gasFeeInHex,
|
|
|
|
conversionRate,
|
|
|
|
convertedCurrency,
|
|
|
|
onClick: () => showCustomizeGasModal(txMeta, sendGasLimit, sendGasPrice, gasTotal),
|
|
|
|
}),
|
2017-08-29 16:50:48 +02:00
|
|
|
]),
|
2018-03-20 00:12:09 +01:00
|
|
|
]),
|
2017-07-30 07:44:39 +02:00
|
|
|
|
2018-03-20 00:12:09 +01:00
|
|
|
h('section.flex-row.flex-center.confirm-screen-row.confirm-screen-total-box ', [
|
2018-03-28 03:08:04 +02:00
|
|
|
h('div', {
|
|
|
|
className: classnames({
|
|
|
|
'confirm-screen-section-column--with-error': errors['insufficientFunds'],
|
|
|
|
'confirm-screen-section-column': !errors['insufficientFunds'],
|
2018-03-28 03:53:57 +02:00
|
|
|
}),
|
2018-03-28 03:08:04 +02:00
|
|
|
}, [
|
2018-03-29 17:00:44 +02:00
|
|
|
h('span.confirm-screen-label', [ this.context.t('total') + ' ' ]),
|
|
|
|
h('div.confirm-screen-total-box__subtitle', [ this.context.t('amountPlusGas') ]),
|
2017-07-30 07:44:39 +02:00
|
|
|
]),
|
|
|
|
|
2018-03-20 00:12:09 +01:00
|
|
|
h('div.confirm-screen-section-column', [
|
2018-04-09 21:15:23 +02:00
|
|
|
h('div.confirm-screen-row-info', `${convertedTotalInFiat} ${currentCurrency.toUpperCase()}`),
|
2018-03-20 00:12:09 +01:00
|
|
|
h('div.confirm-screen-row-detail', `${totalInETH} ETH`),
|
2017-08-29 16:50:48 +02:00
|
|
|
]),
|
2018-03-28 03:08:04 +02:00
|
|
|
|
|
|
|
this.renderErrorMessage('insufficientFunds'),
|
2017-09-18 20:28:10 +02:00
|
|
|
]),
|
2017-07-30 07:44:39 +02:00
|
|
|
]),
|
|
|
|
|
2018-03-20 00:12:09 +01:00
|
|
|
// These are latest errors handling from master
|
|
|
|
// Leaving as comments as reference when we start implementing error handling
|
|
|
|
// h('style', `
|
|
|
|
// .conf-buttons button {
|
|
|
|
// margin-left: 10px;
|
|
|
|
// text-transform: uppercase;
|
|
|
|
// }
|
|
|
|
// `),
|
|
|
|
|
|
|
|
// txMeta.simulationFails ?
|
|
|
|
// h('.error', {
|
|
|
|
// style: {
|
|
|
|
// marginLeft: 50,
|
|
|
|
// fontSize: '0.9em',
|
|
|
|
// },
|
|
|
|
// }, 'Transaction Error. Exception thrown in contract code.')
|
|
|
|
// : null,
|
|
|
|
|
|
|
|
// !isValidAddress ?
|
|
|
|
// h('.error', {
|
|
|
|
// style: {
|
|
|
|
// marginLeft: 50,
|
|
|
|
// fontSize: '0.9em',
|
|
|
|
// },
|
|
|
|
// }, 'Recipient address is invalid. Sending this transaction will result in a loss of ETH.')
|
|
|
|
// : null,
|
|
|
|
|
|
|
|
// insufficientBalance ?
|
|
|
|
// h('span.error', {
|
|
|
|
// style: {
|
|
|
|
// marginLeft: 50,
|
|
|
|
// fontSize: '0.9em',
|
|
|
|
// },
|
|
|
|
// }, 'Insufficient balance for transaction')
|
|
|
|
// : null,
|
|
|
|
|
|
|
|
// // send + cancel
|
|
|
|
// h('.flex-row.flex-space-around.conf-buttons', {
|
|
|
|
// style: {
|
|
|
|
// display: 'flex',
|
|
|
|
// justifyContent: 'flex-end',
|
|
|
|
// margin: '14px 25px',
|
|
|
|
// },
|
|
|
|
// }, [
|
|
|
|
// h('button', {
|
|
|
|
// onClick: (event) => {
|
|
|
|
// this.resetGasFields()
|
|
|
|
// event.preventDefault()
|
|
|
|
// },
|
|
|
|
// }, 'Reset'),
|
|
|
|
|
|
|
|
// // Accept Button or Buy Button
|
|
|
|
// insufficientBalance ? h('button.btn-green', { onClick: props.buyEth }, 'Buy Ether') :
|
|
|
|
// h('input.confirm.btn-green', {
|
|
|
|
// type: 'submit',
|
|
|
|
// value: 'SUBMIT',
|
|
|
|
// style: { marginLeft: '10px' },
|
|
|
|
// disabled: buyDisabled,
|
|
|
|
// }),
|
|
|
|
|
|
|
|
// h('button.cancel.btn-red', {
|
|
|
|
// onClick: props.cancelTransaction,
|
|
|
|
// }, 'Reject'),
|
|
|
|
// ]),
|
|
|
|
// showRejectAll ? h('.flex-row.flex-space-around.conf-buttons', {
|
|
|
|
// style: {
|
|
|
|
// display: 'flex',
|
|
|
|
// justifyContent: 'flex-end',
|
|
|
|
// margin: '14px 25px',
|
|
|
|
// },
|
|
|
|
// }, [
|
|
|
|
// h('button.cancel.btn-red', {
|
|
|
|
// onClick: props.cancelAllTransactions,
|
|
|
|
// }, 'Reject All'),
|
|
|
|
// ]) : null,
|
|
|
|
// ]),
|
|
|
|
// ])
|
|
|
|
// )
|
|
|
|
// }
|
|
|
|
]),
|
|
|
|
|
|
|
|
h('form#pending-tx-form', {
|
2018-04-02 20:59:35 +02:00
|
|
|
className: 'confirm-screen-form',
|
2018-03-20 00:12:09 +01:00
|
|
|
onSubmit: this.onSubmit,
|
|
|
|
}, [
|
2018-04-02 20:59:35 +02:00
|
|
|
this.renderErrorMessage('simulationFails'),
|
2018-03-20 00:12:09 +01:00
|
|
|
h('.page-container__footer', [
|
|
|
|
// Cancel Button
|
|
|
|
h('button.btn-cancel.page-container__footer-button.allcaps', {
|
|
|
|
onClick: (event) => {
|
|
|
|
clearSend()
|
|
|
|
this.cancel(event, txMeta)
|
|
|
|
},
|
2018-03-29 17:00:44 +02:00
|
|
|
}, this.context.t('cancel')),
|
2018-03-20 00:12:09 +01:00
|
|
|
|
|
|
|
// Accept Button
|
2018-04-06 11:04:39 +02:00
|
|
|
h('button.btn-confirm.page-container__footer-button.allcaps', {
|
|
|
|
onClick: event => this.onSubmit(event),
|
|
|
|
}, this.context.t('confirm')),
|
2018-03-17 00:39:00 +01:00
|
|
|
]),
|
2017-07-30 08:09:49 +02:00
|
|
|
]),
|
2017-09-13 08:02:51 +02:00
|
|
|
])
|
2017-07-30 07:18:26 +02:00
|
|
|
)
|
2017-05-11 02:26:09 +02:00
|
|
|
}
|
|
|
|
|
2018-03-28 03:08:04 +02:00
|
|
|
ConfirmSendEther.prototype.renderErrorMessage = function (message) {
|
|
|
|
const { send: { errors } } = this.props
|
|
|
|
|
|
|
|
return errors[message]
|
|
|
|
? h('div.confirm-screen-error', [ errors[message] ])
|
|
|
|
: null
|
|
|
|
}
|
|
|
|
|
2017-09-22 07:25:16 +02:00
|
|
|
ConfirmSendEther.prototype.onSubmit = function (event) {
|
2017-05-11 02:26:09 +02:00
|
|
|
event.preventDefault()
|
2018-03-28 03:08:04 +02:00
|
|
|
const { updateSendErrors } = this.props
|
2018-03-14 20:37:09 +01:00
|
|
|
const txMeta = this.gatherTxMeta()
|
2017-05-11 02:26:09 +02:00
|
|
|
const valid = this.checkValidity()
|
2018-03-28 03:08:04 +02:00
|
|
|
const balanceIsSufficient = this.isBalanceSufficient(txMeta)
|
2017-06-27 00:57:46 +02:00
|
|
|
this.setState({ valid, submitting: true })
|
2017-09-13 17:11:03 +02:00
|
|
|
|
2018-03-28 03:08:04 +02:00
|
|
|
if (valid && this.verifyGasParams() && balanceIsSufficient) {
|
2017-05-11 02:26:09 +02:00
|
|
|
this.props.sendTransaction(txMeta, event)
|
2018-03-28 03:08:04 +02:00
|
|
|
} else if (!balanceIsSufficient) {
|
2018-04-27 12:41:18 +02:00
|
|
|
updateSendErrors({ insufficientFunds: 'insufficientFunds' })
|
2017-05-11 02:26:09 +02:00
|
|
|
} else {
|
2018-04-27 12:41:18 +02:00
|
|
|
updateSendErrors({ invalidGasParams: 'invalidGasParams' })
|
2017-06-27 00:57:46 +02:00
|
|
|
this.setState({ submitting: false })
|
2017-05-11 02:26:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-22 07:25:16 +02:00
|
|
|
ConfirmSendEther.prototype.cancel = function (event, txMeta) {
|
2017-09-13 17:11:03 +02:00
|
|
|
event.preventDefault()
|
2017-12-20 18:17:16 +01:00
|
|
|
const { cancelTransaction } = this.props
|
2018-01-12 01:30:07 +01:00
|
|
|
|
2017-12-20 18:17:16 +01:00
|
|
|
cancelTransaction(txMeta)
|
2017-11-29 05:24:35 +01:00
|
|
|
.then(() => this.props.history.push(DEFAULT_ROUTE))
|
2017-09-13 17:11:03 +02:00
|
|
|
}
|
|
|
|
|
2018-03-28 03:08:04 +02:00
|
|
|
ConfirmSendEther.prototype.isBalanceSufficient = function (txMeta) {
|
|
|
|
const {
|
|
|
|
balance,
|
|
|
|
conversionRate,
|
|
|
|
} = this.props
|
|
|
|
const {
|
|
|
|
txParams: {
|
|
|
|
gas,
|
|
|
|
gasPrice,
|
|
|
|
value: amount,
|
|
|
|
},
|
|
|
|
} = txMeta
|
2018-05-05 17:11:53 +02:00
|
|
|
const gasTotal = calcGasTotal(gas, gasPrice)
|
2018-03-28 03:08:04 +02:00
|
|
|
|
|
|
|
return isBalanceSufficient({
|
|
|
|
amount,
|
|
|
|
gasTotal,
|
|
|
|
balance,
|
|
|
|
conversionRate,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-09-22 07:25:16 +02:00
|
|
|
ConfirmSendEther.prototype.checkValidity = function () {
|
2017-05-16 00:07:38 +02:00
|
|
|
const form = this.getFormEl()
|
2017-05-11 02:26:09 +02:00
|
|
|
const valid = form.checkValidity()
|
|
|
|
return valid
|
|
|
|
}
|
|
|
|
|
2017-09-22 07:25:16 +02:00
|
|
|
ConfirmSendEther.prototype.getFormEl = function () {
|
2017-05-16 00:07:38 +02:00
|
|
|
const form = document.querySelector('form#pending-tx-form')
|
|
|
|
// Stub out form for unit tests:
|
|
|
|
if (!form) {
|
2017-05-16 00:22:49 +02:00
|
|
|
return { checkValidity () { return true } }
|
2017-05-16 00:07:38 +02:00
|
|
|
}
|
|
|
|
return form
|
|
|
|
}
|
|
|
|
|
2017-03-23 21:44:09 +01:00
|
|
|
// After a customizable state value has been updated,
|
2018-03-14 20:37:09 +01:00
|
|
|
ConfirmSendEther.prototype.gatherTxMeta = function () {
|
2017-03-23 21:44:09 +01:00
|
|
|
const props = this.props
|
2017-03-28 20:46:33 +02:00
|
|
|
const state = this.state
|
2017-11-08 20:18:27 +01:00
|
|
|
const txData = clone(state.txData) || clone(props.txData)
|
2017-11-08 17:44:48 +01:00
|
|
|
|
2018-06-08 17:22:38 +02:00
|
|
|
const { gasPrice: sendGasPrice, gasLimit: sendGasLimit } = props.send
|
2018-03-14 22:33:14 +01:00
|
|
|
const {
|
|
|
|
lastGasPrice,
|
|
|
|
txParams: {
|
|
|
|
gasPrice: txGasPrice,
|
|
|
|
gas: txGasLimit,
|
|
|
|
},
|
|
|
|
} = txData
|
|
|
|
|
|
|
|
let forceGasMin
|
|
|
|
if (lastGasPrice) {
|
|
|
|
forceGasMin = ethUtil.addHexPrefix(multiplyCurrencies(lastGasPrice, 1.1, {
|
|
|
|
multiplicandBase: 16,
|
|
|
|
multiplierBase: 10,
|
|
|
|
toNumericBase: 'hex',
|
|
|
|
}))
|
|
|
|
}
|
2018-03-13 06:01:35 +01:00
|
|
|
|
2018-03-14 22:33:14 +01:00
|
|
|
txData.txParams.gasPrice = sendGasPrice || forceGasMin || txGasPrice
|
2018-03-14 20:40:59 +01:00
|
|
|
txData.txParams.gas = sendGasLimit || txGasLimit
|
2018-03-13 06:01:35 +01:00
|
|
|
|
2017-09-14 04:57:33 +02:00
|
|
|
// log.debug(`UI has defaulted to tx meta ${JSON.stringify(txData)}`)
|
2018-03-14 20:37:09 +01:00
|
|
|
return txData
|
2017-03-23 21:44:09 +01:00
|
|
|
}
|
|
|
|
|
2017-09-22 07:25:16 +02:00
|
|
|
ConfirmSendEther.prototype.verifyGasParams = function () {
|
2017-03-23 21:44:09 +01:00
|
|
|
// We call this in case the gas has not been modified at all
|
|
|
|
if (!this.state) { return true }
|
2017-03-28 20:46:33 +02:00
|
|
|
return (
|
|
|
|
this._notZeroOrEmptyString(this.state.gas) &&
|
|
|
|
this._notZeroOrEmptyString(this.state.gasPrice)
|
|
|
|
)
|
2017-03-23 21:44:09 +01:00
|
|
|
}
|
|
|
|
|
2017-09-22 07:25:16 +02:00
|
|
|
ConfirmSendEther.prototype._notZeroOrEmptyString = function (obj) {
|
2017-03-23 21:44:09 +01:00
|
|
|
return obj !== '' && obj !== '0x0'
|
|
|
|
}
|
|
|
|
|
2017-09-22 07:25:16 +02:00
|
|
|
ConfirmSendEther.prototype.bnMultiplyByFraction = function (targetBN, numerator, denominator) {
|
2017-06-03 00:18:14 +02:00
|
|
|
const numBN = new BN(numerator)
|
|
|
|
const denomBN = new BN(denominator)
|
|
|
|
return targetBN.mul(numBN).div(denomBN)
|
|
|
|
}
|