aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components
diff options
context:
space:
mode:
authorDan <danjm.com@gmail.com>2017-09-26 08:39:10 +0800
committerDan <danjm.com@gmail.com>2017-09-26 08:39:10 +0800
commitfc3e071ad699f6c3586a20f12e06e6f456b0eea3 (patch)
tree7d601a5ec035e93d517083d03aeda0d3c679ef9e /ui/app/components
parent79bcb88db3946260c832402d97e0c800cdeba5a9 (diff)
downloadtangerine-wallet-browser-fc3e071ad699f6c3586a20f12e06e6f456b0eea3.tar
tangerine-wallet-browser-fc3e071ad699f6c3586a20f12e06e6f456b0eea3.tar.gz
tangerine-wallet-browser-fc3e071ad699f6c3586a20f12e06e6f456b0eea3.tar.bz2
tangerine-wallet-browser-fc3e071ad699f6c3586a20f12e06e6f456b0eea3.tar.lz
tangerine-wallet-browser-fc3e071ad699f6c3586a20f12e06e6f456b0eea3.tar.xz
tangerine-wallet-browser-fc3e071ad699f6c3586a20f12e06e6f456b0eea3.tar.zst
tangerine-wallet-browser-fc3e071ad699f6c3586a20f12e06e6f456b0eea3.zip
Send token now estimates gas and price.
Diffstat (limited to 'ui/app/components')
-rw-r--r--ui/app/components/send-token/index.js45
1 files changed, 37 insertions, 8 deletions
diff --git a/ui/app/components/send-token/index.js b/ui/app/components/send-token/index.js
index 166088898..e4f13a874 100644
--- a/ui/app/components/send-token/index.js
+++ b/ui/app/components/send-token/index.js
@@ -57,6 +57,9 @@ function mapDispatchToProps (dispatch) {
dispatch(actions.signTokenTx(tokenAddress, toAddress, amount, txData))
),
updateTokenExchangeRate: token => dispatch(actions.updateTokenExchangeRate(token)),
+ estimateGas: ({ to, amount }) => dispatch(actions.estimateGas({ to, amount })),
+ getGasPrice: () => dispatch(actions.getGasPrice()),
+
}
}
@@ -69,8 +72,8 @@ function SendTokenScreen () {
amountToSend: '0x0',
selectedCurrency: 'USD',
isGasTooltipOpen: false,
- gasPrice: '0x5d21dba00',
- gasLimit: '0x7b0d',
+ gasPrice: null,
+ gasLimit: null,
errors: {},
}
}
@@ -84,6 +87,24 @@ SendTokenScreen.prototype.componentWillMount = function () {
updateTokenExchangeRate(symbol)
}
+SendTokenScreen.prototype.estimateGasAndPrice = function () {
+ const { selectedToken } = this.props
+ const { errors, amount, to } = this.state
+
+ if (!errors.to && !errors.amount && amount > 0) {
+ Promise.all([
+ this.props.getGasPrice(),
+ this.props.estimateGas({ to, amount: this.getAmountToSend(amount, selectedToken) }),
+ ])
+ .then(([blockGasPrice, estimatedGas]) => {
+ this.setState({
+ blockGasPrice,
+ estimatedGas,
+ })
+ })
+ }
+}
+
SendTokenScreen.prototype.validate = function () {
const {
to,
@@ -215,7 +236,10 @@ SendTokenScreen.prototype.renderToAddressInput = function () {
to: e.target.value,
errors: {},
}),
- onBlur: () => this.setErrorsFor('to'),
+ onBlur: () => {
+ this.setErrorsFor('to')
+ this.estimateGasAndPrice()
+ },
onFocus: () => this.clearErrorsFor('to'),
}),
h('datalist#addresses', [
@@ -271,7 +295,10 @@ SendTokenScreen.prototype.renderAmountInput = function () {
onChange: e => this.setState({
amount: e.target.value,
}),
- onBlur: () => this.setErrorsFor('amount'),
+ onBlur: () => {
+ this.setErrorsFor('amount')
+ this.estimateGasAndPrice()
+ },
onFocus: () => this.clearErrorsFor('amount'),
}),
h('div.send-screen-input-wrapper__error-message', [ errorMessage ]),
@@ -283,6 +310,8 @@ SendTokenScreen.prototype.renderGasInput = function () {
isGasTooltipOpen,
gasPrice,
gasLimit,
+ blockGasPrice,
+ estimatedGas,
selectedCurrency,
errors: {
gasPrice: gasPriceErrorMessage,
@@ -303,8 +332,8 @@ SendTokenScreen.prototype.renderGasInput = function () {
}, [
isGasTooltipOpen && h(GasTooltip, {
className: 'send-tooltip',
- gasPrice,
- gasLimit,
+ gasPrice: gasPrice || blockGasPrice || '0x0',
+ gasLimit: gasLimit || estimatedGas || '0x0',
onClose: () => this.setState({ isGasTooltipOpen: false }),
onFeeChange: ({ gasLimit, gasPrice }) => {
this.setState({ gasLimit, gasPrice, errors: {} })
@@ -327,9 +356,9 @@ SendTokenScreen.prototype.renderGasInput = function () {
h(GasFeeDisplay, {
conversionRate,
tokenExchangeRate,
- gasPrice,
+ gasPrice: gasPrice || blockGasPrice || '0x0',
activeCurrency: selectedCurrency,
- gas: gasLimit,
+ gas: gasLimit || estimatedGas || '0x0',
blockGasLimit: currentBlockGasLimit,
}),
h(