2017-09-22 23:34:56 +02:00
|
|
|
const Component = require('react').Component
|
|
|
|
const { connect } = require('react-redux')
|
|
|
|
const h = require('react-hyperscript')
|
|
|
|
const inherits = require('util').inherits
|
2017-11-09 16:14:32 +01:00
|
|
|
const tokenAbi = require('human-standard-token-abi')
|
2017-09-22 23:34:56 +02:00
|
|
|
const abiDecoder = require('abi-decoder')
|
2017-11-09 16:14:32 +01:00
|
|
|
abiDecoder.addABI(tokenAbi)
|
2017-09-22 23:34:56 +02:00
|
|
|
const actions = require('../../actions')
|
2018-01-24 21:10:28 +01:00
|
|
|
const t = require('../../../i18n')
|
2017-09-22 23:34:56 +02:00
|
|
|
const clone = require('clone')
|
|
|
|
const Identicon = require('../identicon')
|
2018-03-14 03:14:05 +01:00
|
|
|
const GasFeeDisplay = require('../send/gas-fee-display-v2.js')
|
2017-09-22 23:34:56 +02:00
|
|
|
const ethUtil = require('ethereumjs-util')
|
|
|
|
const BN = ethUtil.BN
|
2017-10-18 20:08:53 +02:00
|
|
|
const {
|
|
|
|
conversionUtil,
|
|
|
|
multiplyCurrencies,
|
|
|
|
addCurrencies,
|
|
|
|
} = require('../../conversion-util')
|
2018-03-28 03:53:57 +02:00
|
|
|
const {
|
|
|
|
getGasTotal,
|
|
|
|
isBalanceSufficient,
|
|
|
|
} = require('../send/send-utils')
|
2017-10-30 18:48:50 +01:00
|
|
|
const {
|
|
|
|
calcTokenAmount,
|
|
|
|
} = require('../../token-util')
|
2018-03-28 03:53:57 +02:00
|
|
|
const classnames = require('classnames')
|
2017-09-22 23:34:56 +02:00
|
|
|
|
2017-10-26 18:06:34 +02:00
|
|
|
const { MIN_GAS_PRICE_HEX } = require('../send/send-constants')
|
2017-09-22 23:34:56 +02:00
|
|
|
|
2017-10-18 20:08:53 +02:00
|
|
|
const {
|
|
|
|
getTokenExchangeRate,
|
|
|
|
getSelectedAddress,
|
2017-11-09 16:14:32 +01:00
|
|
|
getSelectedTokenContract,
|
2017-10-18 20:08:53 +02:00
|
|
|
} = require('../../selectors')
|
|
|
|
|
2017-09-22 23:34:56 +02:00
|
|
|
module.exports = connect(mapStateToProps, mapDispatchToProps)(ConfirmSendToken)
|
|
|
|
|
|
|
|
function mapStateToProps (state, ownProps) {
|
|
|
|
const { token: { symbol }, txData } = ownProps
|
|
|
|
const { txParams } = txData || {}
|
|
|
|
const tokenData = txParams.data && abiDecoder.decodeMethod(txParams.data)
|
2017-11-09 16:14:32 +01:00
|
|
|
|
2017-09-22 23:34:56 +02:00
|
|
|
const {
|
|
|
|
conversionRate,
|
|
|
|
identities,
|
2017-10-20 22:43:55 +02:00
|
|
|
currentCurrency,
|
2017-09-22 23:34:56 +02:00
|
|
|
} = state.metamask
|
2018-03-28 03:53:57 +02:00
|
|
|
const accounts = state.metamask.accounts
|
2017-10-18 20:08:53 +02:00
|
|
|
const selectedAddress = getSelectedAddress(state)
|
|
|
|
const tokenExchangeRate = getTokenExchangeRate(state, symbol)
|
2018-03-28 03:53:57 +02:00
|
|
|
const { balance } = accounts[selectedAddress]
|
2017-09-22 23:34:56 +02:00
|
|
|
return {
|
|
|
|
conversionRate,
|
|
|
|
identities,
|
|
|
|
selectedAddress,
|
|
|
|
tokenExchangeRate,
|
|
|
|
tokenData: tokenData || {},
|
2017-10-20 22:43:55 +02:00
|
|
|
currentCurrency: currentCurrency.toUpperCase(),
|
2017-11-09 16:14:32 +01:00
|
|
|
send: state.metamask.send,
|
|
|
|
tokenContract: getSelectedTokenContract(state),
|
2018-03-28 03:53:57 +02:00
|
|
|
balance,
|
2017-09-22 23:34:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function mapDispatchToProps (dispatch, ownProps) {
|
|
|
|
const { token: { symbol } } = ownProps
|
|
|
|
|
|
|
|
return {
|
|
|
|
backToAccountDetail: address => dispatch(actions.backToAccountDetail(address)),
|
|
|
|
cancelTransaction: ({ id }) => dispatch(actions.cancelTx({ id })),
|
|
|
|
updateTokenExchangeRate: () => dispatch(actions.updateTokenExchangeRate(symbol)),
|
2017-11-09 16:14:32 +01:00
|
|
|
editTransaction: txMeta => {
|
|
|
|
const { token: { address } } = ownProps
|
2018-03-09 16:31:17 +01:00
|
|
|
const { txParams = {}, id } = txMeta
|
|
|
|
const tokenData = txParams.data && abiDecoder.decodeMethod(txParams.data) || {}
|
2017-11-09 16:14:32 +01:00
|
|
|
const { params = [] } = tokenData
|
2017-12-13 07:24:41 +01:00
|
|
|
const { value: to } = params[0] || {}
|
|
|
|
const { value: tokenAmountInDec } = params[1] || {}
|
|
|
|
const tokenAmountInHex = conversionUtil(tokenAmountInDec, {
|
2017-11-09 16:14:32 +01:00
|
|
|
fromNumericBase: 'dec',
|
|
|
|
toNumericBase: 'hex',
|
|
|
|
})
|
|
|
|
const {
|
|
|
|
gas: gasLimit,
|
|
|
|
gasPrice,
|
|
|
|
} = txParams
|
|
|
|
dispatch(actions.setSelectedToken(address))
|
2017-11-10 04:49:16 +01:00
|
|
|
dispatch(actions.updateSend({
|
|
|
|
gasLimit,
|
|
|
|
gasPrice,
|
|
|
|
gasTotal: null,
|
|
|
|
to,
|
2017-12-13 07:24:41 +01:00
|
|
|
amount: tokenAmountInHex,
|
2017-11-10 04:49:16 +01:00
|
|
|
errors: { to: null, amount: null },
|
|
|
|
editingTransactionId: id,
|
2018-03-20 12:37:23 +01:00
|
|
|
token: ownProps.token,
|
2017-11-10 04:49:16 +01:00
|
|
|
}))
|
2017-11-09 16:14:32 +01:00
|
|
|
dispatch(actions.showSendTokenPage())
|
|
|
|
},
|
2018-03-14 03:14:05 +01:00
|
|
|
showCustomizeGasModal: (txMeta, sendGasLimit, sendGasPrice, sendGasTotal) => {
|
|
|
|
const { id, txParams, lastGasPrice } = txMeta
|
|
|
|
const { gas: txGasLimit, gasPrice: txGasPrice } = txParams
|
|
|
|
const tokenData = txParams.data && abiDecoder.decodeMethod(txParams.data)
|
|
|
|
const { params = [] } = tokenData
|
|
|
|
const { value: to } = params[0] || {}
|
|
|
|
const { value: tokenAmountInDec } = params[1] || {}
|
|
|
|
const tokenAmountInHex = conversionUtil(tokenAmountInDec, {
|
|
|
|
fromNumericBase: 'dec',
|
|
|
|
toNumericBase: 'hex',
|
|
|
|
})
|
|
|
|
|
|
|
|
let forceGasMin
|
|
|
|
if (lastGasPrice) {
|
2018-03-14 22:20:18 +01:00
|
|
|
forceGasMin = ethUtil.addHexPrefix(multiplyCurrencies(lastGasPrice, 1.1, {
|
2018-03-14 03:14:05 +01:00
|
|
|
multiplicandBase: 16,
|
|
|
|
multiplierBase: 10,
|
|
|
|
toNumericBase: 'hex',
|
|
|
|
fromDenomination: 'WEI',
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch(actions.updateSend({
|
|
|
|
gasLimit: sendGasLimit || txGasLimit,
|
|
|
|
gasPrice: sendGasPrice || txGasPrice,
|
|
|
|
editingTransactionId: id,
|
|
|
|
gasTotal: sendGasTotal,
|
|
|
|
to,
|
|
|
|
amount: tokenAmountInHex,
|
|
|
|
forceGasMin,
|
|
|
|
}))
|
|
|
|
dispatch(actions.showModal({ name: 'CUSTOMIZE_GAS' }))
|
|
|
|
},
|
2018-03-28 03:53:57 +02:00
|
|
|
updateSendErrors: error => dispatch(actions.updateSendErrors(error)),
|
2017-09-22 23:34:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inherits(ConfirmSendToken, Component)
|
|
|
|
function ConfirmSendToken () {
|
|
|
|
Component.call(this)
|
|
|
|
this.state = {}
|
|
|
|
this.onSubmit = this.onSubmit.bind(this)
|
|
|
|
}
|
|
|
|
|
|
|
|
ConfirmSendToken.prototype.componentWillMount = function () {
|
2017-11-09 16:14:32 +01:00
|
|
|
const { tokenContract, selectedAddress } = this.props
|
|
|
|
tokenContract && tokenContract
|
|
|
|
.balanceOf(selectedAddress)
|
|
|
|
.then(usersToken => {
|
|
|
|
})
|
2017-09-22 23:34:56 +02:00
|
|
|
this.props.updateTokenExchangeRate()
|
|
|
|
}
|
|
|
|
|
|
|
|
ConfirmSendToken.prototype.getAmount = function () {
|
2017-11-09 16:14:32 +01:00
|
|
|
const {
|
|
|
|
conversionRate,
|
|
|
|
tokenExchangeRate,
|
|
|
|
token,
|
|
|
|
tokenData,
|
|
|
|
send: { amount, editingTransactionId },
|
|
|
|
} = this.props
|
2017-09-22 23:34:56 +02:00
|
|
|
const { params = [] } = tokenData
|
2017-11-09 16:14:32 +01:00
|
|
|
let { value } = params[1] || {}
|
2017-09-22 23:34:56 +02:00
|
|
|
const { decimals } = token
|
2017-11-09 16:14:32 +01:00
|
|
|
|
|
|
|
if (editingTransactionId) {
|
|
|
|
value = conversionUtil(amount, {
|
|
|
|
fromNumericBase: 'hex',
|
|
|
|
toNumericBase: 'dec',
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-10-30 18:48:50 +01:00
|
|
|
const sendTokenAmount = calcTokenAmount(value, decimals)
|
2017-09-22 23:34:56 +02:00
|
|
|
|
|
|
|
return {
|
|
|
|
fiat: tokenExchangeRate
|
|
|
|
? +(sendTokenAmount * tokenExchangeRate * conversionRate).toFixed(2)
|
|
|
|
: null,
|
2017-10-21 01:18:25 +02:00
|
|
|
token: typeof value === 'undefined'
|
2018-01-24 09:14:47 +01:00
|
|
|
? t('unknown')
|
2017-10-21 01:18:25 +02:00
|
|
|
: +sendTokenAmount.toFixed(decimals),
|
2017-09-22 23:34:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ConfirmSendToken.prototype.getGasFee = function () {
|
2017-10-19 04:09:26 +02:00
|
|
|
const { conversionRate, tokenExchangeRate, token, currentCurrency } = this.props
|
2017-09-22 23:34:56 +02:00
|
|
|
const txMeta = this.gatherTxMeta()
|
|
|
|
const txParams = txMeta.txParams || {}
|
|
|
|
const { decimals } = token
|
|
|
|
|
|
|
|
const gas = txParams.gas
|
2017-10-26 18:06:34 +02:00
|
|
|
const gasPrice = txParams.gasPrice || MIN_GAS_PRICE_HEX
|
2017-10-18 20:08:53 +02:00
|
|
|
const gasTotal = multiplyCurrencies(gas, gasPrice, {
|
|
|
|
multiplicandBase: 16,
|
|
|
|
multiplierBase: 16,
|
|
|
|
})
|
2017-09-22 23:34:56 +02:00
|
|
|
|
2017-10-20 22:43:55 +02:00
|
|
|
const FIAT = conversionUtil(gasTotal, {
|
2017-09-22 23:34:56 +02:00
|
|
|
fromNumericBase: 'BN',
|
|
|
|
toNumericBase: 'dec',
|
|
|
|
fromDenomination: 'WEI',
|
|
|
|
fromCurrency: 'ETH',
|
2017-10-19 04:09:26 +02:00
|
|
|
toCurrency: currentCurrency,
|
2017-09-22 23:34:56 +02:00
|
|
|
numberOfDecimals: 2,
|
|
|
|
conversionRate,
|
|
|
|
})
|
2017-10-18 20:08:53 +02:00
|
|
|
const ETH = conversionUtil(gasTotal, {
|
2017-09-22 23:34:56 +02:00
|
|
|
fromNumericBase: 'BN',
|
|
|
|
toNumericBase: 'dec',
|
|
|
|
fromDenomination: 'WEI',
|
|
|
|
fromCurrency: 'ETH',
|
|
|
|
toCurrency: 'ETH',
|
|
|
|
numberOfDecimals: 6,
|
|
|
|
conversionRate,
|
|
|
|
})
|
2017-10-18 20:08:53 +02:00
|
|
|
const tokenGas = multiplyCurrencies(gas, gasPrice, {
|
|
|
|
toNumericBase: 'dec',
|
|
|
|
multiplicandBase: 16,
|
|
|
|
multiplierBase: 16,
|
|
|
|
toCurrency: 'BAT',
|
|
|
|
conversionRate: tokenExchangeRate,
|
|
|
|
invertConversionRate: true,
|
|
|
|
fromDenomination: 'WEI',
|
|
|
|
numberOfDecimals: decimals || 4,
|
|
|
|
})
|
2017-09-22 23:34:56 +02:00
|
|
|
|
|
|
|
return {
|
2017-10-19 04:09:26 +02:00
|
|
|
fiat: +Number(FIAT).toFixed(2),
|
2017-09-22 23:34:56 +02:00
|
|
|
eth: ETH,
|
|
|
|
token: tokenExchangeRate
|
2017-10-18 20:08:53 +02:00
|
|
|
? tokenGas
|
2017-09-22 23:34:56 +02:00
|
|
|
: null,
|
2018-03-14 03:14:05 +01:00
|
|
|
gasFeeInHex: gasTotal.toString(16),
|
2017-09-22 23:34:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ConfirmSendToken.prototype.getData = function () {
|
2017-10-10 23:36:13 +02:00
|
|
|
const { identities, tokenData } = this.props
|
|
|
|
const { params = [] } = tokenData
|
|
|
|
const { value } = params[0] || {}
|
2017-09-22 23:34:56 +02:00
|
|
|
const txMeta = this.gatherTxMeta()
|
|
|
|
const txParams = txMeta.txParams || {}
|
2017-11-02 13:15:59 +01:00
|
|
|
|
2017-09-22 23:34:56 +02:00
|
|
|
return {
|
|
|
|
from: {
|
|
|
|
address: txParams.from,
|
|
|
|
name: identities[txParams.from].name,
|
|
|
|
},
|
|
|
|
to: {
|
2017-10-18 20:26:13 +02:00
|
|
|
address: value,
|
2018-01-24 09:14:47 +01:00
|
|
|
name: identities[value] ? identities[value].name : t('newRecipient'),
|
2017-09-22 23:34:56 +02:00
|
|
|
},
|
|
|
|
memo: txParams.memo || '',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ConfirmSendToken.prototype.renderHeroAmount = function () {
|
2017-10-19 04:09:26 +02:00
|
|
|
const { token: { symbol }, currentCurrency } = this.props
|
2017-09-22 23:34:56 +02:00
|
|
|
const { fiat: fiatAmount, token: tokenAmount } = this.getAmount()
|
|
|
|
const txMeta = this.gatherTxMeta()
|
|
|
|
const txParams = txMeta.txParams || {}
|
|
|
|
const { memo = '' } = txParams
|
|
|
|
|
|
|
|
return fiatAmount
|
|
|
|
? (
|
|
|
|
h('div.confirm-send-token__hero-amount-wrapper', [
|
2017-10-19 04:09:26 +02:00
|
|
|
h('h3.flex-center.confirm-screen-send-amount', `${fiatAmount}`),
|
|
|
|
h('h3.flex-center.confirm-screen-send-amount-currency', currentCurrency),
|
2017-09-22 23:34:56 +02:00
|
|
|
h('div.flex-center.confirm-memo-wrapper', [
|
2017-10-10 23:30:20 +02:00
|
|
|
h('h3.confirm-screen-send-memo', [ memo ? `"${memo}"` : '' ]),
|
2017-09-22 23:34:56 +02:00
|
|
|
]),
|
|
|
|
])
|
|
|
|
)
|
|
|
|
: (
|
|
|
|
h('div.confirm-send-token__hero-amount-wrapper', [
|
|
|
|
h('h3.flex-center.confirm-screen-send-amount', tokenAmount),
|
|
|
|
h('h3.flex-center.confirm-screen-send-amount-currency', symbol),
|
|
|
|
h('div.flex-center.confirm-memo-wrapper', [
|
2017-10-10 23:30:20 +02:00
|
|
|
h('h3.confirm-screen-send-memo', [ memo ? `"${memo}"` : '' ]),
|
2017-09-22 23:34:56 +02:00
|
|
|
]),
|
|
|
|
])
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
ConfirmSendToken.prototype.renderGasFee = function () {
|
2018-03-14 03:14:05 +01:00
|
|
|
const {
|
|
|
|
currentCurrency: convertedCurrency,
|
|
|
|
conversionRate,
|
|
|
|
send: { gasTotal, gasLimit: sendGasLimit, gasPrice: sendGasPrice },
|
|
|
|
showCustomizeGasModal,
|
|
|
|
} = this.props
|
|
|
|
const txMeta = this.gatherTxMeta()
|
2018-03-14 03:26:45 +01:00
|
|
|
const { gasFeeInHex } = this.getGasFee()
|
2017-09-22 23:34:56 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
h('section.flex-row.flex-center.confirm-screen-row', [
|
2018-01-24 09:14:47 +01:00
|
|
|
h('span.confirm-screen-label.confirm-screen-section-column', [ t('gasFee') ]),
|
2017-09-22 23:34:56 +02:00
|
|
|
h('div.confirm-screen-section-column', [
|
2018-03-14 03:14:05 +01:00
|
|
|
h(GasFeeDisplay, {
|
|
|
|
gasTotal: gasTotal || gasFeeInHex,
|
|
|
|
conversionRate,
|
|
|
|
convertedCurrency,
|
|
|
|
onClick: () => showCustomizeGasModal(txMeta, sendGasLimit, sendGasPrice, gasTotal),
|
|
|
|
}),
|
2017-09-22 23:34:56 +02:00
|
|
|
]),
|
|
|
|
])
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
ConfirmSendToken.prototype.renderTotalPlusGas = function () {
|
2018-03-28 03:53:57 +02:00
|
|
|
const { token: { symbol }, currentCurrency, send: { errors } } = this.props
|
2017-09-22 23:34:56 +02:00
|
|
|
const { fiat: fiatAmount, token: tokenAmount } = this.getAmount()
|
|
|
|
const { fiat: fiatGas, token: tokenGas } = this.getGasFee()
|
|
|
|
|
|
|
|
return fiatAmount && fiatGas
|
|
|
|
? (
|
2018-03-17 00:39:00 +01:00
|
|
|
h('section.flex-row.flex-center.confirm-screen-row.confirm-screen-total-box ', [
|
2017-09-22 23:34:56 +02:00
|
|
|
h('div.confirm-screen-section-column', [
|
2018-01-24 09:14:47 +01:00
|
|
|
h('span.confirm-screen-label', [ t('total') + ' ' ]),
|
|
|
|
h('div.confirm-screen-total-box__subtitle', [ t('amountPlusGas') ]),
|
2017-09-22 23:34:56 +02:00
|
|
|
]),
|
|
|
|
|
|
|
|
h('div.confirm-screen-section-column', [
|
2017-10-21 03:57:59 +02:00
|
|
|
h('div.confirm-screen-row-info', `${addCurrencies(fiatAmount, fiatGas)} ${currentCurrency}`),
|
2017-10-21 01:18:25 +02:00
|
|
|
h('div.confirm-screen-row-detail', `${addCurrencies(tokenAmount, tokenGas || '0')} ${symbol}`),
|
2017-09-22 23:34:56 +02:00
|
|
|
]),
|
|
|
|
])
|
|
|
|
)
|
|
|
|
: (
|
2018-03-17 00:39:00 +01:00
|
|
|
h('section.flex-row.flex-center.confirm-screen-row.confirm-screen-total-box ', [
|
2018-03-28 03:53:57 +02:00
|
|
|
h('div', {
|
|
|
|
className: classnames({
|
|
|
|
'confirm-screen-section-column--with-error': errors['insufficientFunds'],
|
|
|
|
'confirm-screen-section-column': !errors['insufficientFunds'],
|
|
|
|
}),
|
|
|
|
}, [
|
2018-01-24 09:14:47 +01:00
|
|
|
h('span.confirm-screen-label', [ t('total') + ' ' ]),
|
|
|
|
h('div.confirm-screen-total-box__subtitle', [ t('amountPlusGas') ]),
|
2017-09-22 23:34:56 +02:00
|
|
|
]),
|
|
|
|
|
|
|
|
h('div.confirm-screen-section-column', [
|
|
|
|
h('div.confirm-screen-row-info', `${tokenAmount} ${symbol}`),
|
2018-01-29 21:29:01 +01:00
|
|
|
h('div.confirm-screen-row-detail', `+ ${fiatGas} ${currentCurrency} ${t('gas')}`),
|
2017-09-22 23:34:56 +02:00
|
|
|
]),
|
2018-03-28 03:53:57 +02:00
|
|
|
|
|
|
|
this.renderErrorMessage('insufficientFunds'),
|
2017-09-22 23:34:56 +02:00
|
|
|
])
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2018-03-28 03:53:57 +02:00
|
|
|
ConfirmSendToken.prototype.renderErrorMessage = function (message) {
|
|
|
|
const { send: { errors } } = this.props
|
|
|
|
|
|
|
|
return errors[message]
|
|
|
|
? h('div.confirm-screen-error', [ errors[message] ])
|
|
|
|
: null
|
|
|
|
}
|
|
|
|
|
2017-09-22 23:34:56 +02:00
|
|
|
ConfirmSendToken.prototype.render = function () {
|
2017-11-09 16:14:32 +01:00
|
|
|
const { editTransaction } = this.props
|
2017-09-22 23:34:56 +02:00
|
|
|
const txMeta = this.gatherTxMeta()
|
|
|
|
const {
|
|
|
|
from: {
|
|
|
|
address: fromAddress,
|
|
|
|
name: fromName,
|
|
|
|
},
|
|
|
|
to: {
|
|
|
|
address: toAddress,
|
|
|
|
name: toName,
|
|
|
|
},
|
|
|
|
} = this.getData()
|
|
|
|
|
|
|
|
this.inputs = []
|
|
|
|
|
2018-03-14 03:32:27 +01:00
|
|
|
const title = txMeta.lastGasPrice ? 'Reprice Transaction' : t('confirm')
|
2018-03-14 03:14:05 +01:00
|
|
|
const subtitle = txMeta.lastGasPrice
|
|
|
|
? 'Increase your gas fee to attempt to overwrite and speed up your transaction'
|
2018-03-14 03:32:27 +01:00
|
|
|
: t('pleaseReviewTransaction')
|
2018-03-14 03:14:05 +01:00
|
|
|
|
2017-09-22 23:34:56 +02:00
|
|
|
return (
|
2018-02-13 07:51:05 +01:00
|
|
|
h('div.confirm-screen-container.confirm-send-token', [
|
2017-09-22 23:34:56 +02:00
|
|
|
// Main Send token Card
|
2018-02-13 07:51:05 +01:00
|
|
|
h('div.page-container', [
|
|
|
|
h('div.page-container__header', [
|
2018-03-14 03:14:05 +01:00
|
|
|
!txMeta.lastGasPrice && h('button.confirm-screen-back-button', {
|
2017-11-09 16:14:32 +01:00
|
|
|
onClick: () => editTransaction(txMeta),
|
2018-01-29 21:29:01 +01:00
|
|
|
}, t('edit')),
|
2018-03-14 03:14:05 +01:00
|
|
|
h('div.page-container__title', title),
|
|
|
|
h('div.page-container__subtitle', subtitle),
|
2017-09-22 23:34:56 +02:00
|
|
|
]),
|
2018-03-17 00:39:00 +01:00
|
|
|
h('.page-container__content', [
|
|
|
|
h('div.flex-row.flex-center.confirm-screen-identicons', [
|
|
|
|
h('div.confirm-screen-account-wrapper', [
|
|
|
|
h(
|
|
|
|
Identicon,
|
|
|
|
{
|
|
|
|
address: fromAddress,
|
|
|
|
diameter: 60,
|
|
|
|
},
|
|
|
|
),
|
|
|
|
h('span.confirm-screen-account-name', fromName),
|
|
|
|
// h('span.confirm-screen-account-number', fromAddress.slice(fromAddress.length - 4)),
|
|
|
|
]),
|
|
|
|
h('i.fa.fa-arrow-right.fa-lg'),
|
|
|
|
h('div.confirm-screen-account-wrapper', [
|
|
|
|
h(
|
|
|
|
Identicon,
|
|
|
|
{
|
|
|
|
address: toAddress,
|
|
|
|
diameter: 60,
|
|
|
|
},
|
|
|
|
),
|
|
|
|
h('span.confirm-screen-account-name', toName),
|
|
|
|
// h('span.confirm-screen-account-number', toAddress.slice(toAddress.length - 4)),
|
|
|
|
]),
|
2017-09-22 23:34:56 +02:00
|
|
|
]),
|
|
|
|
|
2018-03-17 00:39:00 +01:00
|
|
|
// h('h3.flex-center.confirm-screen-sending-to-message', {
|
|
|
|
// style: {
|
|
|
|
// textAlign: 'center',
|
|
|
|
// fontSize: '16px',
|
|
|
|
// },
|
|
|
|
// }, [
|
|
|
|
// `You're sending to Recipient ...${toAddress.slice(toAddress.length - 4)}`,
|
|
|
|
// ]),
|
|
|
|
|
|
|
|
this.renderHeroAmount(),
|
|
|
|
|
|
|
|
h('div.confirm-screen-rows', [
|
|
|
|
h('section.flex-row.flex-center.confirm-screen-row', [
|
|
|
|
h('span.confirm-screen-label.confirm-screen-section-column', [ t('from') ]),
|
|
|
|
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-09-22 23:34:56 +02:00
|
|
|
]),
|
|
|
|
|
2018-03-17 00:39:00 +01:00
|
|
|
toAddress && h('section.flex-row.flex-center.confirm-screen-row', [
|
|
|
|
h('span.confirm-screen-label.confirm-screen-section-column', [ t('to') ]),
|
|
|
|
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-09-22 23:34:56 +02:00
|
|
|
]),
|
|
|
|
|
2018-03-17 00:39:00 +01:00
|
|
|
this.renderGasFee(),
|
2017-09-22 23:34:56 +02:00
|
|
|
|
2018-03-17 00:39:00 +01:00
|
|
|
this.renderTotalPlusGas(),
|
2017-09-22 23:34:56 +02:00
|
|
|
|
2018-03-17 00:39:00 +01:00
|
|
|
]),
|
2017-10-10 23:30:20 +02:00
|
|
|
|
2018-03-17 00:39:00 +01:00
|
|
|
]),
|
|
|
|
h('form#pending-tx-form', {
|
|
|
|
onSubmit: this.onSubmit,
|
|
|
|
}, [
|
|
|
|
h('.page-container__footer', [
|
|
|
|
// Cancel Button
|
|
|
|
h('button.btn-cancel.page-container__footer-button.allcaps', {
|
|
|
|
onClick: (event) => this.cancel(event, txMeta),
|
|
|
|
}, t('cancel')),
|
|
|
|
|
|
|
|
// Accept Button
|
|
|
|
h('button.btn-confirm.page-container__footer-button.allcaps', [t('confirm')]),
|
|
|
|
]),
|
|
|
|
]),
|
2017-09-22 23:34:56 +02:00
|
|
|
]),
|
|
|
|
])
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
ConfirmSendToken.prototype.onSubmit = function (event) {
|
|
|
|
event.preventDefault()
|
2018-03-28 03:53:57 +02:00
|
|
|
const { updateSendErrors } = this.props
|
2017-09-22 23:34:56 +02:00
|
|
|
const txMeta = this.gatherTxMeta()
|
|
|
|
const valid = this.checkValidity()
|
2018-03-28 03:53:57 +02:00
|
|
|
const balanceIsSufficient = this.isBalanceSufficient(txMeta)
|
2017-09-22 23:34:56 +02:00
|
|
|
this.setState({ valid, submitting: true })
|
|
|
|
|
2018-03-28 03:53:57 +02:00
|
|
|
if (valid && this.verifyGasParams() && balanceIsSufficient) {
|
2017-09-22 23:34:56 +02:00
|
|
|
this.props.sendTransaction(txMeta, event)
|
2018-03-28 03:53:57 +02:00
|
|
|
} else if (!balanceIsSufficient) {
|
|
|
|
updateSendErrors({ insufficientFunds: t('insufficientFunds') })
|
2017-09-22 23:34:56 +02:00
|
|
|
} else {
|
2018-03-28 03:53:57 +02:00
|
|
|
updateSendErrors({ invalidGasParams: t('invalidGasParams') })
|
2017-09-22 23:34:56 +02:00
|
|
|
this.setState({ submitting: false })
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-28 03:53:57 +02:00
|
|
|
ConfirmSendToken.prototype.isBalanceSufficient = function (txMeta) {
|
|
|
|
const {
|
|
|
|
balance,
|
|
|
|
conversionRate,
|
|
|
|
} = this.props
|
|
|
|
const {
|
|
|
|
txParams: {
|
|
|
|
gas,
|
|
|
|
gasPrice,
|
|
|
|
},
|
|
|
|
} = txMeta
|
|
|
|
const gasTotal = getGasTotal(gas, gasPrice)
|
|
|
|
|
|
|
|
return isBalanceSufficient({
|
|
|
|
amount: '0',
|
|
|
|
gasTotal,
|
|
|
|
balance,
|
|
|
|
conversionRate,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-09-22 23:34:56 +02:00
|
|
|
ConfirmSendToken.prototype.cancel = function (event, txMeta) {
|
|
|
|
event.preventDefault()
|
2017-12-20 19:35:41 +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-09-22 23:34:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ConfirmSendToken.prototype.checkValidity = function () {
|
|
|
|
const form = this.getFormEl()
|
|
|
|
const valid = form.checkValidity()
|
|
|
|
return valid
|
|
|
|
}
|
|
|
|
|
|
|
|
ConfirmSendToken.prototype.getFormEl = function () {
|
|
|
|
const form = document.querySelector('form#pending-tx-form')
|
|
|
|
// Stub out form for unit tests:
|
|
|
|
if (!form) {
|
|
|
|
return { checkValidity () { return true } }
|
|
|
|
}
|
|
|
|
return form
|
|
|
|
}
|
|
|
|
|
|
|
|
// After a customizable state value has been updated,
|
|
|
|
ConfirmSendToken.prototype.gatherTxMeta = function () {
|
|
|
|
const props = this.props
|
|
|
|
const state = this.state
|
|
|
|
const txData = clone(state.txData) || clone(props.txData)
|
|
|
|
|
2018-03-14 20:40:59 +01:00
|
|
|
const { gasPrice: sendGasPrice, gas: 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-14 03:14:05 +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-14 03:14:05 +01:00
|
|
|
|
2017-09-22 23:34:56 +02:00
|
|
|
// log.debug(`UI has defaulted to tx meta ${JSON.stringify(txData)}`)
|
|
|
|
return txData
|
|
|
|
}
|
|
|
|
|
|
|
|
ConfirmSendToken.prototype.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)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
ConfirmSendToken.prototype._notZeroOrEmptyString = function (obj) {
|
|
|
|
return obj !== '' && obj !== '0x0'
|
|
|
|
}
|
|
|
|
|
|
|
|
ConfirmSendToken.prototype.bnMultiplyByFraction = function (targetBN, numerator, denominator) {
|
|
|
|
const numBN = new BN(numerator)
|
|
|
|
const denomBN = new BN(denominator)
|
|
|
|
return targetBN.mul(numBN).div(denomBN)
|
|
|
|
}
|