diff options
author | nyatla <nyatla39@gmail.com> | 2018-04-10 16:14:28 +0800 |
---|---|---|
committer | nyatla <nyatla39@gmail.com> | 2018-04-10 16:14:28 +0800 |
commit | cc246528b509b80e560715f3b315acf0764e99e7 (patch) | |
tree | a04cc12e6c11345bf751726f15fa9d3dd6be4733 /ui/app/send-v2.js | |
parent | bc0487006c623f1c81c186ba5b2a7137efb940ec (diff) | |
parent | b91bd818c7c2aec2952036a2f69ab05e0690a06e (diff) | |
download | tangerine-wallet-browser-cc246528b509b80e560715f3b315acf0764e99e7.tar.gz tangerine-wallet-browser-cc246528b509b80e560715f3b315acf0764e99e7.tar.zst tangerine-wallet-browser-cc246528b509b80e560715f3b315acf0764e99e7.zip |
Merge tag 'v4.5.5'
# Conflicts:
# app/_locales/ja/messages.json
# package-lock.json
messages.jsonのローカライズ
Diffstat (limited to 'ui/app/send-v2.js')
-rw-r--r-- | ui/app/send-v2.js | 63 |
1 files changed, 34 insertions, 29 deletions
diff --git a/ui/app/send-v2.js b/ui/app/send-v2.js index 620da73f8..094743ff0 100644 --- a/ui/app/send-v2.js +++ b/ui/app/send-v2.js @@ -1,7 +1,7 @@ const { inherits } = require('util') +const PropTypes = require('prop-types') const PersistentForm = require('../lib/persistent-form') const h = require('react-hyperscript') -const t = require('../i18n') const ethAbi = require('ethereumjs-abi') const ethUtil = require('ethereumjs-util') @@ -27,9 +27,14 @@ const { const { isBalanceSufficient, isTokenBalanceSufficient, + getGasTotal, } = require('./components/send/send-utils') const { isValidAddress } = require('./util') +SendTransactionScreen.contextTypes = { + t: PropTypes.func, +} + module.exports = SendTransactionScreen inherits(SendTransactionScreen, PersistentForm) @@ -128,7 +133,7 @@ SendTransactionScreen.prototype.updateGas = function () { estimateGas(estimateGasParams), ]) .then(([gasPrice, gas]) => { - const newGasTotal = this.getGasTotal(gas, gasPrice) + const newGasTotal = getGasTotal(gas, gasPrice) updateGasTotal(newGasTotal) this.setState({ gasLoadingError: false }) }) @@ -136,19 +141,11 @@ SendTransactionScreen.prototype.updateGas = function () { this.setState({ gasLoadingError: true }) }) } else { - const newGasTotal = this.getGasTotal(gasLimit, gasPrice) + const newGasTotal = getGasTotal(gasLimit, gasPrice) updateGasTotal(newGasTotal) } } -SendTransactionScreen.prototype.getGasTotal = function (gasLimit, gasPrice) { - return multiplyCurrencies(gasLimit, gasPrice, { - toNumericBase: 'hex', - multiplicandBase: 16, - multiplierBase: 16, - }) -} - SendTransactionScreen.prototype.componentDidUpdate = function (prevProps) { const { from: { balance }, @@ -189,9 +186,9 @@ SendTransactionScreen.prototype.renderHeader = function () { return h('div.page-container__header', [ - h('div.page-container__title', selectedToken ? t('sendTokens') : t('sendETH')), + h('div.page-container__title', selectedToken ? this.context.t('sendTokens') : this.context.t('sendETH')), - h('div.page-container__subtitle', t('onlySendToEtherAddress')), + h('div.page-container__subtitle', this.context.t('onlySendToEtherAddress')), h('div.page-container__header-close', { onClick: () => { @@ -257,16 +254,13 @@ SendTransactionScreen.prototype.handleToChange = function (to, nickname = '') { const { updateSendTo, updateSendErrors, - from: {address: from}, } = this.props let toError = null if (!to) { - toError = t('required') + toError = this.context.t('required') } else if (!isValidAddress(to)) { - toError = t('invalidAddressRecipient') - } else if (to === from) { - toError = t('fromToSame') + toError = this.context.t('invalidAddressRecipient') } updateSendTo(to, nickname) @@ -282,9 +276,9 @@ SendTransactionScreen.prototype.renderToRow = function () { h('div.send-v2__form-label', [ - t('to'), + this.context.t('to'), - this.renderErrorMessage(t('to')), + this.renderErrorMessage(this.context.t('to')), ]), @@ -385,11 +379,11 @@ SendTransactionScreen.prototype.validateAmount = function (value) { ) if (conversionRate && !sufficientBalance) { - amountError = t('insufficientFunds') + amountError = this.context.t('insufficientFunds') } else if (verifyTokenBalance && !sufficientTokens) { - amountError = t('insufficientTokens') + amountError = this.context.t('insufficientTokens') } else if (amountLessThanZero) { - amountError = t('negativeETH') + amountError = this.context.t('negativeETH') } updateSendErrors({ amount: amountError }) @@ -419,7 +413,7 @@ SendTransactionScreen.prototype.renderAmountRow = function () { setMaxModeTo(true) this.setAmountToMax() }, - }, [ !maxModeOn ? t('max') : '' ]), + }, [ !maxModeOn ? this.context.t('max') : '' ]), ]), h('div.send-v2__form-field', [ @@ -448,7 +442,7 @@ SendTransactionScreen.prototype.renderGasRow = function () { return h('div.send-v2__form-row', [ - h('div.send-v2__form-label', h('gasFee')), + h('div.send-v2__form-label', this.context.t('gasFee')), h('div.send-v2__form-field', [ @@ -518,11 +512,11 @@ SendTransactionScreen.prototype.renderFooter = function () { clearSend() goHome() }, - }, t('cancel')), + }, this.context.t('cancel')), h('button.btn-primary--lg.page-container__footer-button', { disabled: !noErrors || !gasTotal || missingTokenBalance, onClick: event => this.onSubmit(event), - }, t('next')), + }, this.context.t('next')), ]) } @@ -582,12 +576,17 @@ SendTransactionScreen.prototype.getEditedTx = function () { data, }) } else { - const data = unapprovedTxs[editingTransactionId].txParams.data + const { data } = unapprovedTxs[editingTransactionId].txParams + Object.assign(editingTx.txParams, { value: ethUtil.addHexPrefix(amount), to: ethUtil.addHexPrefix(to), data, }) + + if (typeof editingTx.txParams.data === 'undefined') { + delete editingTx.txParams.data + } } return editingTx @@ -597,7 +596,7 @@ SendTransactionScreen.prototype.onSubmit = function (event) { event.preventDefault() const { from: {address: from}, - to, + to: _to, amount, gasLimit: gas, gasPrice, @@ -616,6 +615,8 @@ SendTransactionScreen.prototype.onSubmit = function (event) { return } + const to = ethUtil.addHexPrefix(_to) + this.addToAddressBookIfNew(to, toNickname) if (editingTransactionId) { @@ -636,6 +637,10 @@ SendTransactionScreen.prototype.onSubmit = function (event) { txParams.to = to } + Object.keys(txParams).forEach(key => { + txParams[key] = ethUtil.addHexPrefix(txParams[key]) + }) + selectedToken ? signTokenTx(selectedToken.address, to, amount, txParams) : signTx(txParams) |