aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/send.js
diff options
context:
space:
mode:
authorChi Kei Chan <chikeichan@gmail.com>2017-09-26 10:56:12 +0800
committerGitHub <noreply@github.com>2017-09-26 10:56:12 +0800
commitd1737777f0fcc78cf034c52aa1fb039f40eca4e2 (patch)
tree6635c935a75e69ed8d33703f6b174511df0b9cab /ui/app/send.js
parent5f6ec6aa982101bed57d9a8766330af71a274183 (diff)
parent0d4433ed58ea7c5f9518170b7be44b194041eba7 (diff)
downloadtangerine-wallet-browser-d1737777f0fcc78cf034c52aa1fb039f40eca4e2.tar.gz
tangerine-wallet-browser-d1737777f0fcc78cf034c52aa1fb039f40eca4e2.tar.zst
tangerine-wallet-browser-d1737777f0fcc78cf034c52aa1fb039f40eca4e2.zip
Merge pull request #2157 from danjm/MM-57-use-gas-estimator
[NewUI] Estimate gasPrice and gasLimit in send screen.
Diffstat (limited to 'ui/app/send.js')
-rw-r--r--ui/app/send.js61
1 files changed, 52 insertions, 9 deletions
diff --git a/ui/app/send.js b/ui/app/send.js
index 6c701f982..8791e9124 100644
--- a/ui/app/send.js
+++ b/ui/app/send.js
@@ -16,6 +16,8 @@ const {
hideWarning,
addToAddressBook,
signTx,
+ estimateGas,
+ getGasPrice,
} = require('./actions')
const { stripHexPrefix, addHexPrefix } = require('ethereumjs-util')
const { isHex, numericBalance, isValidAddress, allNull } = require('./util')
@@ -33,6 +35,8 @@ function mapStateToProps (state) {
addressBook,
conversionRate,
currentBlockGasLimit: blockGasLimit,
+ estimatedGas,
+ blockGasPrice,
} = state.metamask
const { warning } = state.appState
const selectedIdentity = getSelectedIdentity(state)
@@ -65,13 +69,15 @@ function SendTransactionScreen () {
newTx: {
from: '',
to: '',
- amount: 0,
amountToSend: '0x0',
- gasPrice: '0x5d21dba00',
- gas: '0x7b0d',
+ gasPrice: null,
+ gas: null,
+ amount: '0x0',
txData: null,
memo: '',
},
+ blockGasPrice: null,
+ estimatedGas: null,
activeCurrency: 'USD',
tooltipIsOpen: false,
errors: {},
@@ -87,6 +93,7 @@ function SendTransactionScreen () {
this.getAmountToSend = this.getAmountToSend.bind(this)
this.setErrorsFor = this.setErrorsFor.bind(this)
this.clearErrorsFor = this.clearErrorsFor.bind(this)
+ this.estimateGasAndPrice = this.estimateGasAndPrice.bind(this)
this.renderFromInput = this.renderFromInput.bind(this)
this.renderToInput = this.renderToInput.bind(this)
@@ -162,7 +169,10 @@ SendTransactionScreen.prototype.renderToInput = function (to, identities, addres
},
})
},
- onBlur: () => this.setErrorsFor('to'),
+ onBlur: () => {
+ this.setErrorsFor('to')
+ this.estimateGasAndPrice()
+ },
onFocus: event => {
this.clearErrorsFor('to')
this.state.newTx.to && event.target.select()
@@ -218,7 +228,10 @@ SendTransactionScreen.prototype.renderAmountInput = function (activeCurrency) {
),
})
},
- onBlur: () => this.setErrorsFor('amount'),
+ onBlur: () => {
+ this.setErrorsFor('amount')
+ this.estimateGasAndPrice()
+ },
onFocus: () => this.clearErrorsFor('amount'),
}),
@@ -301,7 +314,14 @@ SendTransactionScreen.prototype.render = function () {
conversionRate,
} = props
- const { blockGasLimit, newTx, activeCurrency, isValid } = this.state
+ const {
+ blockGasLimit,
+ newTx,
+ activeCurrency,
+ isValid,
+ blockGasPrice,
+ estimatedGas,
+ } = this.state
const { gas, gasPrice } = newTx
return (
@@ -322,7 +342,13 @@ SendTransactionScreen.prototype.render = function () {
this.renderAmountInput(activeCurrency),
- this.renderGasInput(gasPrice, gas, activeCurrency, conversionRate, blockGasLimit),
+ this.renderGasInput(
+ gasPrice || blockGasPrice || '0x0',
+ gas || estimatedGas || '0x0',
+ activeCurrency,
+ conversionRate,
+ blockGasLimit
+ ),
this.renderMemoInput(),
@@ -357,6 +383,23 @@ SendTransactionScreen.prototype.setActiveCurrency = function (newCurrency) {
this.setState({ activeCurrency: newCurrency })
}
+SendTransactionScreen.prototype.estimateGasAndPrice = function () {
+ const { errors, sendAmount, newTx } = this.state
+
+ if (!errors.to && !errors.amount && newTx.amount > 0) {
+ Promise.all([
+ this.props.dispatch(getGasPrice()),
+ this.props.dispatch(estimateGas({ to: newTx.to, amount: sendAmount })),
+ ])
+ .then(([blockGasPrice, estimatedGas]) => {
+ this.setState({
+ blockGasPrice,
+ estimatedGas,
+ })
+ })
+ }
+}
+
SendTransactionScreen.prototype.back = function () {
var address = this.props.address
this.props.dispatch(backToAccountDetail(address))
@@ -477,7 +520,7 @@ SendTransactionScreen.prototype.clearErrorsFor = function (field) {
SendTransactionScreen.prototype.onSubmit = function (event) {
event.preventDefault()
- const { warning, balance, amountToSend } = this.props
+ const { warning, balance } = this.props
const state = this.state || {}
const recipient = state.newTx.to
@@ -495,7 +538,7 @@ SendTransactionScreen.prototype.onSubmit = function (event) {
from: this.state.newTx.from,
to: this.state.newTx.to,
- value: amountToSend,
+ value: this.state.newTx.amountToSend,
gas: this.state.newTx.gas,
gasPrice: this.state.newTx.gasPrice,